Validate elicitation sub-capabilities in check_capability#3061
Open
Rodrigo-Palma wants to merge 2 commits into
Open
Validate elicitation sub-capabilities in check_capability#3061Rodrigo-Palma wants to merge 2 commits into
Rodrigo-Palma wants to merge 2 commits into
Conversation
check_capability only rejected a requested elicitation capability when the client declared no elicitation support at all, ignoring the form/url sub-capabilities. A client that advertised only URL-mode elicitation would incorrectly pass a check for form-mode elicitation (and vice versa). Mirror the existing sampling sub-capability handling: when a specific elicitation mode is requested, require the client to declare that mode. A bare elicitation request is still satisfied by any elicitation support. Fixes modelcontextprotocol#2965
Document that check_client_capability inspects the elicitation form/url sub-capabilities, so a tool can choose a mode the client actually supports before it asks. Companion to the check_capability sub-capability fix.
bddfe3c to
22da7a0
Compare
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.
Connection.check_capability()(exposed publicly viaServerSession.check_client_capability) rejected a requestedelicitationcapability only when the client declared no elicitation support at all. It never inspected theform/urlsub-capabilities, so a client that advertised only URL-mode elicitation would incorrectly pass a check for form-mode elicitation, and vice versa.Handle elicitation the same way as
sampling: when a specific mode is requested, require the client to declare that mode. A bare elicitation request is still satisfied by any elicitation support.Fixes #2965
Motivation and Context
check_capabilitymirrors the (correct)samplinghandling for the top-level presence check but omits the per-sub-capability checks thatsamplingperforms forcontext/tools:Because it only returns
Falsewhen the client has no elicitation at all, a caller checking for form-mode elicitation against a URL-only client (or vice versa) gets a wrongTrue. This is public API, so once a caller relies on it (e.g. checking for form support beforeelicit_form), it silently returns incorrect results.The fix adds the
form/urlsub-capability checks, matching thesamplingpattern:Scope kept to elicitation. The issue also mentioned
extensionsandtasksas lower-priority gaps:extensionsis already handled onmain(SEP-2133), andtasksis left out to keep this tightly scoped — happy to follow up separately if desired.How Has This Been Tested?
Extended the existing
test_check_capability_per_field_branchesparametrization intests/server/test_connection.pywith the elicitation branches: the two bug cases (URL-only client vs. form request, and form-only client vs. URL request), the matching positive cases, and the bare-request case. The two bug cases fail onmainand pass with this change; the fulltest_connection.pysuite is green (44 passed).ruff check,ruff format --check, andpyrightare all clean on the changed files.Docs: added a short "Ask only in a mode the client supports" section to
docs/handlers/elicitation.mdshowing how a server usescheck_client_capabilityto pick a form/url mode the client supports before eliciting.mkdocs build --strictpasses.Breaking Changes
No API change.
check_capabilitynow returns the correctFalsefor a requested elicitation mode the client does not support (previously a wrongTrue). Callers that were (incorrectly) relying on the old always-true-when-any-elicitation behavior would see the corrected result.Types of changes
Checklist
Additional context
AI assistance: I used AI tooling to help analyze the issue, draft the fix, and scaffold the tests. I reviewed and understand the change, stand behind it, and can discuss it directly.