[FEATURE] Support for multiple MCP servers (and loading from config file)
Overview
Add support for loading MCP server configurations from a JSON config file, allowing users to define multiple MCP servers declaratively instead of programmatically. This extends the existing experimental agent_config.py to support an mcp_servers field that creates and manages MCPClient instances automatically.
Note: Multiple MCP servers and automatic lifecycle management already work programmatically (see tests_integ/mcp/test_mcp_tool_provider.py::test_mcp_client_multiple_servers). This feature request is specifically about configuration file support.
Implementation Requirements
1. Extend Agent Config Schema (src/strands/experimental/agent_config.py)
Add mcp_servers to the existing AGENT_CONFIG_SCHEMA JSON schema. The configuration format should be compatible with the Claude Desktop / Cursor / VS Code mcpServers convention where possible.
Target config format:
{
"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": {
"aws_docs": {
"command": "uvx",
"args": ["awslabs.aws-documentation-mcp-server@latest"],
"env": { "AWS_PROFILE": "default" },
"prefix": "aws",
"startup_timeout": 30,
"tool_filters": {
"allowed": ["search_.*"],
"rejected": ["dangerous_tool"]
}
},
"remote_service": {
"transport": "sse",
"url": "http://localhost:8000/sse",
"headers": {
"Authorization": "Bearer token123"
},
"prefix": "remote"
},
"http_service": {
"transport": "streamable-http",
"url": "http://localhost:8000/mcp",
"headers": {},
"prefix": "http"
}
}
}
2. Create MCP Config Module (src/strands/tools/mcp/mcp_config.py)
Create a new module that handles parsing MCP server configuration and creating MCPClient instances.
Key components:
- Transport type detection: Infer transport from config (default to
stdioifcommandis present, otherwise infer fromurlor explicittransportfield) - Transport types to support:
stdio— usesmcp.client.stdio.stdio_clientwithStdioServerParameterssse— usesmcp.client.sse.sse_clientstreamable-http— usesmcp.client.streamable_http.streamablehttp_client
- Config-to-MCPClient mapping: Convert each server config entry into an
MCPClientinstance with the appropriate transport callable
Per-server configuration options:
| Field | Type | Required | Description |
|---|---|---|---|
command |
string | For stdio | Command to run the MCP server |
args |
string[] | No | Arguments for the command |
env |
object | No | Environment variables for the subprocess |
cwd |
string | No | Working directory for stdio subprocess |
transport |
string | No | Transport type: "stdio", "sse", "streamable-http" (auto-detected if omitted) |
url |
string | For sse/http | URL of the remote MCP server |
headers |
object | No | HTTP headers for sse/http transports |
prefix |
string | No | Prefix for tool names to avoid collisions |
startup_timeout |
int | No | Timeout for server initialization (default: 30) |
tool_filters |
object | No | Tool filter config with allowed and rejected arrays of string/regex patterns |
3. Integrate with config_to_agent
Update config_to_agent() in agent_config.py to:
- Parse the
mcp_serversfield from config - Create
MCPClientinstances using the new config module - Append
MCPClientinstances to the tools list passed toAgent() - Let existing
ToolProviderhandling inToolRegistry.process_tools()manage lifecycle
4. Also Provide Standalone Config Loading
In addition to config_to_agent integration, provide a standalone function to load MCP clients from config for users who want to use them independently:
from strands.tools.mcp import MCPClient
from strands.tools.mcp.mcp_config import load_mcp_clients_from_config
# Load from file
clients = load_mcp_clients_from_config("mcp_config.json")
# Or from dict
clients = load_mcp_clients_from_config({
"aws_docs": {
"command": "uvx",
"args": ["awslabs.aws-documentation-mcp-server@latest"]
}
})
# Use with agent
agent = Agent(tools=list(clients.values()))
5. Testing
Unit tests (tests/strands/tools/mcp/test_mcp_config.py):
- Config parsing and validation for each transport type
- Transport type auto-detection logic
- Tool filter parsing (string literals → exact match, regex patterns)
- Error handling for invalid configs
- MCPClient creation with correct parameters
Unit tests (tests/strands/experimental/test_agent_config.py):
- Extend existing tests for
config_to_agentwithmcp_serversfield
Integration tests (tests_integ/mcp/test_mcp_config.py):
- Load MCP servers from config file using existing
echo_server.py - Verify tools are loaded and callable via agent
- Multiple server config loading
Files to Create/Modify
| File | Action | Description |
|---|---|---|
src/strands/tools/mcp/mcp_config.py |
Create | MCP config parsing and MCPClient factory |
src/strands/tools/mcp/__init__.py |
Modify | Export new config module |
src/strands/experimental/agent_config.py |
Modify | Add mcp_servers to schema and processing |
tests/strands/tools/mcp/test_mcp_config.py |
Create | Unit tests for config module |
tests/strands/experimental/test_agent_config.py |
Modify | Add tests for mcp_servers in agent config |
tests_integ/mcp/test_mcp_config.py |
Create | Integration tests |
AGENTS.md |
Modify | Update directory structure |
Acceptance Criteria
- [ ] Users can define multiple MCP servers in a JSON config file
- [ ] Config supports stdio, SSE, and streamable-http transport types
- [ ] Transport type is auto-detected when not explicitly specified
- [ ]
config_to_agent()correctly creates agents with MCP tools from config - [ ] Standalone
load_mcp_clients_from_config()function works independently - [ ] Per-server options work:
prefix,startup_timeout,tool_filters,env,headers - [ ] Tool filters support string literals and regex patterns in config
- [ ] Invalid configurations produce clear error messages with JSON schema validation
- [ ] Unit tests cover all config parsing paths and edge cases
- [ ] Integration tests verify end-to-end MCP tool usage from config
- [ ] Existing MCP programmatic usage (
Agent(tools=[mcp_client])) is unaffected
Assumptions
- JSON only — No YAML/TOML support needed for now (per maintainer decision)
- Skip graceful failures — #1481 (fail-open strategy) is deferred; a single server failure will fail agent init as-is
- No environment variable interpolation — Config values are taken as-is (env passthrough via
envfield for stdio only) - Experimental — This feature lives under
experimental/agent_config.pyand is subject to API changes - No workflow changes — No GitHub Actions modifications required
Prior Art & References
- Closed PR #623: Prior implementation attempt by @JackYPCOnline with
mcp_from_config.py— can reference for patterns - Docs PR #718: Design doc for broader MCP integration by @mkmeral — config loading is identified as P1 gap
- Issue #1481: Graceful MCP server startup failures — deferred, can be layered on later
- Claude Desktop config format: Industry-standard
mcpServersJSON format - Existing patterns:
agent_config.pyfor JSON schema validation,MCPClientfor transport handling
Notes for Future Improvement
- Consider adding YAML support in a follow-up
- Consider environment variable interpolation (e.g.,
${ENV_VAR}) for sensitive values - Consider
fail_openoption when #1481 is implemented - The
AGENTS.mddirectory structure should be updated to reflect the newmcp_config.pyfile README.mdMCP section could be updated with config file example
/strands
I've analyzed the current implementation and found that multiple MCP servers and lifecycle management are already supported! The gap is specifically around configuration file support. Multiple MCP Server Support: Automatic Lifecycle Management: Configuration file support for MCP servers - Users currently must define MCP clients programmatically. There is an experimental Q1.1: What configuration file format should be used? Q1.2: Where should MCP configuration be located? Q2.1: Should MCP configuration be part of the agent config, or separate? Option A - Integrated Agent Config: Option B - Separate MCP Config: Which approach is preferred? Q3.1: Which MCP transport types should be supported in configuration? Q3.2: For each transport type, what parameters need to be configurable? Example for stdio: Q4.1: Which MCPClient options should be configurable? Q4.2: How should tool filters be specified in config? Example: Q5.1: Should the configuration support environment variable interpolation? Example: Q5.2: Should paths in configuration support relative paths, and if so, relative to what? Q6.1: Should this implementation: Q6.2: Are there specific MCP servers you'd like to test with? Q6.3: Should example configurations be provided in documentation? Q7.1: How should configuration validation errors be reported? Q7.2: How should MCP server startup failures be handled? Based on the repository structure, I recommend: This keeps the implementation focused and aligned with existing patterns.Repository Analysis & Clarifying Questions
Repository Analysis
Current Capabilities ✅
# This already works!
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])
ToolProvider interfacetests_integ/mcp/test_mcp_tool_provider.py::test_mcp_client_multiple_serversWhat's Missing ❌
agent_config.py that supports loading agents from JSON, but it does not support MCP configuration.
Clarifying Questions
1. Configuration File Format & Location
agent_config.py)?
2. Configuration Schema
{
"name": "my_agent",
"model": "claude-3-5-sonnet-20241022",
"mcp_servers": [
{
"name": "aws_docs",
"transport": {
"type": "stdio",
"command": "uvx",
"args": ["awslabs.aws-documentation-mcp-server@latest"]
},
"prefix": "aws",
"startup_timeout": 30
}
]
}
{
"mcp_servers": [
{
"name": "aws_docs",
"transport": { "type": "stdio", "command": "uvx", "args": [...] },
"prefix": "aws"
}
]
}
3. Transport Types
stdio (command-line based servers){
"transport": {
"type": "stdio",
"command": "python",
"args": ["server.py"],
"env": {...} // Should environment variables be configurable?
}
}
4. MCP Client Configuration Options
prefix (for tool name prefixing)?startup_timeout?tool_filters (allowed/rejected patterns)?elicitation_callback (probably not, requires code)?{
"tool_filters": {
"allowed": ["echo", "list_.*"], // String literals or regex patterns
"rejected": ["dangerous_tool"]
}
}
5. Environment Variables & Dynamic Configuration
{
"transport": {
"type": "stdio",
"command": "${MCP_SERVER_COMMAND}",
"args": ["${MCP_SERVER_ARGS}"]
}
}
6. Scope & Testing
agent_config.py?7. Error Handling
Recommendation
src/strands/experimental/agent_config.py to support MCP configuration
https://github.com/strands-agents/sdk-python/pull/623
Refinement notes:
- We need to agree on a format (or maybe support multiple? :) )
- We need to agree Strands specific options
- We should probably fix this beforehand https://github.com/strands-agents/sdk-python/issues/1481
Chiming in as a consumer, I think would be excellent if it could support multiple mcp servers, users could provide a list of mcp server urls to connect via http.
Something like:
{
"model": "us.anthropic.claude-3-5-sonnet-20241022-v2:0",
"prompt": "You are a coding assistant. Help users write, debug, and improve their code. You have access to file operations and can execute shell commands when needed.",
"tools": ["strands_tools.file_read", "strands_tools.editor", "strands_tools.shell"],
"mcp_servers": [
{ # dict to keep this extensible
"url": ""
}
]
}
However, these items immediately come to mind, would need to brainstorm:
- How would a user pass in different headers to different MCP servers?
- What if a user wants to filter x tools from x server so the agent only knows about x tools at runtime, even when connected to multiple servers.
For this second bit, we are currently doing this manually by loading all of the tools from servers and then filtering only the ones that have been configured for the agent in code.
I think the second bit may be a different feature altogether, unless something like this could be done:
"mcp_servers": [
{
"url": "my-store-server-a.com/mcp",
"tools": [
"load_invoices",
"build_order"
]
}
]
/strands review the latest comments and refine this issue
Issue Refinement Summary
Based on the latest comments and repository analysis, here's the refined scope for this feature:
Current State ✅
Multiple MCP servers and lifecycle management already work programmatically. The gap is specifically configuration file support.
Key Decisions Needed
Based on @mkmeral's notes and @MannyDiera's feedback:
| Decision | Recommendation | Rationale |
|---|---|---|
| Format | JSON | Matches existing agent_config.py pattern |
| Location | Extend experimental/agent_config.py |
Unified configuration approach |
| Transports | stdio, sse, streamable-http | Cover all common use cases |
Proposed Configuration Schema
{
"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"],
"prefix": "aws",
"startup_timeout": 30,
"tool_filter": {
"allowed": ["search_.*"],
"rejected": ["dangerous_tool"]
}
},
{
"name": "remote_service",
"transport": "sse",
"url": "http://localhost:8000/sse",
"headers": {
"Authorization": "Bearer ${MCP_AUTH_TOKEN}"
}
}
]
}
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 |
tool_filter |
object | Filter tools with allowed/rejected patterns |
headers |
object | Per-server HTTP headers (for SSE/HTTP transports) |
Dependencies
⚠️ Blocking: #1481 - Graceful MCP server startup failures
- When loading multiple servers from config, a single failure shouldn't break the entire agent
- Recommend implementing #1481 first or in conjunction
Questions for Maintainers
- Should we support YAML in addition to JSON?
- Should
mcp_serversbe in agent config or separate file (or both)? - Any additional Strands-specific options needed beyond what MCPClient already supports?
Next Steps
- Get alignment on the schema above
- Implement #1481 (graceful failures)
- Extend
agent_config.pywith MCP support - Add documentation and examples
@Unshure fyi https://github.com/strands-agents/docs/pull/718
/strands
- Just json for now
- it can be in agent config
- For now no
We can also skip 1481 for now
The issue has been refined and updated with a comprehensive implementation description. Here's what was accomplished: ✅ This issue is ready for implementation. It is well-scoped for a single developer and a single PR. The implementation path is clear, building on existing patterns in Task Refinement Complete
Summary
Analysis Results
Decisions Made (from maintainer input)
Decision
Answer
Config format
JSON only for now
Config location
Integrated into existing agent config
Additional Strands-specific options
None beyond MCPClient defaults
Graceful failures (#1481)
Deferred / skipped for now
Implementation Scope
src/strands/tools/mcp/mcp_config.py — MCP config parser & MCPClient factorysrc/strands/experimental/agent_config.py — Add mcp_servers to schemasrc/strands/tools/mcp/__init__.py — Export new moduleReadiness Assessment
agent_config.py and MCPClient.
/strands implement
Unable to create pull request via API. You can create it manually by clicking here.
Loading from JSON config matters most when teams want their MCP server set per-environment without code change. The shape we landed on internally: env-overlays in the JSON ({"mcp_servers": {"_base": {...}, "prod": {...overrides...}}}) so dev/stage/prod swap server lists declaratively.
Two gotchas worth designing in: lifecycle ordering when one MCP server depends on another being up first, and credential resolution (env vars vs secrets manager) so the JSON itself is committable without leaking secrets.
If the implementation lands without these the config file pattern still works, just with a thicker user-side wrapper.
Closing as completed: multiple MCP servers with config-file loading shipped in both SDKs as load_servers — Python in #3053 and TypeScript in #2947, both supporting the mcpServers JSON format with env-var interpolation, disabled, and per-server error tolerance. Docs: https://strandsagents.com/latest/documentation/docs/user-guide/concepts/tools/mcp-tools/