MCP Tool Provider
The stirrup.tools.mcp module provides MCP (Model Context Protocol) integration.
Note
Requires pip install stirrup[mcp] (or: uv add stirrup[mcp])
MCPToolProvider
stirrup.tools.mcp.MCPToolProvider
Bases: ToolProvider
MCP tool provider that manages connections to multiple MCP servers.
MCPToolProvider connects to MCP servers and exposes each server's tools as individual Tool objects.
Usage with Agent (preferred): from stirrup.clients.chat_completions_client import ChatCompletionsClient
client = ChatCompletionsClient(model="gpt-5")
agent = Agent(
client=client,
name="assistant",
tools=[*DEFAULT_TOOLS, MCPToolProvider.from_config("mcp.json")],
)
async with agent.session(output_dir="./output") as session:
await session.run("Use MCP tools")
Standalone usage with connect() context manager: provider = MCPToolProvider.from_config(Path("mcp.json")) async with provider.connect() as provider: tools = provider.get_all_tools() # Use tools...
Initialize the MCP manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
MCPConfig
|
MCPConfig instance. |
required |
server_names
|
list[str] | None
|
Which servers to connect to. If None, connects to all servers in config. |
None
|
Source code in src/stirrup/tools/mcp.py
from_config
classmethod
Create an MCPToolProvider from a config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Path | str
|
Path to the MCP config file. |
required |
server_names
|
list[str] | None
|
Which servers to connect to. If None, connects to all servers in config. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
MCPToolProvider instance. |
Source code in src/stirrup/tools/mcp.py
__aenter__
async
__aenter__() -> list[Tool[Any, ToolUseCountMetadata]]
Enter async context: connect to MCP servers and return all tools.
Returns:
| Type | Description |
|---|---|
list[Tool[Any, ToolUseCountMetadata]]
|
List of Tool objects, one for each tool available across all connected servers. |
Source code in src/stirrup/tools/mcp.py
__aexit__
async
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Exit async context: disconnect from MCP servers.
Source code in src/stirrup/tools/mcp.py
Configuration Models
MCPConfig
stirrup.tools.mcp.MCPConfig
Bases: BaseModel
Root configuration matching mcp.json format.
mcp_servers
class-attribute
instance-attribute
Map of server names to their configurations.
_infer_transport_types
classmethod
Convert raw server configs to appropriate typed instances.
Source code in src/stirrup/tools/mcp.py
Server Configurations
StdioServerConfig
For local command-based MCP servers:
stirrup.tools.mcp.StdioServerConfig
Bases: BaseModel
Configuration for stdio-based MCP servers (local process).
args
class-attribute
instance-attribute
Arguments to pass to the command.
env
class-attribute
instance-attribute
Environment variables to set for the server process.
cwd
class-attribute
instance-attribute
cwd: str | None = None
Working directory for the server process.
SseServerConfig
For SSE (Server-Sent Events) based MCP servers:
stirrup.tools.mcp.SseServerConfig
Bases: BaseModel
Configuration for SSE-based MCP servers (HTTP GET with Server-Sent Events).
headers
class-attribute
instance-attribute
Optional HTTP headers.
timeout
class-attribute
instance-attribute
timeout: float = 5.0
HTTP timeout for regular operations (seconds).
sse_read_timeout
class-attribute
instance-attribute
sse_read_timeout: float = 300.0
Timeout for SSE read operations (seconds).
StreamableHttpServerConfig
For streamable HTTP MCP servers:
stirrup.tools.mcp.StreamableHttpServerConfig
Bases: BaseModel
Configuration for Streamable HTTP MCP servers (HTTP POST with optional SSE responses).
headers
class-attribute
instance-attribute
Optional HTTP headers.
sse_read_timeout
class-attribute
instance-attribute
sse_read_timeout: float = 300.0
SSE read timeout (seconds).
terminate_on_close
class-attribute
instance-attribute
terminate_on_close: bool = True
Close session when transport closes.
WebSocketServerConfig
For WebSocket-based MCP servers:
stirrup.tools.mcp.WebSocketServerConfig
Bases: BaseModel
Configuration for WebSocket-based MCP servers.