mcp: negotiate protocol version (#112)
Negotiate the protocol version properly, and set the header on HTTP transports. We follow the logic of the Typescript SDK. - On initialization, the client sends the latest version it can support, and accepts the version that the server returns if the client supports it. If not, the connection fails. - The server accepts the client's version unless it doesn't support it, in which case it replies with its latest version. Fixes #103.
This commit is contained in:
parent
a1a3510315
commit
c037ba51d2
1 changed files with 73 additions and 16 deletions
|
|
@ -22,6 +22,16 @@ import (
|
|||
"github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
|
||||
)
|
||||
|
||||
// latestProtocolVersion is the latest protocol version that this version of the SDK supports.
|
||||
// It is the version that the client sends in the initialization request.
|
||||
const latestProtocolVersion = "2025-06-18"
|
||||
|
||||
var supportedProtocolVersions = []string{
|
||||
latestProtocolVersion,
|
||||
"2025-03-26",
|
||||
"2024-11-05",
|
||||
}
|
||||
|
||||
// A MethodHandler handles MCP messages.
|
||||
// For methods, exactly one of the return values must be nil.
|
||||
// For notifications, both must be nil.
|
||||
|
|
|
|||
Loading…
Reference in a new issue