MCPToolkit connects to one or more MCP (Model Context Protocol) servers and exposes their tools as native agent tools. Your agent can call any tool from any connected MCP server without additional configuration.
Basic Usage
Parameters
MCPConfig
required
MCP configuration with server definitions.
str
default:"\"\""
Prefix added to all tool names (e.g.,
"mcp_").bool
default:"true"
Whether to include the server name in tool names (e.g.,
filesystem_list_files).bool
default:"false"
Require user confirmation before executing any MCP tool.
Multiple Servers
Connect to several MCP servers at once. Tools from all servers are available to the agent:Context Manager
MCPToolkit must be used as a context manager to properly manage server connections:
Tool Discovery
After initialization, inspect available tools:Refreshing Tools
If server tools change at runtime, refresh the tool list:Combining with Other Toolkits
MCP toolkit works alongside other toolkits and individual tools:Agent-Managed Lifecycle
Instead of manually managing the toolkit lifecycle withasync with, you can let the agent handle it automatically. When you pass an uninitialized MCPToolkit to an agent, the agent will initialize it on first use and shut it down when the agent shuts down:
If you pre-initialize the toolkit yourself (via
async with toolkit: or await toolkit.initialize()), the agent detects this and does not take ownership — you remain responsible for shutting it down.