-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
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) -> CallToolResultThis 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,
) -> CallToolResultThe 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
- Subclassing
_MCPServerWithClientSession— requires duplicating significant implementation code and accessing private APIs - Using
session.send_request()directly — bypasses the SDK's retry logic and error handling - 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
- MCP Specification: https://modelcontextprotocol.io/specification/2025-11-25/basic#general-fields
- MCP Python SDK changelog for
metasupport: https://github.com/modelcontextprotocol/python-sdk/releases/tag/v1.19.0