SOP-006: Configuring MCP Transports
FreshSource: MCP Advanced Topics
Document Control
| Field | Value |
|---|---|
| SOP ID | SOP-006 |
| Version | 1.0 |
| Status | Active |
| Last Updated | 2024-12 |
Overview
Configure MCP transports for local (STDIO) and remote (HTTP) deployments.
Transport Types
| Transport | Best For | Pros | Cons |
|---|---|---|---|
| STDIO | Local development, Desktop apps, CLI tools | Simple, No network, Fast | Same machine only |
| HTTP | Production, Multi-user, Remote access | Scalable, Stateless option, Cloud-ready | Network latency, More complex |
STDIO Transport Setup
python
# server_stdio.py
from mcp.server import Server
from mcp.server.stdio import stdio_server
server = Server("stdio-server")
# ... define tools ...
async def main():
async with stdio_server() as (read, write):
await server.run(read, write)
if __name__ == "__main__":
import asyncio
asyncio.run(main())Client Configuration:
json
{
"mcpServers": {
"my-server": {
"command": "python",
"args": ["server_stdio.py"]
}
}
}HTTP Transport Setup
python
# server_http.py
from mcp.server import Server
from mcp.server.sse import SseServerTransport
from starlette.applications import Starlette
from starlette.routing import Route
server = Server("http-server")
# ... define tools ...
# Create SSE transport
sse = SseServerTransport("/messages")
async def handle_sse(request):
async with sse.connect_sse(
request.scope,
request.receive,
request._send
) as streams:
await server.run(
streams[0],
streams[1],
server.create_initialization_options()
)
app = Starlette(
routes=[
Route("/sse", handle_sse),
Route("/messages", sse.handle_post_message, methods=["POST"])
]
)
# Run with: uvicorn server_http:appDecision Flow: Which Transport?
HTTP Transport Modes
| Mode | Features | Good For |
|---|---|---|
| Stateful | Maintains session between requests, Supports all MCP features | Interactive apps, Long-running sessions |
| Stateless | No session state, Limited features (no sampling, notifications) | Serverless, High-scale, Simple tools |
Verification Checklist
- [ ] Transport type selected for use case
- [ ] Server starts without errors
- [ ] Client connects successfully
- [ ] Message exchange works
- [ ] Proper cleanup on disconnect
Troubleshooting
| Issue | Solution |
|---|---|
| Connection timeout | Check firewall/ports |
| Protocol error | Verify JSON-RPC format |
| State lost | Use stateful mode if needed |
| Memory leak | Ensure proper cleanup |