Skip to content

feat - add unique check for tool names on run #1254

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 1 commit into from

Conversation

gidonkessler
Copy link

@gidonkessler gidonkessler commented Mar 27, 2025

I've never contributed to open source before but saw this todo thought I'd give it a try :)

Hopefully it looks close to what you guys were imagining and would appreciate some guidance on the test 🙏

@Wh1isper
Copy link
Contributor

That's a good idea, and it occurs to me that we may need to add a optional prefix for mcp server. This allows users to not be blocked by this feature from using two mcp servers those have the same name tool.

see: #1266

If #1266 is merged, I'd like to hint the users that they can set a prefix.

Further, we can automatically help the user to set this prefix and tell: if user doesn't like it or if something goes wrong (some llm's have requirements for tool name, here we might only use some short random letters + numbers), users can configure the prefix manually.

Copy link
Contributor

@DouweM DouweM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gidonkessler Sorry for the delay here! Can you please rebase on main and have a look at my comments?

# TODO(Marcelo): We should check if the tool names are unique. If not, we should raise an error.
tool_defs: list[ToolDefinition] = await server.list_tools()

tool_name_counts: Counter[str] = Counter(tool_def.name for tool_def in tool_defs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also verify that the MCP server's tools don't clash with tools from other servers, as well as the user-defined tools? We can look at all of the function_tool_defs.

I suggest looking at the Agent._register_tool method that does this when adding a new user-defined tool.

Instead of using a Counter, I think we can turn function_tool_defs into a dict, and when iterating over the new tools, check if a key for that name already exists.

]
)

class MockMCPServer(MCPServer):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this and likely do away with so much mocking of implementation details that may change in the future if we instead test that an MCP tool name doesn't conflict with a user-defined tool, or another MCP server's tool. We can likely use the FastMCP server we define in tests/mcp_server.py and already use from (the latest version of this) test_mcp.py

@DouweM DouweM self-assigned this Apr 30, 2025
@DouweM DouweM marked this pull request as draft April 30, 2025 21:31
@DouweM
Copy link
Contributor

DouweM commented Apr 30, 2025

@Wh1isper plans to implement this check with an error message suggesting to set a tool name prefix in #1266.

@DouweM DouweM closed this Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants