Skip to content

fix(langchain): load MCP tool metadata on the invocation session - #41749

Closed
John Kennedy (jkennedyvz) wants to merge 3 commits into
masterfrom
jkennedyvz/langchain/mcp-param-headers
Closed

John Kennedy (jkennedyvz) wants to merge 3 commits into
masterfrom
jkennedyvz/langchain/mcp-param-headers

Conversation

@jkennedyvz

@jkennedyvz John Kennedy (jkennedyvz) commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Detached MCP tools reconnect after discovery, but the MCP SDK only mirrors x-mcp-header arguments after listing tools on that session. Load the serving client’s listing with cache_mode="use" before either invocation path so cached metadata is reabsorbed and Mcp-Param-* headers reach the server.

Each session lists once, before its first call to a tool it has not listed yet. This adds no tools/list requests: the SDK already lists after any successful call on an unlisted session to load output schemas, so this moves that request ahead of the call. Long-held sessions do not list again on later calls.

The HTTP regression uses the SDK server’s real argument-header validation, covers direct/group clients and ordinary/interrupt-driven calls.

Compatible with #41736: the listing belongs immediately inside its serving-member connection; this PR leaves that independent connection-routing change untouched.

Local checks found an existing failure in test_separate_adapters_keep_their_own_protocol_era (the original client is disconnected because the adapter clones it); it also fails with this fix removed.

Release note

MCP tools invoked after discovery reconnect with the metadata required to send argument headers.

Implemented with AI assistance.

References

Made by Robin · view thread · openai:gpt-6.1-sol (medium)

@github-actions github-actions Bot added fix For PRs that implement a fix internal langchain `langchain` package issues & PRs size: S 50-199 LOC labels Nov 7, 2026

@robin-agent robin-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robin Review found 1 potential issue.

Open in Web

@codspeed

codspeed Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 note

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: the symbols of the profiling trace could not be resolved, because no information about the language frames was collected.

See affected benchmarks

✅ 2 untouched benchmarks
⏩ 15 skipped benchmarks1


Comparing jkennedyvz/langchain/mcp-param-headers (aaf8b8e) with master (ccf1624)2

Open in CodSpeed

Footnotes

  1. 15 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on master (92c7def) during the generation of this report, so ccf1624 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@jkennedyvz
John Kennedy (jkennedyvz) marked this pull request as ready for review November 7, 2026 23:51
Co-authored-by: Robin <open-swe@users.noreply.github.com>
The SDK already lists after a call on an unlisted session, so listing before the first call moves that request rather than adding one; held sessions no longer re-list on every call.

Co-authored-by: Robin <open-swe@users.noreply.github.com>
@robin-agent
robin-agent Bot force-pushed the jkennedyvz/langchain/mcp-param-headers branch from ff5b823 to aaf8b8e Compare November 17, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix For PRs that implement a fix internal langchain `langchain` package issues & PRs size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant