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

Skip to content

fix: serialize empty MCP tool properties as {} not null for OpenAI - #28380

Merged
ibetitsmike merged 2 commits into
mainfrom
fix/chatd-openai-null-tool-properties
Aug 20, 2026
Merged

fix: serialize empty MCP tool properties as {} not null for OpenAI#28380
ibetitsmike merged 2 commits into
mainfrom
fix/chatd-openai-null-tool-properties

Conversation

@DanielleMaywood

Copy link
Copy Markdown
Contributor

Summary

Fixed a bug where MCP tools with an empty properties schema 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 properties object collapsed to Go nil at two layers:

  1. agent/x/agentmcp/manager.go toolInputSchemaMap stripped the present-but-empty "properties": {} (guarded by len(properties) > 0), so the wire copy lost it entirely.
  2. coderd/x/chatd/chatloop/chatloop.go buildToolDefinitions embedded info.Parameters directly into the input schema. When nil, encoding/json marshals it as null.

Fix

  • buildToolDefinitions now substitutes an empty object when Parameters is nil, mirroring the existing required guard (the sink, protects all tool sources).
  • toolInputSchemaMap now preserves an empty properties object 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":{}}:

  • TestBuildToolDefinitionsNilPropertiesBecomesEmptyObject
  • TestToolInputSchemaMapPreservesEmptyProperties
  • TestWorkspaceMCPToolInfosFromResources/EmptyPropertiesYieldsEmptySchema

This PR was generated by Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: c6f5e37448

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator

Heads up: the lint failure here is

coderd/x/chatd/chatloop/chatloop_internal_test.go:96:7: unused-receiver: method receiver 't' is not referenced in method's body, consider removing or renaming it as _ (revive)

Dropping the receiver name fixes it: func (staticParametersTool) ProviderOptions() fantasy.ProviderOptions { return nil }.

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.

🤖 Mux posted this comment on Mike's behalf.

@DanielleMaywood
DanielleMaywood marked this pull request as ready for review August 20, 2026 13:50
@ibetitsmike
ibetitsmike merged commit 5480299 into main Aug 20, 2026
33 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 20, 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