This example demonstrates how to use MCP Compose with Streamable HTTP transport. This is the modern, recommended HTTP transport for MCP that replaces the deprecated SSE transport.
This example shows:
- Two MCP Servers: Calculator and Echo servers (
mcp1.py,mcp2.py) - Streamable HTTP Transport: Modern HTTP-based MCP communication
- Unified Access: Single interface to all tools from multiple servers
┌─────────────────────────────────────────────────────────────┐
│ Pydantic AI Agent │
│ │
│ ┌────────────────────────────────────────────────────────┐ │
│ │ MCPServerStreamableHTTP │ │
│ │ (connects to http://localhost:8888/mcp) │ │
│ └──────────────────────┬─────────────────────────────────┘ │
└─────────────────────────┼────────────────────────────────────┘
│ HTTP (Streamable HTTP transport)
▼
┌─────────────────────────────────────────────────────────────┐
│ MCP Compose Server │
│ (http://localhost:8888/mcp) │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Calculator │ │ Echo │ │
│ │ (mcp1.py) │ │ (mcp2.py) │ │
│ │ │ │ │ │
│ │ • add │ │ • ping │ │
│ │ • subtract │ │ • echo │ │
│ │ • multiply │ │ • reverse │ │
│ │ • divide │ │ • uppercase │ │
│ │ │ │ • lowercase │ │
│ │ │ │ • count_words │ │
│ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────┘
- Streamable HTTP Transport: Modern, recommended MCP transport (SSE is deprecated)
- Server Mode: MCP Compose runs as a persistent server
- Multiple Clients: Multiple agents can connect simultaneously
- REST-like: Standard HTTP semantics for easier integration
- Unified Interface: All tools accessible through a single endpoint
make installThis will install:
mcp-compose(the orchestrator)fastmcp(for the demo MCP servers)
make startThe composer will:
- Read configuration from
mcp_compose.toml - Start both Calculator and Echo MCP servers
- Expose a unified Streamable HTTP endpoint at
http://localhost:8888/mcp
make install-agentmake agentOnce the agent is running:
- "What is 15 plus 27?"
- "Multiply 8 by 9"
- "Reverse the text 'hello world'"
- "Convert 'Hello World' to uppercase"
- "Count the words in 'The quick brown fox jumps'"
Press Ctrl+C in the terminal where the composer is running.
With Streamable HTTP transport, the server runs independently:
- Server starts:
mcp-compose serve --transport streamable-http - Endpoint exposed: Server listens at
http://localhost:8888/mcp - Clients connect: Using
MCPServerStreamableHTTPfrom pydantic-ai - Communication: Standard HTTP requests with streaming responses
This is different from STDIO transport where the client spawns the server.
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStreamableHTTP
# Create MCP server connection with Streamable HTTP transport
mcp_server = MCPServerStreamableHTTP(
url="http://localhost:8888/mcp",
timeout=300.0,
)
# Create agent with MCP tools
agent = Agent(
model="anthropic:claude-sonnet-4-0",
toolsets=[mcp_server],
)
# Use async context manager
async with agent:
result = await agent.run("What is 5 + 3?")| Feature | Streamable HTTP | SSE (deprecated) |
|---|---|---|
| Endpoint | /mcp |
/sse |
| Protocol | Modern HTTP streaming | Server-Sent Events |
| Status | Recommended | Deprecated |
| Bidirectional | Yes | Limited |
| File | Description |
|---|---|
mcp_compose.toml |
Configuration for the MCP servers |
mcp1.py |
Calculator MCP server (add, subtract, multiply, divide) |
mcp2.py |
Echo MCP server (ping, echo, reverse, uppercase, etc.) |
agent.py |
Pydantic AI agent using Streamable HTTP transport |
Makefile |
Convenience commands |
The mcp_compose.toml defines the managed MCP servers:
[composer]
name = "demo-composer"
conflict_resolution = "prefix" # Tools become calculator:add, echo:ping, etc.
log_level = "INFO"
[[servers.proxied.stdio]]
name = "calculator"
command = ["python", "mcp1.py"]
restart_policy = "never"
[[servers.proxied.stdio]]
name = "echo"
command = ["python", "mcp2.py"]
restart_policy = "never"| Command | Description |
|---|---|
make help |
Show all available commands |
make install |
Install mcp-compose and FastMCP |
make install-agent |
Install pydantic-ai with MCP support |
make start |
Start the MCP Compose server |
make agent |
Run the AI agent (requires composer running) |
make stop |
Stop the MCP Compose server |
make clean |
Clean up temporary files |
Use Streamable HTTP when:
- ✅ Multiple clients need to connect
- ✅ Server should persist beyond client sessions
- ✅ Deploying as a standalone service
- ✅ Need standard HTTP for load balancers, proxies
- ✅ Using modern MCP features
Use STDIO when:
- ❌ Single client, local usage
- ❌ Client should manage server lifecycle
- ❌ Simpler deployment without network
- STDIO Example - STDIO transport (subprocess)
- SSE Example - SSE transport (deprecated)
- User Guide - Complete feature documentation
- Architecture - System design
Found an issue or want to improve this example? Please open an issue or PR!
BSD 3-Clause License - see LICENSE
Made with ❤️ by Datalayer