Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Last active October 17, 2025 18:04
Show Gist options
  • Select an option

  • Save KyMidd/8df8b0d2e4ddb734ff2126e3e5f57576 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/8df8b0d2e4ddb734ff2126e3e5f57576 to your computer and use it in GitHub Desktop.
PrefixedMCPTool wrapper class to solve MCP tool name collisions in Strands SDK
class PrefixedMCPTool(AgentTool):
"""Wrapper that adds a prefix to an MCP tool's name."""
def __init__(self, tool, prefix):
super().__init__()
self._original_tool = tool
self._prefix = prefix
original_spec = tool.tool_spec
self._prefixed_spec = original_spec.copy()
self._prefixed_spec["name"] = f"{prefix}{original_spec['name']}"
@property
def tool_spec(self):
"""Return the modified tool spec with prefixed name"""
return self._prefixed_spec
@property
def tool_name(self):
"""Return the prefixed tool name"""
return self._prefixed_spec["name"]
@property
def tool_type(self):
"""Delegate to the original tool's type"""
return self._original_tool.tool_type
def stream(self, tool_use, *args, **kwargs):
"""Delegate to the original tool with all arguments
Important: The *args and **kwargs are crucial here!
The Strands framework passes additional arguments like
invocation_state that must be forwarded to the original tool.
"""
return self._original_tool.stream(tool_use, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment