-
Notifications
You must be signed in to change notification settings - Fork 766
[FEATURE] Support for multiple MCP servers (and loading from config file) #482
Description
Problem Statement
I would like strands to support multiple MCP servers. One of the mechanisms to provide this may be loading from a config file.
As outlined in the parent issue #198 the DX for adding MCP tools to an agent can be improved, alongside these improvements it would be great to configure multiple MCP servers and have the lifecycle of client connections be managed automatically.
Refined Requirements
Based on repository analysis and community feedback, here's the refined scope:
Current State ✅
Multiple MCP servers and lifecycle management are already supported programmatically:
from strands import Agent
from strands.tools.mcp import MCPClient
from mcp.client.stdio import stdio_client, StdioServerParameters
client1 = MCPClient(lambda: stdio_client(StdioServerParameters(command="uvx", args=["server1"])), prefix="server1")
client2 = MCPClient(lambda: stdio_client(StdioServerParameters(command="uvx", args=["server2"])), prefix="server2")
agent = Agent(tools=[client1, client2])Gap ❌
Configuration file support for MCP servers - Users must currently define MCP clients programmatically. The experimental agent_config.py does not support MCP configuration.
Proposed Solution
Extend src/strands/experimental/agent_config.py to support MCP server configuration.
Configuration Format
Use JSON format (matching existing agent_config.py pattern):
{
"name": "my_agent",
"model": "us.anthropic.claude-3-5-sonnet-20241022-v2:0",
"prompt": "You are a helpful assistant.",
"tools": ["strands_tools.file_read"],
"mcp_servers": [
{
"name": "aws_docs",
"transport": "stdio",
"command": "uvx",
"args": ["awslabs.aws-documentation-mcp-server@latest"],
"env": {},
"prefix": "aws",
"startup_timeout": 30,
"tool_filter": {
"allowed": ["search_.*", "get_docs"],
"rejected": ["dangerous_tool"]
}
},
{
"name": "local_agent",
"transport": "sse",
"url": "http://localhost:8000/sse",
"headers": {
"Authorization": "Bearer ${MCP_AUTH_TOKEN}"
},
"timeout": 300,
"prefix": "local"
},
{
"name": "remote_service",
"transport": "streamable-http",
"url": "https://api.example.com/mcp",
"headers": {
"X-API-Key": "${API_KEY}"
}
}
]
}Transport Types
| Transport | Required Fields | Optional Fields |
|---|---|---|
stdio |
command |
args, env, cwd |
sse |
url |
headers, timeout |
streamable-http |
url |
headers, timeout |
Strands-Specific Options (per server)
| Option | Type | Description |
|---|---|---|
name |
string | Server identifier (required) |
prefix |
string | Prefix for tool names to avoid collisions |
startup_timeout |
int | Timeout for server initialization (default: 30) |
tool_filter |
object | Filter which tools to load (allowed/rejected patterns) |
Features
- Environment Variable Interpolation: Support
${VAR_NAME}syntax for secrets - Per-Server Headers: Allow different auth headers per MCP server
- Tool Filtering: Per-server tool allow/reject lists (supports regex patterns)
- Graceful Failures: Opt-in behavior to continue if some servers fail (see [FEATURE] Graceful MCP server startup failures - fail open #1481)
Dependencies
- Blocking: [FEATURE] Graceful MCP server startup failures - fail open #1481 - Graceful MCP server startup failures (fail open)
- When loading multiple MCP servers from config, a single failure shouldn't break the entire agent
Use Cases
- Config-driven agents: Load agent configuration including MCP servers from a single JSON file
- Multi-server setups: Seamlessly interact with multiple MCP servers (AWS docs, local tools, remote services)
- Environment-specific configs: Different MCP servers per environment using env var interpolation
- Selective tool loading: Filter which tools to expose from each server
Implementation Approach
- Extend
AGENT_CONFIG_SCHEMAinagent_config.pyto includemcp_serversproperty - Create helper to parse MCP config and instantiate
MCPClientinstances - Support stdio transport first, then add SSE and streamable-http
- Add validation for transport-specific required fields
- Implement environment variable interpolation for sensitive values
Acceptance Criteria
- JSON configuration file can define multiple MCP servers
- All three transport types supported (stdio, sse, streamable-http)
- Per-server options work: prefix, startup_timeout, tool_filter, headers
- Environment variable interpolation works for secrets
- Integration with [FEATURE] Graceful MCP server startup failures - fail open #1481 for graceful failure handling
- Documentation with examples
- Unit and integration tests
References
- PR feat(mcp): add a feature to start MCP server from config file #623 (closed, not merged) - Previous implementation attempt
- MCP Transport Types
- Anthropic MCP Server Config Examples