Skip to main content
AgentScope integrates with Model Context Protocol (MCP) servers, letting an agent reach any MCP-compatible tool provider. The framework handles protocol negotiation, tool discovery, and result conversion automatically. Two connection modes are supported: MCP tools are namespaced as mcp__{server_name}__{tool_name} to avoid name collisions, and tools annotated with readOnlyHint are recognized as read-only by the permission system (auto-allowed in EXPLORE and ACCEPT_EDITS modes; in DEFAULT they still ASK unless an allow rule matches). AgentScope 2.0.11 uses the MCP Python SDK 2.x (mcp>=2.0.0). Protocol negotiation is automatic for existing STDIO, Streamable HTTP, and SSE servers.

Register MCP Client

Build one or more MCPClient instances and pass them to Toolkit(mcps=[...]). Stateful clients must be connected before the toolkit is constructed.

Filter Exposed Tools

To expose only a subset of an MCP server’s tools, set enable_tools or disable_tools on the client itself:

Update HTTP Headers at Runtime

The headers in mcp_config are fixed at construction. When an auth token rotates mid-session, call set_runtime_headers() on a Streamable HTTP client to replace the headers sent with subsequent requests — no rebuild and no reconnect:
The behaviour has a few boundaries worth knowing:
In a Docker workspace the live MCP client runs inside the gateway process and the host holds a proxy. Calling set_runtime_headers() on the proxy relays the update to the gateway — see MCP Gateway.

Use MCP Tools Outside a Toolkit

If you need to invoke MCP tools outside a Toolkit, call await client.list_tools() to retrieve a list of MCPTool adapters and use them like any other ToolBase instance.

Stream Tool Progress

Set stream_progress=True on a local MCPClient to show progress while a server executes a tool. The server must emit MCP progress notifications:
Enable progress notifications
During Agent.reply_stream(), progress arrives as CustomEvent(name="mcp_progress"). Its value contains reply_id, tool_call_id, progress, and optional total and message values. Use the IDs to update the matching tool indicator. These are transient snapshots: consumers must not rely on receiving every update. They are excluded from the final tool result and ignored by Msg.append_event(). Outside a toolkit, await tool(...) returns an asynchronous iterator of ToolChunk objects when streaming is enabled. Progress is carried in chunk.metadata["mcp_progress"], followed by the final result chunk. With the default stream_progress=False, it returns only the final chunk.
Sandbox gateway tools return only final results even when the configuration enables progress streaming. If an MCP result contains structured content but no text block, AgentScope adds its JSON representation to the final result.