Add ClientSession.register_tool_schema() for dynamic tool discovery - #3290
Draft
HaoChiBao wants to merge 1 commit into
Draft
Add ClientSession.register_tool_schema() for dynamic tool discovery#3290HaoChiBao wants to merge 1 commit into
HaoChiBao wants to merge 1 commit into
Conversation
Lets clients register output schemas for tools that never appear in list_tools(), so call_tool can validate structuredContent without touching private caches. Mirrored on Client; complete listings still prune unlisted registrations. Fixes modelcontextprotocol#3145
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
ClientSession.register_tool_schema(name, output_schema=None)so dynamically discovered tools (absent fromlist_tools()) can populate the output-schema cache without touching private_tool_output_schemas.Client._same_schemacheck as_absorb_tool_listing).list_tools(): an uncursored single-page listing still prunes schemas for tools not in that listing (including manual registrations); re-register if still needed. A listing that includes the name replaces the registered schema.Fixes #3145
Motivation
Servers that use search/catalog-style discovery (e.g. Bedrock AgentCore Gateway) intentionally return only a small
list_tools()subset. Invoking discovered tools today logs a warning and skipsstructuredContentvalidation unless callers write the private cache. This PR adds the small public API proposed in the issue.Design notes / ask for review
Issue #3145 is unlabeled (
ready for worknot present). Claimed on the issue; happy to adjust API/prune semantics if maintainers prefer a different contract (e.g. surviving complete listings). Preferring a ready PR over draft for reviewability.Test plan
uv run --frozen pytest tests/client/test_register_tool_schema.py tests/client/test_session_promotions.py -quv run --frozen ruff check/ruff format --checkon touched filesuv run --frozen pyrighton touched modulesAI disclosure
Implemented with AI assistance (Cursor). I reviewed and understand the full change, including validator-cache eviction and the documented
list_tools()prune interaction.