Skip to content

feat: support SEP-2575 make MCP stateless#3211

Open
Yuan325 wants to merge 1 commit into
mcp-v202606from
sep-2575
Open

feat: support SEP-2575 make MCP stateless#3211
Yuan325 wants to merge 1 commit into
mcp-v202606from
sep-2575

Conversation

@Yuan325

@Yuan325 Yuan325 commented May 11, 2026

Copy link
Copy Markdown
Contributor

Support SEP-2575

This PR also updates our custom auth error code since it contradicts with some new errors added in this SEP.:

// Custom auth error codes
UNAUTHORIZED = -401
FORBIDDEN    = -403

For stdio transport:

  • If _meta.io.modelcontextprotocol/protocolVersion was provided, it will use the protocol version specified (take precedence over existing version).
  • Else, it will use the version during initialization method.
  • If no initialization method was called, it will default to v2024-11-05 similar to Toolbox's HTTP transport. Toolbox had a custom transport on v2024-11-05 --> "regular" HTTP POST (without SSE), that does not enforce the initialize method

For HTTP transport:

  • Use the version that was specified in header as protocol version.
  • If it specified the DRAFT version, it will check against _meta.io.modelcontextprotocol/protocolVersion to validate.

@Yuan325 Yuan325 requested a review from a team as a code owner May 11, 2026 22:42

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the MCP stateless protocol version (draft), adding the server/discover method and refactoring JSON-RPC structures to handle per-request metadata like protocol versions and client information. Review feedback highlights several critical issues: JSON field shadowing in request structs that may break unmarshaling, a missing case for the draft version in the method processing loop, and a duplicate error code. Furthermore, the metadata validation logic requires adjustments to maintain backward compatibility with clients not using the new metadata fields and to ensure negotiated protocol versions are not inadvertently overwritten.

Comment thread internal/server/mcp/vdraft/types.go Outdated
Comment thread internal/server/mcp/mcp.go
Comment thread internal/server/mcp/jsonrpc/jsonrpc.go
Comment thread internal/server/mcp.go Outdated
Comment thread internal/server/mcp.go Outdated
Comment thread internal/server/mcp.go Outdated
@Yuan325 Yuan325 force-pushed the sep-2575 branch 2 times, most recently from cb4b8a9 to dcf9c44 Compare May 12, 2026 03:09
@Yuan325

Yuan325 commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for the MCP 2026 protocol draft, including metadata validation for protocol versions and client information. It refactors the JSON-RPC request structures to include a standardized _meta object and introduces the server/discover method. Feedback highlights a critical potential nil pointer dereference in the protocol validation logic and a conflict where a new error code duplicates an existing one.

Comment thread internal/server/mcp.go Outdated
Comment thread internal/server/mcp/jsonrpc/jsonrpc.go
@Yuan325

Yuan325 commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the Model Context Protocol (MCP) v2026+ by implementing protocol version negotiation, client information validation, and a new server/discover method. It also refactors JSON-RPC message structures to support per-request metadata and adds a standard error for unsupported protocol versions. Feedback includes a critical fix for a colliding error code, the removal of a redundant string check, and suggestions to eliminate code duplication by utilizing shared types from the jsonrpc package.

Comment thread internal/server/mcp/jsonrpc/jsonrpc.go
Comment thread internal/server/mcp.go Outdated
Comment thread internal/server/mcp/vdraft/method.go
Comment thread internal/server/mcp/vdraft/types.go
@Yuan325

Yuan325 commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for the MCP 2026 draft protocol, introducing the server/discover method and per-request metadata validation for protocol versions, client info, and capabilities. It refactors JSON-RPC structures to support the _meta field and updates error handling for protocol mismatches. Feedback identifies opportunities to improve HTTP status code mapping for JSON-RPC errors, remove a redundant protocol version check, and correct a header name in an error message.

Comment thread internal/server/mcp.go
Comment thread internal/server/mcp.go Outdated
Comment thread internal/server/mcp.go Outdated
@Yuan325 Yuan325 force-pushed the move-initialize branch from 5b354e6 to f3c296a Compare May 19, 2026 19:57
@Yuan325 Yuan325 changed the base branch from move-initialize to mcp-v202606 May 19, 2026 20:03
@Yuan325 Yuan325 force-pushed the sep-2575 branch 4 times, most recently from 18fb620 to a60ede4 Compare May 19, 2026 23:44
@Yuan325

Yuan325 commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the MCP draft protocol version, replacing the initialization and ping methods with a new server discovery mechanism. It refactors JSON-RPC request and error structures to support per-request metadata validation, including protocol version and client capabilities. Feedback suggests optimizing performance by avoiding redundant JSON unmarshaling in the draft method processor and improving error handling by replacing fragile string-based checks with structured error codes.

Comment thread internal/server/mcp/vdraft/method.go Outdated
Comment thread internal/server/mcp.go Outdated
case TOOLS_LIST:
return toolsListHandler(id, resourceMgr, toolset, body)
return toolsListHandler(id, resourceMgr, toolset, body, stdio)
case TOOLS_CALL:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does toolCallHandler need the stdio boolean too? Will this error if header is nil accessToken := tools.AccessToken(header.Get(authTokenHeadername))?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants