AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Feature Request: Pass `_Meta` Parameter Through To MCP SDK `Call_tool()`

langchain-mcp-adapters does not pass the MCP `_meta` field from tool arguments to the MCP SDK's `call_tool()`, preventing per-request metadata like session IDs, routing tags, or tenant context from reaching MCP servers.

mediumConfidence 85%LangchainVector Storeslangchain-core

Origin Analysis

The MCPToolCallRequest dataclass lacks a `meta` field, the `_invoke` helper passes the full args dict to `call_tool` without extracting `_meta`, and the `_handler` never forwards metadata to the MCP SDK.
1. Create an MCP tool with a server that logs or validates `_meta`. 2. Invoke the LangChain wrapped tool with arguments `{'message': 'hello', '_meta': {'session_id': 'abc123'}}` using `tool.ainvoke`. 3. Observe that the MCP server does not receive any `_meta` metadata and may treat `_meta` as a normal tool argument.

Fixing Code Block

# In langchain_mcp_adapters/tools.py # 1) Add meta field to dataclass (inside MCPToolCallRequest) meta: dict[str, Any] | None = None # 2) In _invoke, before constructing MCPToolCallRequest: tool_args = dict(args) meta = tool_args.pop('_meta', None) call_request = MCPToolCallRequest( name=tool.name, args=tool_args, headers=headers, timeout=timeout, meta=meta, interceptors=interceptors, ) # 3) In _handler, when calling session.call_tool: response = await session.call_tool( request.name, arguments=request.args, read_timeout_seconds=request.timeout, headers=request.headers, meta=request.meta, )
Adds a `meta` field to `MCPToolCallRequest`, extracts `_meta` from the incoming tool arguments before constructing the request (avoiding mutation of the original args), and forwards `meta` to `ClientSession.call_tool()` in the low-level handler. Interceptors can also override `meta` via `request.override(meta={...})`.

Edge Case Audit

This change requires an MCP SDK version that supports the `meta` parameter in `ClientSession.call_tool()` (spec 2025-06-18 or later). On older SDK versions a `TypeError` will occur. Ensure the extracted `_meta` is a dict or `None`; non-dict values will be rejected by the SDK. If this patch is reverted, user code relying on `_meta` being stripped from tool arguments will break again; consider a deprecation period or keep extracting `_meta` even if not forwarded. Concurrent invocations using the same interceptor should not mutate the request object; the current `override` creates a new dataclass, which is safe.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state