-
Notifications
You must be signed in to change notification settings - Fork 423
Description
Checks
- I have updated to the lastest minor and patch version of Strands
- I have checked the documentation and this is not expected behavior
- I have searched ./issues and there are no duplicates of my issue
Strands Version
1.4.0
Python Version
3.13
Operating System
macOS
Installation Method
pip
Steps to Reproduce
When creating multiple mcp clients that offer a tool with the same name, it can be multiple instances of the same mcp server package, or 2 mcp server that have generic names like execute
or run
Strands should offer a way to namespace with prefix in front, this is what projects like agentgateway do with mcp multiplexing
Here is an example code snippet using two instances of the EKS MCP Server
mcp_client = MCPClient(lambda: stdio_client(
StdioServerParameters(
command="uvx",
args=["awslabs.eks-mcp-server@latest","--allow-write","--allow-sensitive-data-access"],
env={
"AWS_REGION": "us-west-2",
"AWS_PROFILE": "cross-account-1"
}
)
))
mcp_client_2 = MCPClient(lambda: stdio_client(
StdioServerParameters(
command="uvx",
args=["awslabs.eks-mcp-server@latest","--allow-write","--allow-sensitive-data-access"],
env={
"AWS_REGION": "us-west-2",
"AWS_PROFILE": "carrlos-Admin"
}
)
))
Then using the mcp clients in Strands
mcp_tools = mcp_client.list_tools_sync()
mcp_tools_2 = mcp_client_2.list_tools_sync()
# Namespace the tools to avoid conflicts
namespaced_tools_1 = [NamespacedMCPTool(tool, "cross") for tool in mcp_tools]
namespaced_tools_2 = [NamespacedMCPTool(tool, "carrlos") for tool in mcp_tools_2]
all_tools = [get_todays_date, use_aws, environment, get_profile_from_cluster] + namespaced_tools_1 + namespaced_tools_2
agent = Agent(
name="MyAgent",
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
system_prompt="""
You are a Platform Engineer managing EKS clusters located in different AWS accounts.
IMPORTANT: When working with EKS clusters, you MUST:
1. First call get_profile_from_cluster(cluster_name) to determine which AWS profile/namespace to use
2. Use the returned profile information to select the correct namespaced tools:
- If profile is "cross-account-1", use tools prefixed with "cross__"
- If profile is "carrlos-Admin", use tools prefixed with "carrlos__"
For example:
- For cluster "agentic-ai-on-eks-workshop" → use "cross__" tools
- For cluster "cloud-provider-1" → use "carrlos__" tools
Always check the cluster-to-profile mapping before executing any Kubernetes operations.
""",
tools=all_tools
)
I had to override AgentTool to inject the namespace
class NamespacedMCPTool(MCPAgentTool):
"""Wrapper for MCPAgentTool that allows custom naming"""
def __init__(self, mcp_tool: MCPAgentTool, namespace: str):
# Properly initialize the parent class
super().__init__(mcp_tool.mcp_tool, mcp_tool.mcp_client)
self.namespace = namespace
self._custom_name = f"{namespace}__{mcp_tool.tool_name}"
self._original_name = mcp_tool.tool_name
@property
def tool_name(self) -> str:
return self._custom_name
@property
def tool_spec(self) -> ToolSpec:
spec = super().tool_spec
spec["name"] = self._custom_name
return spec
async def stream(self, tool_use: ToolUse, invocation_state: dict[str, Any], **kwargs: Any) -> ToolGenerator:
"""Stream the MCP tool using the original tool name for the MCP server call."""
result = await self.mcp_client.call_tool_async(
tool_use_id=tool_use["toolUseId"],
name=self._original_name, # Use original name for MCP server
arguments=tool_use["input"],
)
yield result
Expected Behavior
For the mcp classes like STDIO or StreammeableHTTP to offer an optional argument name
and used as prefix under the hood
then I could something like
StdioServerParameters(
name="cross"
command="uvx",
args=["awslabs.eks-mcp-server@latest","--allow-write","--allow-sensitive-data-access"],
env={
"AWS_REGION": "us-west-2",
"AWS_PROFILE": "cross-account-1"
}
)
Actual Behavior
The tools get override and a single set of tools offer to the Agent
Additional Context
Maybe related to issue #715
Possible Solution
No response
Related Issues
No response