Skip to content

fix(mcp-server): assign original_name with type ignore and wrap long docstring #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/agents/mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,14 @@ async def list_tools(
# Reset the cache dirty to False
self._cache_dirty = False
# Fetch the tools from the server
self._tools_list = (await self.session.list_tools()).tools
tools = self._tools_list
tools = (await self.session.list_tools()).tools
# Add server name prefix to each tool's name to ensure global uniqueness
for tool in tools:
# Store original name for actual tool calls (cast to Any so mypy won't complain)
tool.original_name = tool.name # type: ignore[attr-defined]
# Prefix tool name with server name using underscore separator
tool.name = f"{self.name}_{tool.name}"
self._tools_list = tools

# Filter tools based on tool_filter
filtered_tools = tools
Expand All @@ -287,11 +293,23 @@ async def list_tools(
return filtered_tools

async def call_tool(self, tool_name: str, arguments: dict[str, Any] | None) -> CallToolResult:
"""Invoke a tool on the server."""
"""Invoke a tool on the server.

Args:
tool_name: The name of the tool to call. Can be either the prefixed name
(server_name_tool_name) or the original tool name.
arguments: The arguments to pass to the tool.
"""
if not self.session:
raise UserError("Server not initialized. Make sure you call `connect()` first.")

return await self.session.call_tool(tool_name, arguments)
# If the tool name is prefixed with server name, strip it
if "_" in tool_name and tool_name.startswith(f"{self.name}_"):
original_tool_name = tool_name.split("_", 1)[1]
else:
original_tool_name = tool_name

return await self.session.call_tool(original_tool_name, arguments)

async def list_prompts(
self,
Expand Down