tool "properties" and "required" fields missing if set them as null, AdditionalProperties can't be masharl#713
Conversation
…the MCP server will specify the low version during initialization phase. For example, the mcp server dose support '2025-06-18' version. But if client dose not specify the version, the mcp server will use '2025-03-26'. And, the other case is that the mcp client dose not need the latest '2025-11-25' version MCP features. But when client do initialization with MCP server, the server select '2025-11-25' version during negotiation and raised "unsupported protocol version 2025-11-25" error. Since mcp-go library dose not implement the '2025-11-25' version mcp feature temporary. fix issue mark3labs#650. Signed-off-by: hai.yue <hai.yue@ingka.com>
…, openai) failure, if set them as null. And AdditionalProperties can't be masharl correctly even specified. Signed-off-by: hai.yue <hai.yue@ingka.com>
WalkthroughAdds custom JSON MarshalJSON/UnmarshalJSON implementations for ToolInputSchema, ToolOutputSchema, and ToolArgumentsSchema (with helpers) to control serialization of properties/required/additionalProperties; adds tests for empty/nil serialization cases; fixes a comment spelling typo. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@mcp/tools.go`:
- Around line 698-701: The GoDoc comment for the UnmarshalJSON method is
incorrect: it references "ToolOutputSchema" but the method is defined on
ToolArgumentsSchema. Update the comment to accurately describe the receiver by
changing the comment text to reference ToolArgumentsSchema (i.e., the
UnmarshalJSON method on ToolArgumentsSchema that calls
toolArgumentsSchemaUnmarshalJSON), ensuring the comment matches the function
name UnmarshalJSON and the helper toolArgumentsSchemaUnmarshalJSON.
🧹 Nitpick comments (1)
mcp/tools.go (1)
703-731: Minor typo and LGTM on the logic.The implementation correctly ensures
propertiesis serialized as{}when nil andrequiredis serialized as[]when empty, addressing the LLM compatibility issues described in the PR.📝 Fix typo in comment
-// It handls the fields stored in ToolArgumentsSchema when json.Marshaler been called +// toolArgumentsSchemaMarshalJSON handles the fields stored in ToolArgumentsSchema when json.Marshaler is called
Signed-off-by: hai.yue <hai.yue@ingka.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@mcp/tools.go`:
- Around line 723-728: The inline comment incorrectly mentions "Properties"
while the code handles tis.Required; update the comment above the block that
marshals the "required" field to accurately describe that it marshals
tis.Required to an empty slice ([]) rather than nil when its length is zero,
referencing tis.Required and the "required" map key so the comment matches the
code's intent.
Signed-off-by: hai.yue <hai.yue@ingka.com>
Description
tool "properties" and "required" fields missing cause LLM (qwen, openai) failure if set them as null.
the pr fix below issues:
1. 'Required' is not included in mashal content even set it as []string{}. Some LLM, like qwen and openai require this field.
2. Mashal 'Tool' dose not trigger its sub fields InputSchema and OutputSchema' MarshalJSON and UnmarshalJSON function call. The same thing happens even marsh its sub fields InputSchema and OutputSchema directly.
Fixes #712
Type of Change
Checklist
Additional Information
Code to reproduce the issue:
....
Summary by CodeRabbit
Bug Fixes
Tests