Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(coderd/x/chatd): prevent nil required field in MCP tool schemas for OpenAI - #23538

Merged
kylecarbs merged 1 commit into
mainfrom
fix/mcp-nil-required-schema
Mar 24, 2026
Merged

fix(coderd/x/chatd): prevent nil required field in MCP tool schemas for OpenAI#23538
kylecarbs merged 1 commit into
mainfrom
fix/mcp-nil-required-schema

Conversation

@kylecarbs

Copy link
Copy Markdown
Member

When an MCP server (e.g. Linear) returns a tool whose inputSchema omits the required field, the Go []string deserializes to nil. This nil propagates through to the OpenAI API as "required": null in JSON, which OpenAI rejects:

Invalid schema for function 'linear__list_documents': None is not of type 'array'.

Anthropic is unaffected because its provider defensively initializes required to []string{}. Fantasy's own funcToolWrapper also has a nil guard, but the coder-side mcpToolWrapper did not.

Two fixes:

  • mcpclient: coerce nil Required to []string{} in Info(), matching what Fantasy's funcToolWrapper already does.
  • chatloop: only include the "required" key in the schema map when non-empty, as defense-in-depth.

…or OpenAI

When an MCP server returns a tool whose inputSchema omits the
"required" field, the Go []string deserializes to nil. This nil
propagates through to the OpenAI API as "required": null, which
OpenAI rejects with "None is not of type 'array'".

Two fixes:
- mcpclient: coerce nil Required to []string{} in Info()
- chatloop: only include "required" key when non-empty
@kylecarbs
kylecarbs marked this pull request as ready for review March 24, 2026 21:53
@kylecarbs
kylecarbs merged commit 3812b50 into main Mar 24, 2026
33 checks passed
@kylecarbs
kylecarbs deleted the fix/mcp-nil-required-schema branch March 24, 2026 22:29
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants