Skip to content

Commit 6a868bc

Browse files
ezynda3opencode
andcommitted
fix: maintain backward compatibility for protocol version negotiation
When the server does not receive an MCP-Protocol-Version header, it should assume protocol version 2025-03-26 for backward compatibility as per the MCP specification. 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <noreply@opencode.ai>
1 parent 278238b commit 6a868bc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

server/server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,14 @@ func (s *MCPServer) handleInitialize(
604604
}
605605

606606
func (s *MCPServer) protocolVersion(clientVersion string) string {
607+
// For backwards compatibility, if the server does not receive an MCP-Protocol-Version header,
608+
// and has no other way to identify the version - for example, by relying on the protocol version negotiated
609+
// during initialization - the server SHOULD assume protocol version 2025-03-26
610+
// https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#protocol-version-header
611+
if len(clientVersion) == 0 {
612+
clientVersion = "2025-03-26"
613+
}
614+
607615
if slices.Contains(mcp.ValidProtocolVersions, clientVersion) {
608616
return clientVersion
609617
}

0 commit comments

Comments
 (0)