Skip to content

mcp: check requests against declared client capabilities - #1363

Open
po-et wants to merge 2 commits into
modelcontextprotocol:mainfrom
po-et:fix/1303-client-capability-checks
Open

po-et wants to merge 2 commits into
modelcontextprotocol:mainfrom
po-et:fix/1303-client-capability-checks

Conversation

@po-et

@po-et po-et commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #1303.

A tool-enabled sampling request could reach a client that advertised only basic sampling, whose handler then answered without the requested tools. The server now checks declared roots, sampling and sampling.tools before sending a request. The client rejects undeclared tool sampling and elicitation modes with -32602 before calling the handler.

Sampling and elicitation checks also cover multi-round-trip input requests on both 2026-07-28 and legacy sessions. Existing roots fixtures now declare the capability they use.

Validation: the added regression tests fail on current main and pass with the fix; go test -race ./..., go vet ./..., staticcheck ./... and git diff --check pass locally (Go 1.27.1, staticcheck 0.8.1).

A separate, pre-existing gap remains: the modern multi-round-trip roots input path calls the client roots handler without a capability check. This PR gates outbound ServerSession.ListRoots; it does not change that modern input path.

po-et added 2 commits October 9, 2026 11:09
Reject undeclared tool sampling and elicitation modes before invoking client handlers, and check roots and sampling before sending server requests.

Fixes modelcontextprotocol#1303

This branch has not been deployed

No deployments
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.

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

1 participant