go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

mcp: requests to the client aren't checked against the capabilities it declared

Open po-et opened this issue 2 months ago • 1 comments

The spec has a rule on each side of some requests a server sends to a client. From client/sampling (2025-11-25), servers MUST NOT send tool-enabled sampling requests to a client that hasn't declared sampling.tools, and the schema says the client MUST return an error for such a request. From client/elicitation, "Error Handling": a client MUST answer a request for a mode it didn't declare with -32602.

Only ServerSession.Elicit checks the client's capabilities today. CreateMessageWithTools sends tools to any client, and a client with only a CreateMessageHandler, which declares sampling without tools, drops tools and toolChoice and answers anyway, so the server gets an answer produced without the tools it asked for. CreateMessage and ListRoots don't check sampling and roots either. On the client side, a url-mode elicitation reaches the handler of a client that declared only form mode, which is the default.

This came up in the review of #699 (https://github.com/modelcontextprotocol/go-sdk/pull/699#discussion_r2810556445), with the suggestion to cover all capability-gated server→client requests consistently. I have a change that does that: those server methods return an error before sending, as Elicit does, and the client answers -32602 before calling its handler. I can send it as a PR if that's the direction you want.

po-et avatar Sep 26 '26 21:09 po-et

Hi @po-et , thank you for reporting this. Feel free to proceed with the PR

guglielmo-san avatar Sep 30 '26 13:09 guglielmo-san