Skip to content

limit tool name length #69

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

DougieHauser
Copy link

Describe your changes

Resolves #64

Attempts to filter tools whose operation_id + server name are too long.

Note: The codebase seems to have logic overlap between the functions server.py/_filter_tools and convert.py/def convert_openapi_to_mcp_tools - I didn't want to rock the boat too much on my first attempted contribution, but I would be happy to try my luck at refactoring (perhaps in a separate ticket).

Issue ticket number and link (if applicable)

#64

Screenshots of the feature / bugfix

Checklist before requesting a review

  • [V] Added relevant tests
  • [V] Run ruff & mypy
  • [V] All tests pass

Copy link
Contributor

@shira-ayal shira-ayal left a comment

Choose a reason for hiding this comment

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

First of all - thank you so much for contributing!
I had a few comments on the code itself, but also wanted to remark on the implementation in general.

I think hard-coding skipping on tools is not a good practice - even if some clients don't accept long tool names, it's not something defined by the spec so we shouldn't enforce it for all MCPs.
It will be better to implement by configuring the max length as an optional argument when generating the MCP based on the FastAPI app, roughly like this:

mcp = FastApiMCP(app, max_tool_name_length=60)

(with max_tool_name_length default to None).

Would be happy to see these changes implemented and then approve!

Regarding your note - it will be best to open an Issue (assigned to yourself) and then implement in a separate PR :)

Thanks again for your contribution!

@DougieHauser DougieHauser requested a review from shira-ayal April 19, 2025 22:19
Copy link

codecov bot commented Apr 19, 2025

Codecov Report

Attention: Patch coverage is 68.75000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
fastapi_mcp/server.py 78.57% 3 Missing ⚠️
fastapi_mcp/openapi/convert.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@shahar4499
Copy link
Contributor

I think syncing tadata-org:main latest changes back to your branch would resolve test coverage issues

@DougieHauser DougieHauser force-pushed the feature/limit-tool-name-length branch from 5c80302 to 2494832 Compare April 20, 2025 12:24
@DougieHauser
Copy link
Author

DougieHauser commented Apr 20, 2025

@shahar4499 - Thanks, I rebased my branch with the "upstream" repo but couldn't get the codecov bot to run again.

I then tried to push a "dummy commit" in order to trigger it, but again, no such luck.

Is there anything I'm missing?

Thanks.

@DougieHauser DougieHauser force-pushed the feature/limit-tool-name-length branch from 8571f99 to 4388fc6 Compare April 20, 2025 16:12
Copy link
Contributor

@shira-ayal shira-ayal left a comment

Choose a reason for hiding this comment

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

Nice!
Can you address the small notes I commented?
Other than that, looks fine by me

@DougieHauser DougieHauser requested a review from shira-ayal April 21, 2025 13:01
@DougieHauser DougieHauser force-pushed the feature/limit-tool-name-length branch from e02d7c2 to f4fabd6 Compare April 22, 2025 11:36
@DougieHauser DougieHauser force-pushed the feature/limit-tool-name-length branch from f4fabd6 to 985a9df Compare April 23, 2025 15:18
@DougieHauser
Copy link
Author

Hey @shira-ayal, just pinging to see if there are any more expected changes.
Thanks.

@shira-ayal
Copy link
Contributor

Hi @DougieHauser !
Looks great, waiting for @shahar4499 to take a final look before we merge :)

@shira-ayal shira-ayal self-requested a review April 24, 2025 15:11
@DougieHauser
Copy link
Author

Hi @DougieHauser !
Looks great, waiting for @shahar4499 to take a final look before we merge :)

Hey @shahar4499, just a quick ping. Thanks.

@jshcrm
Copy link

jshcrm commented May 18, 2025

Just want to chime in here as a user that I hit the operation_id max length issue when using claude desktop, and it was not obvious that I needed to add an operation_id to my endpoints with the proper length as a workaround. I did eventually find that referenced in the docs. This PR looks like it will simply exclude endpoints that violate the operation_id length, which all of mine did when I let operation ids be auto generated. I'd love to see some kind of console logging or warning when an endpoint is going to be excluded, or maybe an option to automatically reduce the operation_id to a length that fits instead of excluding

@jshcrm
Copy link

jshcrm commented May 18, 2025

Unless I'm missing something this PR will just remove the tools and not offer any feedback that that happened or why, which would then lead to me digging through code and debugging why fastapi_mcp isn't doing the one thing it's supposed to do, create tools from my endpoints

@DougieHauser
Copy link
Author

That's a good point, @jshcrm ..
Personally, it's my 1st PR on this repo, and I tried to stay consistent with what seemed like the convention that was already in place for other filters such as _include_operations, _exclude_operations, _include_tags and _exclude_tags

TBH, I could just go ahead and add logging for all of them..
Just want to make sure this repo is still maintained, because I believe it's been pretty stale for a month now.

@shahar4499 @shira-ayal

@DougieHauser
Copy link
Author

On second though, @jshcrm ..

The max limit functionality does seem less "explicit" than the others..
I've added a warning for it alone, at this point. Thanks.

@jshcrm
Copy link

jshcrm commented May 20, 2025

@DougieHauser Awesome I think that warning will go a long way! Thanks for adding that. I'm also hoping this repo is still being maintained - there was a release a few days ago but I'd really love to see the switch from sse to streamable-http

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Combined Server and tool name should not exceed 60 characters
4 participants