Skip to content

Commit e3ce66b

Browse files
committed
feat: add tool metadata in decorator
1 parent 61399b3 commit e3ce66b

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ async def list_tools(self) -> list[MCPTool]:
290290
outputSchema=info.output_schema,
291291
annotations=info.annotations,
292292
icons=info.icons,
293+
_meta=info.meta
293294
)
294295
for info in tools
295296
]
@@ -363,6 +364,7 @@ def add_tool(
363364
description: str | None = None,
364365
annotations: ToolAnnotations | None = None,
365366
icons: list[Icon] | None = None,
367+
meta: dict[str, Any] | None = None,
366368
structured_output: bool | None = None,
367369
) -> None:
368370
"""Add a tool to the server.
@@ -388,6 +390,7 @@ def add_tool(
388390
description=description,
389391
annotations=annotations,
390392
icons=icons,
393+
meta=meta,
391394
structured_output=structured_output,
392395
)
393396

@@ -409,6 +412,7 @@ def tool(
409412
description: str | None = None,
410413
annotations: ToolAnnotations | None = None,
411414
icons: list[Icon] | None = None,
415+
meta: dict[str, Any] | None = None,
412416
structured_output: bool | None = None,
413417
) -> Callable[[AnyFunction], AnyFunction]:
414418
"""Decorator to register a tool.
@@ -456,6 +460,7 @@ def decorator(fn: AnyFunction) -> AnyFunction:
456460
description=description,
457461
annotations=annotations,
458462
icons=icons,
463+
meta=meta,
459464
structured_output=structured_output,
460465
)
461466
return fn

src/mcp/server/fastmcp/tools/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Tool(BaseModel):
3434
context_kwarg: str | None = Field(None, description="Name of the kwarg that should receive context")
3535
annotations: ToolAnnotations | None = Field(None, description="Optional annotations for the tool")
3636
icons: list[Icon] | None = Field(default=None, description="Optional list of icons for this tool")
37+
meta: dict[str, Any] | None = Field(default=None, description="Optional metadata for this tool")
3738

3839
@cached_property
3940
def output_schema(self) -> dict[str, Any] | None:
@@ -49,6 +50,7 @@ def from_function(
4950
context_kwarg: str | None = None,
5051
annotations: ToolAnnotations | None = None,
5152
icons: list[Icon] | None = None,
53+
meta: dict[str, Any] | None = None,
5254
structured_output: bool | None = None,
5355
) -> Tool:
5456
"""Create a Tool from a function."""
@@ -81,6 +83,7 @@ def from_function(
8183
context_kwarg=context_kwarg,
8284
annotations=annotations,
8385
icons=icons,
86+
meta=meta
8487
)
8588

8689
async def run(

src/mcp/server/fastmcp/tools/tool_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def add_tool(
5050
description: str | None = None,
5151
annotations: ToolAnnotations | None = None,
5252
icons: list[Icon] | None = None,
53+
meta: dict[str, Any] | None = None,
5354
structured_output: bool | None = None,
5455
) -> Tool:
5556
"""Add a tool to the server."""
@@ -60,6 +61,7 @@ def add_tool(
6061
description=description,
6162
annotations=annotations,
6263
icons=icons,
64+
meta=meta,
6365
structured_output=structured_output,
6466
)
6567
existing = self._tools.get(tool.name)

0 commit comments

Comments
 (0)