Skip to content

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

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

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

@HaoChiBao HaoChiBao commented Aug 11, 2026

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
@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

@github-actions github-actions Bot closed this Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

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