MCP Tool Provider
MCPToolProvider is a drop-in replacement for AgentTools that connects one or more MCP (Model Context Protocol) servers to any agent-squad agent. Tools are fetched from the servers at startup and exposed to the agent with no extra wiring — the existing tool_config / toolConfig mechanism handles everything.
How it works
Section titled “How it works”- You call
await MCPToolProvider.create(servers)which connects to each MCP server and fetches its tool list before returning. - The tool schemas (already JSON Schema) are passed through directly to the agent’s provider format (Bedrock, Anthropic, OpenAI).
- When the agent calls a tool,
MCPToolProviderroutes the call to the correct server and returns the result. - Errors reported by the server (
isError: true) are surfaced back to the model as an error string rather than crashing.
The async factory pattern is required because the agent needs tool definitions synchronously when building each API request. Using create() ensures the connection and tool list are ready before the agent is used.
Installation
Section titled “Installation”npm install agent-squadnpm install @modelcontextprotocol/client # MCP SDK v2 — recommendedOr the v1 SDK, if you only talk to servers on protocol 2025-11-25 or older:
npm install @modelcontextprotocol/sdkBoth are optional peer dependencies — never installed automatically. When both are present, MCPToolProvider uses v2.
| Installed package | MCP protocol versions | Notes |
|---|---|---|
| @modelcontextprotocol/client >= 2.0.0 | 2026-07-28 and all legacy versions | auto-negotiated per server (server/discover probe with initialize fallback); Node >= 20 |
| @modelcontextprotocol/sdk >= 1.0.0 | 2025-11-25 and older | the v1 package will never support 2026-07-28 |
pip install "agent-squad[mcp]"The mcp extra is optional — it is not pulled in when you install the base package. Both SDK majors are supported:
| Installed mcp version | MCP protocol versions | Notes |
|---|---|---|
| mcp >= 2.0 | 2026-07-28 and all legacy versions | auto-negotiated per server (server/discover probe with initialize fallback) |
| mcp 1.x | 2025-11-25 and older | the 1.x line will not receive 2026-07-28 support |
Basic usage
Section titled “Basic usage”import { AgentSquad, BedrockLLMAgent, MCPToolProvider } from "agent-squad";
const provider = await MCPToolProvider.create([ { type: "stdio", command: "uvx", args: ["my-mcp-server"] },]);
const agent = new BedrockLLMAgent({ name: "mcp-agent", description: "An agent that uses tools from an MCP server", toolConfig: { tool: provider },});
const orchestrator = new AgentSquad();orchestrator.addAgent(agent);
// When done, clean up server connections:await provider.disconnect();from agent_squad import AgentSquadfrom agent_squad.agents import BedrockLLMAgent, BedrockLLMAgentOptionsfrom agent_squad.tools import MCPToolProvider, MCPServerConfig
provider = await MCPToolProvider.create([ MCPServerConfig(type="stdio", command="uvx", args=["my-mcp-server"]),])
agent = BedrockLLMAgent(BedrockLLMAgentOptions( name="mcp-agent", description="An agent that uses tools from an MCP server", tool_config={"tool": provider}))
orchestrator = AgentSquad()orchestrator.add_agent(agent)
# When done, clean up server connections:await provider.disconnect()Transports
Section titled “Transports”MCPToolProvider supports three transports: stdio, streamable-http, and sse.
stdio — spawn a local process
Section titled “stdio — spawn a local process”The most common transport. Agent Squad launches the MCP server as a subprocess and communicates over stdin/stdout.
import { MCPToolProvider } from "agent-squad";
const provider = await MCPToolProvider.create([ { type: "stdio", command: "uvx", args: ["my-mcp-server", "--config", "config.json"], env: { API_KEY: process.env.MY_API_KEY! }, },]);from agent_squad.tools import MCPToolProvider, MCPServerConfig
provider = await MCPToolProvider.create([ MCPServerConfig( type="stdio", command="uvx", args=["my-mcp-server", "--config", "config.json"], env={"API_KEY": os.environ["MY_API_KEY"]}, )])Streamable HTTP — connect to a remote server
Section titled “Streamable HTTP — connect to a remote server”The current standard HTTP transport for remote MCP servers. Use this for any server you don’t spawn locally, unless it only speaks the older SSE protocol.
import { MCPToolProvider } from "agent-squad";
const provider = await MCPToolProvider.create([ { type: "streamable-http", url: "http://localhost:3000/mcp", headers: { Authorization: `Bearer ${process.env.MCP_TOKEN}` }, },]);Requires @modelcontextprotocol/client (any version) or @modelcontextprotocol/sdk >= 1.10.
from agent_squad.tools import MCPToolProvider, MCPServerConfig
provider = await MCPToolProvider.create([ MCPServerConfig( type="streamable-http", url="http://localhost:3000/mcp", headers={"Authorization": f"Bearer {os.environ['MCP_TOKEN']}"}, )])Requires mcp >= 1.9 (already satisfied by a fresh pip install "agent-squad[mcp]"). On mcp 2.x, headers are delivered through the SDK’s httpx client factory — same config, no code change.
SSE — connect to a legacy remote server
Section titled “SSE — connect to a legacy remote server”Connect to an MCP server running over HTTP Server-Sent Events (SSE). This is the older HTTP transport, deprecated by the MCP spec since 2025-03-26 — prefer streamable-http for servers that support it.
import { MCPToolProvider } from "agent-squad";
const provider = await MCPToolProvider.create([ { type: "sse", url: "http://localhost:3000/sse", headers: { Authorization: `Bearer ${process.env.MCP_TOKEN}` }, },]);from agent_squad.tools import MCPToolProvider, MCPServerConfig
provider = await MCPToolProvider.create([ MCPServerConfig( type="sse", url="http://localhost:3000/sse", headers={"Authorization": f"Bearer {os.environ['MCP_TOKEN']}"}, )])Multiple servers
Section titled “Multiple servers”You can connect to multiple MCP servers at once. Tools from all servers are merged into a single flat list. If two servers expose a tool with the same name, the first server’s tool wins.
import { MCPToolProvider } from "agent-squad";
const provider = await MCPToolProvider.create([ { type: "stdio", command: "uvx", args: ["filesystem-server"] }, { type: "stdio", command: "uvx", args: ["database-server"] }, { type: "streamable-http", url: "https://api.example.com/mcp" },]);from agent_squad.tools import MCPToolProvider, MCPServerConfig
provider = await MCPToolProvider.create([ MCPServerConfig(type="stdio", command="uvx", args=["filesystem-server"]), MCPServerConfig(type="stdio", command="uvx", args=["database-server"]), MCPServerConfig(type="streamable-http", url="https://api.example.com/mcp"),])Using with any agent
Section titled “Using with any agent”MCPToolProvider works with every agent that accepts AgentTools — just drop it in as the tool value.
import { AnthropicAgent, OpenAIAgent, MCPToolProvider } from "agent-squad";
const mcpTools = await MCPToolProvider.create([ { type: "stdio", command: "uvx", args: ["my-mcp-server"] },]);
// Anthropicconst anthropicAgent = new AnthropicAgent({ name: "anthropic-agent", description: "Agent with MCP tools", apiKey: process.env.ANTHROPIC_API_KEY!, toolConfig: { tool: mcpTools },});
// OpenAIconst openaiAgent = new OpenAIAgent({ name: "openai-agent", description: "Agent with MCP tools", apiKey: process.env.OPENAI_API_KEY!, toolConfig: { tool: mcpTools },});from agent_squad.agents import AnthropicAgent, AnthropicAgentOptionsfrom agent_squad.agents import OpenAIAgent, OpenAIAgentOptionsfrom agent_squad.tools import MCPToolProvider, MCPServerConfig
mcp_tools = await MCPToolProvider.create([ MCPServerConfig(type="stdio", command="uvx", args=["my-mcp-server"]),])
# Anthropicanthropic_agent = AnthropicAgent(AnthropicAgentOptions( name="anthropic-agent", description="Agent with MCP tools", api_key=os.environ["ANTHROPIC_API_KEY"], tool_config={"tool": mcp_tools},))
# OpenAIopenai_agent = OpenAIAgent(OpenAIAgentOptions( name="openai-agent", description="Agent with MCP tools", api_key=os.environ["OPENAI_API_KEY"], tool_config={"tool": mcp_tools},))Tool UI (widgets)
Section titled “Tool UI (widgets)”If an MCP server advertises a UI widget on a tool — via _meta.ui.resourceUri (or the OpenAI openai/outputTemplate alias), the same “MCP Apps” contract ChatGPT Apps use — MCPToolProvider surfaces it instead of flattening the result to text. On a call it reads the result’s structuredContent, fetches the advertised UI resource (resources/read, cached), and returns a ToolResult carrying a UIPayload (its resource URI, MIME type, template, render-only structured content, and meta). Tools whose _meta.ui.visibility excludes model stay callable but are never advertised to the LLM.
Pair the provider with a GroundedAgent and the widget is forwarded to the caller on the streaming response, exactly like a native tool that returns a UIPayload — so the same MCP server that backs a ChatGPT App renders its widgets here. For a server that advertises no _meta.ui, the model sees the same text as before.
Available in the Python and TypeScript MCPToolProvider. See the GroundedAgent tool-UI notes for how the widget is delivered on the stream in each language.
Configuration reference
Section titled “Configuration reference”MCPServerConfig
Section titled “MCPServerConfig”| Field | Type | Required | Description |
|---|---|---|---|
| type | "stdio" \| "streamable-http" \| "sse" | Yes | Transport type |
| command | string | stdio only | Executable to launch |
| args | string[] | No | Arguments for the command |
| env | Record<string, string> | No | Environment variables for the subprocess |
| url | string | streamable-http / sse | Full URL of the server endpoint |
| headers | Record<string, string> | No | HTTP headers for the connection |
| Field | Type | Required | Description |
|---|---|---|---|
| type | str ("stdio", "streamable-http" or "sse") | Yes | Transport type |
| command | str | stdio only | Executable to launch |
| args | list[str] | No | Arguments for the command |
| env | dict[str, str] | No | Environment variables for the subprocess |
| url | str | streamable-http / sse | Full URL of the server endpoint |
| headers | dict[str, str] | No | HTTP headers for the connection |
MCPToolProvider
Section titled “MCPToolProvider”| Parameter | Type | Required | Description |
|---|---|---|---|
| servers | MCPServerConfig[] | Yes | List of MCP servers to connect to |
| callbacks | AgentToolCallbacks | No | Lifecycle hooks for tool start/end/error |
| Parameter | Type | Required | Description |
|---|---|---|---|
| servers | list[MCPServerConfig] | Yes | List of MCP servers to connect to |
| callbacks | AgentToolCallbacks | No | Lifecycle hooks for tool start/end/error |