Skip to content

Conversation

@seratch
Copy link
Member

@seratch seratch commented Jan 29, 2026

This pull request resolves #2367

Here is a documentation draft:

If you need to attach MCP request metadata to tool calls, supply a tool_meta_resolver when constructing the server. The resolver receives an [MCPToolMetaContext][agents.mcp.MCPToolMetaContext] and returns a dict that is sent as MCP _meta.

from agents import Agent, Runner
from agents.mcp import MCPToolMetaContext, MCPServerStreamableHttp

def resolve_meta(args: MCPToolMetaContext) -> dict[str, str]:
    return {"request_id": args.run_context.context["request_id"]}

async def main() -> None:
    async with MCPServerStreamableHttp(
        name="Streamable HTTP Server",
        params={"url": "http://localhost:8000/mcp"},
        tool_meta_resolver=resolve_meta,
    ) as server:
        agent = Agent(
            name="Assistant",
            instructions="Use MCP tools when helpful.",
            mcp_servers=[server],
        )
        await Runner.run(
            agent,
            "List available resources.",
            context={"request_id": "req-123"},
        )

Notes:

  • The resolver runs before each MCP tool invocation during agent runs.
  • If you pass explicit meta when calling MCPUtil.invoke_mcp_tool, it is merged over the resolver output.
  • list_tools() does not accept metadata in the MCP Python SDK yet.
  • If you call server.call_tool directly, pass meta yourself; the resolver is only used by the Agents SDK call path.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 449174b96b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@seratch seratch added this to the 0.8.x milestone Jan 29, 2026
@seratch seratch marked this pull request as draft January 29, 2026 03:56
@seratch seratch force-pushed the feat/mcp-tool-meta-resolver branch from 0e18382 to 709d248 Compare January 29, 2026 04:08
@seratch seratch marked this pull request as ready for review January 29, 2026 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support passing metadata (_meta) in MCP tool calls

2 participants