Skip to content

Tools with the same name in different modules override each other #197

@guillaumebriday

Description

@guillaumebriday

Describe the bug

Tools sharing the same name across different modules aren’t working, likely because of this line: https://github.com/modelcontextprotocol/ruby-sdk/blob/main/lib/mcp/server.rb#L54

To Reproduce
If your tool structure looks like this, for example

app/tools
├── application_tool.rb
├── clients
│   ├── create_tool.rb
│   ├── destroy_tool.rb
│   ├── index_tool.rb
│   ├── show_tool.rb
│   └── update_tool.rb
├── projects
│   ├── create_tool.rb
│   ├── destroy_tool.rb
│   ├── index_tool.rb
│   ├── show_tool.rb
│   └── update_tool.rb

Only the most recently registered tool remains in the tools list:

[Clients::UpdateTool, Projects::UpdateTool].to_h { |t| [t.name_value, t] }
# => {"update_tool" => Projects::UpdateTool}

This happens because name_value returns update_tool for both classes.

Expected behavior
We should probably use a more robust key here to properly handle this case. I could open a PR if needed and adapt the tests, but let me know first what you think about it!

Thanks for this gem! 🙌

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions