Implementation of SEP 973 - Additional metadata + icons support (#1357)
Some checks failed
Main branch checks / checks (push) Has been cancelled

This commit is contained in:
Peter Alexander 2025-09-24 20:29:04 +01:00 • committed by GitHub
commit 71889d7387
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 308 additions and 8 deletions

View file

@ -11,7 +11,7 @@ from pydantic import BaseModel, Field
from mcp.server.fastmcp.exceptions import ToolError
from mcp.server.fastmcp.utilities.context_injection import find_context_parameter
from mcp.server.fastmcp.utilities.func_metadata import FuncMetadata, func_metadata
from mcp.types import ToolAnnotations
from mcp.types import Icon, ToolAnnotations
if TYPE_CHECKING:
from mcp.server.fastmcp.server import Context
@ -33,6 +33,7 @@ class Tool(BaseModel):
is_async: bool = Field(description="Whether the tool is async")
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")
@cached_property
def output_schema(self) -> dict[str, Any] | None:
@ -47,6 +48,7 @@ class Tool(BaseModel):
description: str | None = None,
context_kwarg: str | None = None,
annotations: ToolAnnotations | None = None,
icons: list[Icon] | None = None,
structured_output: bool | None = None,
) -> Tool:
"""Create a Tool from a function."""
@ -78,6 +80,7 @@ class Tool(BaseModel):
is_async=is_async,
context_kwarg=context_kwarg,
annotations=annotations,
icons=icons,
)
async def run(

View file

@ -7,7 +7,7 @@ from mcp.server.fastmcp.exceptions import ToolError
from mcp.server.fastmcp.tools.base import Tool
from mcp.server.fastmcp.utilities.logging import get_logger
from mcp.shared.context import LifespanContextT, RequestT
from mcp.types import ToolAnnotations
from mcp.types import Icon, ToolAnnotations
if TYPE_CHECKING:
from mcp.server.fastmcp.server import Context
@ -49,6 +49,7 @@ class ToolManager:
title: str | None = None,
description: str | None = None,
annotations: ToolAnnotations | None = None,
icons: list[Icon] | None = None,
structured_output: bool | None = None,
) -> Tool:
"""Add a tool to the server."""
@ -58,6 +59,7 @@ class ToolManager:
title=title,
description=description,
annotations=annotations,
icons=icons,
structured_output=structured_output,
)
existing = self._tools.get(tool.name)