Add ClientSession.register_tool_schema() for dynamic tool discovery - #3290
Add ClientSession.register_tool_schema() for dynamic tool discovery#3290HaoChiBao 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 PR has been closed automatically. It's still a draft, but we close those early so you don't put in more time only to have it closed the moment you mark it ready. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3145. If a maintainer assigns you to #3145, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
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.