Skip to content

Commit 3b722d3

Browse files
committed
mcp: remove json-rpc batching for more recent protocol versions
JSON-RPC batching support is removed for protocol versions greater than or equal to protocolVersion20250618 Fixes #21
1 parent 728e0e3 commit 3b722d3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

mcp/streamable.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,22 @@ func (c *streamableServerConn) servePOST(w http.ResponseWriter, req *http.Reques
620620
// This also requires access to the negotiated version, which would either be
621621
// set by the MCP-Protocol-Version header, or would require peeking into the
622622
// session.
623-
incoming, _, err := readBatch(body)
623+
incoming, isBatch, err := readBatch(body)
624624
if err != nil {
625625
http.Error(w, fmt.Sprintf("malformed payload: %v", err), http.StatusBadRequest)
626626
return
627627
}
628+
629+
protocolVersion := req.Header.Get(protocolVersionHeader)
630+
if protocolVersion == "" {
631+
protocolVersion = protocolVersion20250326
632+
}
633+
634+
if isBatch && protocolVersion >= protocolVersion20250618 {
635+
http.Error(w, fmt.Sprintf("JSON-RPC batching is not supported in %s and later (request version: %s)", protocolVersion20250618, protocolVersion), http.StatusBadRequest)
636+
return
637+
}
638+
628639
requests := make(map[jsonrpc.ID]struct{})
629640
tokenInfo := auth.TokenInfoFromContext(req.Context())
630641
isInitialize := false

0 commit comments

Comments
 (0)