mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 23:04:25 +01:00
Add ToolAnnotations support in FastMCP and lowlevel servers (#482)
This commit is contained in:
@@ -41,6 +41,7 @@ from mcp.types import (
|
||||
GetPromptResult,
|
||||
ImageContent,
|
||||
TextContent,
|
||||
ToolAnnotations,
|
||||
)
|
||||
from mcp.types import Prompt as MCPPrompt
|
||||
from mcp.types import PromptArgument as MCPPromptArgument
|
||||
@@ -176,6 +177,7 @@ class FastMCP:
|
||||
name=info.name,
|
||||
description=info.description,
|
||||
inputSchema=info.parameters,
|
||||
annotations=info.annotations,
|
||||
)
|
||||
for info in tools
|
||||
]
|
||||
@@ -244,6 +246,7 @@ class FastMCP:
|
||||
fn: AnyFunction,
|
||||
name: str | None = None,
|
||||
description: str | None = None,
|
||||
annotations: ToolAnnotations | None = None,
|
||||
) -> None:
|
||||
"""Add a tool to the server.
|
||||
|
||||
@@ -254,11 +257,17 @@ class FastMCP:
|
||||
fn: The function to register as a tool
|
||||
name: Optional name for the tool (defaults to function name)
|
||||
description: Optional description of what the tool does
|
||||
annotations: Optional ToolAnnotations providing additional tool information
|
||||
"""
|
||||
self._tool_manager.add_tool(fn, name=name, description=description)
|
||||
self._tool_manager.add_tool(
|
||||
fn, name=name, description=description, annotations=annotations
|
||||
)
|
||||
|
||||
def tool(
|
||||
self, name: str | None = None, description: str | None = None
|
||||
self,
|
||||
name: str | None = None,
|
||||
description: str | None = None,
|
||||
annotations: ToolAnnotations | None = None,
|
||||
) -> Callable[[AnyFunction], AnyFunction]:
|
||||
"""Decorator to register a tool.
|
||||
|
||||
@@ -269,6 +278,7 @@ class FastMCP:
|
||||
Args:
|
||||
name: Optional name for the tool (defaults to function name)
|
||||
description: Optional description of what the tool does
|
||||
annotations: Optional ToolAnnotations providing additional tool information
|
||||
|
||||
Example:
|
||||
@server.tool()
|
||||
@@ -293,7 +303,9 @@ class FastMCP:
|
||||
)
|
||||
|
||||
def decorator(fn: AnyFunction) -> AnyFunction:
|
||||
self.add_tool(fn, name=name, description=description)
|
||||
self.add_tool(
|
||||
fn, name=name, description=description, annotations=annotations
|
||||
)
|
||||
return fn
|
||||
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user