Skip to content

Add ToolAnnotations support in FastMCP and lowlevel servers #482

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

Merged
merged 8 commits into from
Apr 30, 2025

Conversation

bhosmer-ant
Copy link
Contributor

Summary

  • Add proper support for ToolAnnotations in FastMCP and lowlevel servers
  • Update test_tool_annotations_in_fastmcp to access ToolAnnotations fields as properties rather than dictionary keys
  • Add test_lowlevel_server_tool_annotations to verify Tool annotations functionality in lowlevel server
  • Update server.py to convert dictionary annotations to ToolAnnotations objects

Test plan

  • Run all tests with uv run pytest to verify changes work correctly
  • Verify tool annotations are properly accessed and validated in both server implementations

🤖 Generated with Claude Code

Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

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

Just to check why we need dictionary and can be have annotations typed for users?

@ihrpr ihrpr added this to the 2025-03-26 spec release milestone Apr 29, 2025
@bhosmer-ant
Copy link
Contributor Author

@ihrpr ok requested changes should be in (really good change, thanks a bunch) and up to date w/main.

Only change to config is the warning suppression - still a mystery why everybody isn't seeing the test failures with starlette 0.27 and no suppression, but I'm happy to take it out of this PR if you think that's cleaner.

@bhosmer-ant bhosmer-ant requested a review from ihrpr April 29, 2025 21:27
@ihrpr
Copy link
Contributor

ihrpr commented Apr 30, 2025

@ihrpr ok requested changes should be in (really good change, thanks a bunch) and up to date w/main.

Only change to config is the warning suppression - still a mystery why everybody isn't seeing the test failures with starlette 0.27 and no suppression, but I'm happy to take it out of this PR if you think that's cleaner.

yes please, let's take it out before merging. Separately let's look why there is that warning. I checked out this PR and run all tests without the warning suppression and all works fine (CI should also give us a signal)

ihrpr
ihrpr previously approved these changes Apr 30, 2025
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

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

Let's remove warning suppression before merging

) -> Tool:
"""Create a Tool from a function."""
from mcp.server.fastmcp import Context
from mcp.server.fastmcp.server import Context
Copy link
Contributor

Choose a reason for hiding this comment

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

what do we need to change this? I see the problem, but why do we even need it here?
on top of the file there is


if TYPE_CHECKING:
    from mcp.server.fastmcp.server import Context

Copy link
Contributor Author

@bhosmer-ant bhosmer-ant Apr 30, 2025

Choose a reason for hiding this comment

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

There's this a little further down in the function:

    if issubclass(param.annotation, Context):

(and having it up at the top introduces a circular dependency)

@bhosmer-ant
Copy link
Contributor Author

@ihrpr ok killed the warning suppression, can I ask you to reapprove, sorry 😬

Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

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

Looks good!

@ihrpr ihrpr merged commit 1a330ac into main Apr 30, 2025
10 checks passed
@ihrpr ihrpr deleted the basil/tool_annotations branch April 30, 2025 13:52
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.

2 participants