fix(server): validate elicitation form/url sub-capabilities in check_capability#2979
Open
syf2211 wants to merge 1 commit into
Open
Conversation
…capability Connection.check_capability() only verified that the client declared elicitation at all, not whether specific sub-capabilities (form vs url) matched. Mirror the existing sampling sub-capability checks. Fixes modelcontextprotocol#2965
|
Good fix! Validating each elicitation sub-capability (form/url) separately is more precise than the previous all-or-nothing check. The parametrized test matrix covering form-only, url-only, both, and mismatched cases is thorough. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Connection.check_capability()now validates elicitation sub-capabilities (form/url) when the caller specifies them, instead of only checking whether the client declared elicitation at all.Motivation
Fixes #2965.
When a client supports URL-mode elicitation only,
check_capability(ClientCapabilities(elicitation=ElicitationCapability(form=FormElicitationCapability())))incorrectly returnedTrue. The function only compared top-levelhave.elicitation is None, never inspecting individual sub-capabilities.This mirrors the existing
sampling.context/sampling.toolssub-capability checks in the same function.Changes
src/mcp/server/connection.py: Add nestedform/urlpresence checks under the elicitation branch.tests/server/test_connection.py: Add 6 parametrized regression cases covering form/url mismatch, match, and generic elicitation checks.Tests
uv run pytest tests/server/test_connection.py— 44 passeduv run ruff check src/mcp/server/connection.py tests/server/test_connection.py— cleanuv run ruff format --check src/mcp/server/connection.py tests/server/test_connection.py— cleanNotes
ServerSession.check_client_capability()delegates toConnection.check_capability(), so this fix applies to both APIs.