Skip to content

mcp: check requests against declared client capabilities - #1363

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

po-et wants to merge 7 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 sampling request with tools could reach a client that advertised only basic sampling, allowing its handler to answer without the requested tools. Check declared roots, sampling, and sampling.tools before the server sends requests, and reject undeclared tool sampling and elicitation modes before invoking client handlers.

The checks also cover multi-round-trip input requests. The client rejects roots requests when roots are explicitly disabled, including the modern 2026-07-28 path. Default roots support and explicit roots with listChanged disabled continue to work. Raw legacy roots/list requests receive the standard method-not-found error (-32601), with no roots result. Existing roots fixtures declare the capability they use.

The branch includes main at e844b98ccb9d9febfa32253ac6d0e756491c4b76 through the normal merge commit a58fafda3d4bc89d8e768d5e9a33ea4e15ebfb4e. This incorporates the executable-bit restoration merged in #1415 and satisfies the current up-to-date requirement. All 227 tracked file contents and the contribution patch are byte-for-byte identical to the prior PR head 7f4e83f5418b97822cdf1e8a95079417bfda1296; only the conformance script's executable mode changes. No history was rewritten.

Validation (macOS arm64):

  • On the current merged tree, complete Go 1.26.9 go test ./... passes, along with executable-mode, shell-syntax and diff checks.
  • The identical Go tree was already validated at 7f4e83f with complete Go 1.26.9 go test -race ./..., go vet ./..., go build ./..., and complete Go 1.25.6 go test ./.... Those checks were not redundantly rerun for this mode-only merge.
  • Staticcheck 2026.2.1 (0.8.1) and repository-wide gofmt passed on that identical Go tree. The local static analysis used this Go 1.26-compatible version; it does not claim a local run of CI-pinned Staticcheck 0.6.1.
  • The earlier regressions cover undeclared sampling tools and elicitation modes, six roots cases across modern and legacy sessions, and three raw legacy roots/list parameter forms. The modern explicitly-disabled case and incorrect legacy error code were reproduced before their fixes.
  • Independent automated review of this merge confirms correct parents, identical tracked blobs and contribution patch, the restored executable mode, and successful direct --help/syntax checks. Earlier independent review of the unchanged Go code passed eight targeted top-level tests / 59 subtests with race detection.

Full conformance scripts were not executed locally. Remote CI and maintainer approval for this new head are separate from local validation and previous-head checks.

AI assistance was used for implementation, tests, merge verification, and this description. The independent review above was automated, not human or maintainer approval.

po-et added 7 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
Check the roots capability in the shared client handler so modern input
requests respect explicitly disabled roots, as the legacy server API does.
Return the standard method-not-found error on the client rejection path.
Cover both protocol versions and raw legacy requests in regression tests.

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