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%Langchain

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