-
Notifications
You must be signed in to change notification settings - Fork 746
Preserve Tool _meta when marshaling to JSON #609
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
base: main
Are you sure you want to change the base?
Conversation
Needed for openai ui integration Issue: none Test plan: 🤞
WalkthroughTool.MarshalJSON now conditionally includes a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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.
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 (1)
mcp/tools_test.go (1)
1400-1428
: Test correctly verifies_meta
marshaling. Consider adding a nil case.The test appropriately validates that a non-nil
Meta
field is marshaled as_meta
and matches the expected value.To ensure complete coverage of the omitempty behavior, consider adding a test case that verifies
_meta
is omitted whenMeta
isnil
:+func TestToolMetaMarshalingOmitsWhenNil(t *testing.T) { + // Marshal a tool without Meta + data, err := json.Marshal(Tool{ + Name: "test-tool-no-meta", + Description: "A test tool without meta data", + InputSchema: ToolInputSchema{ + Type: "object", + Properties: map[string]any{}, + }, + }) + assert.NoError(t, err) + + // Unmarshal to map + var result map[string]any + err = json.Unmarshal(data, &result) + assert.NoError(t, err) + + // Check that _meta field is not present + assert.NotContains(t, result, "_meta", "Tool without Meta should not include _meta field") +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
mcp/tools.go
(1 hunks)mcp/tools_test.go
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
mcp/tools_test.go (2)
mcp/tools.go (4)
Tool
(557-574)Description
(875-879)ToolInputSchema
(632-632)Properties
(1117-1121)mcp/types.go (2)
Meta
(121-133)NewMetaFromMap
(156-166)
mcp/tools.go (1)
mcp/types.go (1)
Meta
(121-133)
🔇 Additional comments (1)
mcp/tools.go (1)
616-619
: LGTM!The conditional marshaling of
_meta
whenMeta
is non-nil is correctly implemented and matches the existing pattern inCallToolResult.MarshalJSON
(lines 478-480). This ensures spec compliance without breaking backward compatibility.
Description
Adds the
_meta
field to marshaled Tool json. Unmarshalling was already handled.Type of Change
Checklist
I have updated the documentation accordingly(didn't seem necessary)MCP Spec Compliance
Additional Information
Summary by CodeRabbit
New Features
Tests