-
Notifications
You must be signed in to change notification settings - Fork 731
fix(tool): Do not return empty outputSchema
#573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If the output schema is not specify, we do not return it as we break the MCP specification that are expecting the following format: ```json "outputSchema": { "type": "object", "properties": {}, "required": [] } ```
WalkthroughTool.MarshalJSON now omits Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Assessment against linked issues
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
mcp/tools_test.go (2)
589-633
: LGTM; add a quick type check when schema exists.Nice table test verifying presence/absence. Strengthen the “default behavior” branch by asserting the type field.
Apply this diff inside the true-branch to assert the schema shape:
if tt.expectedOutputSchema { assert.True(t, exists) assert.NotNil(t, outputSchema) + schemaMap, ok := outputSchema.(map[string]any) + assert.True(t, ok) + assert.Equal(t, "object", schemaMap["type"]) } else {
589-633
: Consider adding a RawOutputSchema case.Add a small test to ensure raw schemas are emitted (guards regressions on the raw path).
func TestToolWithRawOutputSchema_Included(t *testing.T) { raw := json.RawMessage(`{"type":"object","properties":{"ok":{"type":"boolean"}},"required":["ok"]}`) tool := NewTool("raw_tool", WithString("input", Required()), WithRawOutputSchema(raw)) data, err := json.Marshal(tool) assert.NoError(t, err) var m map[string]any assert.NoError(t, json.Unmarshal(data, &m)) os, exists := m["outputSchema"].(map[string]any) assert.True(t, exists) assert.Equal(t, "object", os["type"]) props, _ := os["properties"].(map[string]any) _, hasOK := props["ok"] assert.True(t, hasOK) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
mcp/tools.go
(1 hunks)mcp/tools_test.go
(1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:0-0
Timestamp: 2025-03-04T07:00:57.111Z
Learning: The Tool struct in the mark3labs/mcp-go project should handle both InputSchema and RawInputSchema consistently between MarshalJSON and UnmarshalJSON methods, even though the tools response from MCP server typically doesn't contain rawInputSchema.
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:0-0
Timestamp: 2025-03-04T07:00:57.111Z
Learning: The Tool struct in mark3labs/mcp-go handles both InputSchema and RawInputSchema formats. When unmarshaling JSON, it first tries to parse into a structured ToolInputSchema format, and if that fails, it falls back to using the raw schema format, providing symmetry with the MarshalJSON method.
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:107-137
Timestamp: 2025-03-04T06:59:43.882Z
Learning: Tool responses from the MCP server shouldn't contain RawInputSchema, which is why the UnmarshalJSON method for the Tool struct is implemented to handle only the structured InputSchema format.
📚 Learning: 2025-03-04T07:00:57.111Z
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:0-0
Timestamp: 2025-03-04T07:00:57.111Z
Learning: The Tool struct in the mark3labs/mcp-go project should handle both InputSchema and RawInputSchema consistently between MarshalJSON and UnmarshalJSON methods, even though the tools response from MCP server typically doesn't contain rawInputSchema.
Applied to files:
mcp/tools_test.go
mcp/tools.go
📚 Learning: 2025-03-04T06:59:43.882Z
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:107-137
Timestamp: 2025-03-04T06:59:43.882Z
Learning: Tool responses from the MCP server shouldn't contain RawInputSchema, which is why the UnmarshalJSON method for the Tool struct is implemented to handle only the structured InputSchema format.
Applied to files:
mcp/tools_test.go
mcp/tools.go
📚 Learning: 2025-03-04T07:00:57.111Z
Learnt from: xinwo
PR: mark3labs/mcp-go#35
File: mcp/tools.go:0-0
Timestamp: 2025-03-04T07:00:57.111Z
Learning: The Tool struct in mark3labs/mcp-go handles both InputSchema and RawInputSchema formats. When unmarshaling JSON, it first tries to parse into a structured ToolInputSchema format, and if that fails, it falls back to using the raw schema format, providing symmetry with the MarshalJSON method.
Applied to files:
mcp/tools_test.go
mcp/tools.go
🧬 Code graph analysis (1)
mcp/tools_test.go (1)
mcp/tools.go (6)
Tool
(557-574)NewTool
(679-701)WithDescription
(722-726)WithOutputSchema
(771-804)WithString
(1046-1064)Required
(878-882)
🔇 Additional comments (1)
mcp/tools.go (1)
604-612
: Correct: omit outputSchema when not explicitly set (matches MCP spec).This conditional now serializes outputSchema only when RawOutputSchema is provided or OutputSchema.Type is non-empty. That aligns with the 2025-06-18 MCP spec where outputSchema is optional; sending an empty object was incorrect. Please update the PR description to reflect that the correct behavior is to omit outputSchema entirely when unspecified (the example showing a default object with empty properties/required contradicts the spec). (modelcontextprotocol.io)
Would you confirm this behavior against clients that broke on v0.39.0 (e.g., Claude Desktop/Web) to ensure omission (not an empty object) resolves discovery?
@alex210501 I'll merge as soon as the typo is fixed |
Description
If the output schema is not specify, we do not return it as we break the MCP specification that are expecting the following format:
Fixes #572 (if applicable)
Type of Change
Checklist
MCP Spec Compliance
Additional Information
Summary by CodeRabbit
Bug Fixes
Tests