Problem
There is a _meta filed per MCP _meta specification:
The `_meta` property/parameter is reserved by MCP to allow clients and servers to attach additional metadata to their interactions.
Currently @langchain/mcp-adapters does NOT expose a way to attach MCP protocol _metaon tool invocations.
It makes it hard to cover the following use cases:
- Distributed tracing / correlation IDs on `tools/call` without HTTP header forks
- Per-request session / user / tenant context the LLM must not see in tool args
- Parity with Python adapters and LangChain4j for multi-language stacks
Proposal
- Extend
beforeToolCall/ tool-call modification to allow_meta(e.g. return{ args?, headers?, _meta? }ormeta)-
const client = new MultiServerMCPClient({ mcpServers: { /* ... */ }, beforeToolCall: ({ name, args }, _state, config) => ({ args, // protocol-level metadata — must NOT require fork() _meta: { "com.example/correlation_id": config?.configurable?.correlation_id, "com.example/trace_id": config?.configurable?.session_id, }, }), });
-
- Forward that value into the underlying MCP SDK
callToolparams as protocol_meta - Optionally surface response
_metaon the tool result / artifact (as Python PR #423 does).