FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add ClientSession.register_tool_schema() for dynamic tool discovery by HaoChiBao · Pull Request #3290 · modelcontextprotocol/python-sdk · GitHub

Add ClientSession.register_tool_schema() for dynamic tool discovery - #3290

Draft
HaoChiBao wants to merge 1 commit into
modelcontextprotocol:mainfrom
HaoChiBao:feat/3145-register-tool-schema
Draft

Add ClientSession.register_tool_schema() for dynamic tool discovery#3290
HaoChiBao wants to merge 1 commit into
modelcontextprotocol:mainfrom
HaoChiBao:feat/3145-register-tool-schema

Conversation

HaoChiBao commented Aug 11, 2026
edited
Loading

Copy link
Copy Markdown

Summary

  • Adds public ClientSession.register_tool_schema(name, output_schema=None) so dynamically discovered tools (absent from list_tools()) can populate the output-schema cache without touching private _tool_output_schemas.
  • Mirrors the same helper on high-level Client.
  • Keeps the compiled validator cache consistent: a changed registration evicts the compiled validator (same _same_schema check as _absorb_tool_listing).
  • Documents interaction with complete 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 skips structuredContent validation 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 work not 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 -q
  • uv run --frozen ruff check / ruff format --check on touched files
  • uv run --frozen pyright on touched modules
  • CI on the PR

AI disclosure

Implemented with AI assistance (Cursor). I reviewed and understand the full change, including validator-cache eviction and the documented list_tools() prune interaction.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ClientSession.register_tool_schema() for dynamic tool discovery patterns

1 participant


Back | FazBrowse Home | New Git URL