Skip to content

feat: add MCP tool call result callback#3479

Open
seratch wants to merge 1 commit into
mainfrom
feat/mcp-tool-call-result-callback
Open

feat: add MCP tool call result callback#3479
seratch wants to merge 1 commit into
mainfrom
feat/mcp-tool-call-result-callback

Conversation

@seratch
Copy link
Copy Markdown
Member

@seratch seratch commented May 21, 2026

This pull request adds a tool_call_result_callback option for local MCP servers so applications can observe MCP CallToolResult metadata without changing the model-visible tool output. The callback receives an MCPToolCallResultContext with the original MCP tool name, public display name, parsed arguments, _meta, structuredContent, isError, and a copied tool output, which lets apps collect frontend-facing data for dual-output MCP tools while keeping replay and model history behavior unchanged.

This pull request resolves #3477.

from agents.mcp import MCPServerStreamableHttp, MCPToolCallResultContext


def tool_call_result_callback(context: MCPToolCallResultContext) -> None:
    app_context = context.run_context.context
    if not isinstance(app_context, dict) or context.result_meta is None:
        return

    app_context.setdefault("frontend_events", []).append(
        {
            "server": context.server_name,
            "tool": context.tool_display_name,
            "meta": dict(context.result_meta),
        }
    )


server = MCPServerStreamableHttp(
    name="Metadata-aware MCP",
    params={"url": "http://localhost:8000/mcp"},
    tool_call_result_callback=tool_call_result_callback,
)

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.

Read _meta from MCP Tool Call Responses

1 participant