-
Notifications
You must be signed in to change notification settings - Fork 679
feat(protocol): allow additional fields in meta #293
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
WalkthroughThe changes introduce a new exported Changes
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Note ⚡️ Faster reviews with cachingCodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure ✨ Finishing Touches
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. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
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 (1)
mcp/types.go (1)
130-139
: Consider defensive initialization in UnmarshalJSONThe implementation correctly extracts the progress token and stores remaining fields, but
AdditionalFields
isn't initialized if it's nil.func (m *Meta) UnmarshalJSON(data []byte) error { raw := make(map[string]any) if err := json.Unmarshal(data, &raw); err != nil { return err } m.ProgressToken = raw["progressToken"] delete(raw, "progressToken") + if m.AdditionalFields == nil { + m.AdditionalFields = make(map[string]any) + } m.AdditionalFields = raw return nil }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (3)
mcp/tools.go
(1 hunks)mcp/types.go
(2 hunks)mcp/types_test.go
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
mcp/tools.go (1)
mcp/types.go (1)
Meta
(106-118)
mcp/types_test.go (1)
mcp/types.go (2)
Meta
(106-118)ProgressToken
(99-99)
🔇 Additional comments (5)
mcp/types.go (3)
104-118
: Well-designed Meta struct implementationThe implementation of the
Meta
struct is clean and well-documented. It supports both the standardizedProgressToken
field and additional arbitrary fields, enabling extensibility while maintaining backward compatibility.
120-128
: Effective JSON marshalling implementationThe marshalling logic properly handles both the protocol-defined
progressToken
field and any additional fields. Using themaps.Copy
function is efficient for merging the maps.
144-144
: Good update to Request.Params.Meta typeChanging from an anonymous struct to the new
Meta
type maintains API compatibility while enabling additional field support.mcp/tools.go (1)
49-49
: Consistent Meta type usage across packageThe
CallToolRequest.Params.Meta
field is properly updated to use the newMeta
type, ensuring consistent handling of metadata across the package.mcp/types_test.go (1)
11-70
: Comprehensive test cases for Meta marshallingThe test cases thoroughly cover various scenarios including empty structs, string tokens, and additional fields. The tests properly validate both marshalling and unmarshalling behaviors, including handling of numeric types in JSON.
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.
LGTM 🚀
Thank you.
Description
Replaces anonymous struct type with real type for
Meta
on request params with custom JSON marshalling logic to allow fields in addition to progress token to be marshalled.Technically, it seems all types in a JSON-RPC protocol like MCP should be open to other fields and MCP's python/JS SDKs do allow this in most types. In practice,
_meta
is being used in several instrumentation frameworks for propagating trace contextmodelcontextprotocol/modelcontextprotocol#246
Defining a type with custom marshalling allows doing similar with mcp-go. As the structure of the existing anonymous struct is preserved, I believe this is a backwards compatible change.
Type of Change
Checklist
MCP Spec Compliance
Actually I couldn't find text in the specification itself but convention in the SDKs along with guidance in the attached issue. I think it is in principal spec compliance.
https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/types.py#L25
https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/types.py#L51
https://github.com/modelcontextprotocol/typescript-sdk/blob/main/src/types.ts#L30 (
.passthrough()
)Additional Information
Summary by CodeRabbit
New Features
Bug Fixes
Tests