Skip to content

Support multiple MCP servers in MCPEnvironment#476

Merged
kylemontgomery1 merged 1 commit intorllm-org:mainfrom
taivu1998:tdv/issue-321-multi-mcp
Apr 4, 2026
Merged

Support multiple MCP servers in MCPEnvironment#476
kylemontgomery1 merged 1 commit intorllm-org:mainfrom
taivu1998:tdv/issue-321-multi-mcp

Conversation

@taivu1998
Copy link
Copy Markdown
Contributor

Summary

This PR adds multi-server MCP support to MCPEnvironment so a single environment can route tool calls across multiple named MCP servers.

Fixes #321.

What changed

  • Added mcp_servers support to MCPEnvironment for configuring multiple named MCP servers.
  • Added tool_name_to_server_name routing for disambiguating tool names when more than one server exposes the same public tool.
  • Kept MCPConnectionManager single-server and moved the multi-server logic into MCPEnvironment as a lightweight registry/router layer.
  • Preserved the legacy single-server mcp_server_command / mcp_server_args / mcp_server_env API for backward compatibility.
  • Updated tool-call execution to handle malformed tool calls more gracefully and to support both dict and JSON-string arguments.
  • Preserved original tool-call ordering in tool_outputs even when calls are routed to different MCP servers.
  • Added cleanup/rollback behavior so failed startup or routing validation does not leave partially initialized global MCP managers behind.
  • Added MCP example documentation showing the new multi-server API.

Design notes

  • Duplicate public tool names now fail fast unless explicitly mapped with tool_name_to_server_name.
  • Duplicate detection uses the effective public tool names exposed today, including underscore aliases for tools whose MCP names contain hyphens.
  • Single-server behavior remains permissive: if exactly one server is configured, unresolved tool names still fall back to that server so existing behavior is preserved.
  • Partial per-server failures are isolated so successful tool outputs from other servers are still returned.

Testing

  • /Users/vuductai/Documents/Projects/rllm/.venv/bin/python -m ruff check rllm/environments/tools/mcp_env.py tests/envs/test_mcp_env.py
  • /Users/vuductai/Documents/Projects/rllm/.venv/bin/python -m pytest tests/envs/test_mcp_env.py tests/agents/test_tool_agent.py tests/envs/test_tool_env.py -q

Coverage added

  • Multi-server initialization
  • Explicit routing for ambiguous tool names
  • Duplicate-name validation
  • Cross-server tool execution routing
  • Partial server failure handling
  • Synthetic ID stability for missing tool-call IDs
  • Interleaved output ordering across servers
  • Startup and routing-validation rollback behavior
  • from_dict support and non-mutation of input args

@kylemontgomery1 kylemontgomery1 merged commit 4f49efc into rllm-org:main Apr 4, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multiple mcp servers for MCPEnvironment

2 participants