fix: serialize empty MCP tool properties as {} not null for OpenAI - #28380
Conversation
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Heads up: the Dropping the receiver name fixes it: FYI: stack #28384 (#28373 → #28376 → #28377) is now based on this branch, complementing it with the schema-split normalization and full input-schema passthrough, so its CI currently inherits this lint failure. We'll rebase the stack when this branch updates.
|
Summary
Fixed a bug where MCP tools with an empty
propertiesschema had their tool definitions sent to OpenAI with"properties": null, causing OpenAI to reject the request.Problem
When an MCP server reports a tool with an empty input schema, e.g.:
{ "type": "object", "properties": {}, "required": [] }Coder was forwarding the tool definition to OpenAI as:
{ "type": "object", "properties": null }OpenAI's function-calling API rejects
properties: null, making these tools unusable with OpenAI models.Root cause
The empty
propertiesobject collapsed to Gonilat two layers:agent/x/agentmcp/manager.gotoolInputSchemaMapstripped the present-but-empty"properties": {}(guarded bylen(properties) > 0), so the wire copy lost it entirely.coderd/x/chatd/chatloop/chatloop.gobuildToolDefinitionsembeddedinfo.Parametersdirectly into the input schema. When nil,encoding/jsonmarshals it asnull.Fix
buildToolDefinitionsnow substitutes an empty object whenParametersis nil, mirroring the existingrequiredguard (the sink, protects all tool sources).toolInputSchemaMapnow preserves an emptypropertiesobject instead of dropping it (the upstream producer).Tests
Added regression tests (failing before, passing after) covering both layers and asserting the schema serializes to
{"type":"object","properties":{}}:TestBuildToolDefinitionsNilPropertiesBecomesEmptyObjectTestToolInputSchemaMapPreservesEmptyPropertiesTestWorkspaceMCPToolInfosFromResources/EmptyPropertiesYieldsEmptySchemaThis PR was generated by Coder Agents.