Skip to content

feat(mcp): add async_mode to MCPToolset#5694

Open
longcw wants to merge 2 commits intomainfrom
longc/mcp-toolset-async-mode
Open

feat(mcp): add async_mode to MCPToolset#5694
longcw wants to merge 2 commits intomainfrom
longc/mcp-toolset-async-mode

Conversation

@longcw
Copy link
Copy Markdown
Contributor

@longcw longcw commented May 9, 2026

Summary

MCPToolset now extends AsyncToolset and gains a keyword-only async_mode flag. When enabled, MCP tools are built with an AsyncRunContext parameter and the MCP server's progress notifications are forwarded via ctx.update, so the agent can narrate progress while a slow MCP tool runs in the background.

Agent(tools=[
    MCPToolset(
        id="search",
        mcp_server=MCPServerHTTP(url="...", client_session_timeout_seconds=120),
        async_mode=True,
    ),
])

Example

examples/voice_agents/mcp/server.py now ships a fast get_weather (sync, no progress) and a long-running book_flight that emits ctx.report_progress updates over ~70s. mcp-agent.py uses async_mode=True and bumps client_session_timeout_seconds=120 since the per-request timeout otherwise fires before book_flight returns.

MCPToolset now extends AsyncToolset and gains an `async_mode=True` flag.
When set, MCP tools are built with an `AsyncRunContext` parameter that
forwards MCP progress notifications via `ctx.update`, so the agent can
narrate progress while a slow MCP tool runs in the background instead of
blocking the reply loop.

`AsyncToolset` no longer stores `get_running_tasks` / `cancel_task` in
`_tools`; they're exposed through a `tools` property override that
subclasses can condition. `MCPToolset` overrides it to expose the
helpers only when `async_mode=True`, so the legacy MCP UX is unchanged
when the flag is off.

`MCPServer.list_tools` now caches per `async_mode`, and the example MCP
server gains a long-running `book_flight` tool that emits progress
updates.
@chenghao-mou chenghao-mou requested a review from a team May 9, 2026 01:59
devin-ai-integration[bot]

This comment was marked as resolved.

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant