Skip to content

Support passing metadata (_meta) in MCP tool calls #2367

@pshopper

Description

@pshopper

Feature request

Is your feature request related to a problem?

When using MCP servers with the Agents SDK, there is no way to pass metadata (_meta) with tool call requests. The MCP protocol supports a _meta field in CallToolRequest (see MCP spec - Calling tools), which allows clients to include additional context such as:

  • Request correlation IDs for debugging and distributed tracing
  • User context (locale, session info) for MCP servers that need request-specific behavior

Currently, the MCPServer.call_tool() method signature is:

async def call_tool(self, tool_name: str, arguments: dict[str, Any] | None) -> CallToolResult

This prevents users from leveraging the full MCP protocol capabilities when invoking tools.

Describe the solution you'd like

Add an optional meta parameter to MCPServer.call_tool():

async def call_tool(
    self,
    tool_name: str,
    arguments: dict[str, Any] | None,
    meta: dict[str, Any] | None = None,
) -> CallToolResult

The meta parameter should be passed through to the underlying MCP ClientSession.call_tool() method, which already supports it (as of mcp>=1.19.0).

Describe alternatives you've considered

  1. Subclassing _MCPServerWithClientSession — requires duplicating significant implementation code and accessing private APIs
  2. Using session.send_request() directly — bypasses the SDK's retry logic and error handling
  3. Patching the session object — fragile and not recommended for production use

None of these alternatives provide a clean, supported way to pass metadata.

Additional context

Example use case — passing request context for debugging and tracing:

server = MCPServerStreamableHttp(name="worker", params={"url": "http://localhost:8000/mcp"})
await server.connect()

# Pass request metadata for tracing and debugging
result = await server.call_tool(
    "search_documents",
    {"query": "quarterly report"},
    meta={"requestId": "req-abc-123", "locale": "en-US"}
)

The MCP library (mcp>=1.19.0) already supports the meta parameter in ClientSession.call_tool(), so this change would align the Agents SDK with the underlying library capabilities.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions