feat: add tool metadata in FastMCP.tool decorator by mat-octave · Pull Request #1463 · modelcontextprotocol/python-sdk · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 36 additions & 8 deletions src/mcp/server/fastmcp/server.py
3 changes: 3 additions & 0 deletions src/mcp/server/fastmcp/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Tool(BaseModel):
context_kwarg: str | None = Field(None, description="Name of the kwarg that should receive context")
annotations: ToolAnnotations | None = Field(None, description="Optional annotations for the tool")
icons: list[Icon] | None = Field(default=None, description="Optional list of icons for this tool")
meta: dict[str, Any] | None = Field(default=None, description="Optional metadata for this tool")

@cached_property
def output_schema(self) -> dict[str, Any] | None:
Expand All @@ -49,6 +50,7 @@ def from_function(
context_kwarg: str | None = None,
annotations: ToolAnnotations | None = None,
icons: list[Icon] | None = None,
meta: dict[str, Any] | None = None,
structured_output: bool | None = None,
) -> Tool:
"""Create a Tool from a function."""
Expand Down Expand Up @@ -81,6 +83,7 @@ def from_function(
context_kwarg=context_kwarg,
annotations=annotations,
icons=icons,
meta=meta,
)

async def run(
Expand Down
2 changes: 2 additions & 0 deletions src/mcp/server/fastmcp/tools/tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def add_tool(
description: str | None = None,
annotations: ToolAnnotations | None = None,
icons: list[Icon] | None = None,
meta: dict[str, Any] | None = None,
structured_output: bool | None = None,
) -> Tool:
"""Add a tool to the server."""
Expand All @@ -60,6 +61,7 @@ def add_tool(
description=description,
annotations=annotations,
icons=icons,
meta=meta,
structured_output=structured_output,
)
existing = self._tools.get(tool.name)
Expand Down
172 changes: 172 additions & 0 deletions tests/server/fastmcp/test_tool_manager.py
Loading