Add ToolAnnotations support in FastMCP and lowlevel servers (#482)

This commit is contained in:
bhosmer-ant
2025-04-30 09:52:56 -04:00
committed by GitHub
parent 017135434e
commit 1a330ac672
6 changed files with 229 additions and 5 deletions

View File

@@ -705,6 +705,54 @@ class ListToolsRequest(PaginatedRequest[RequestParams | None, Literal["tools/lis
params: RequestParams | None = None
class ToolAnnotations(BaseModel):
"""
Additional properties describing a Tool to clients.
NOTE: all properties in ToolAnnotations are **hints**.
They are not guaranteed to provide a faithful description of
tool behavior (including descriptive properties like `title`).
Clients should never make tool use decisions based on ToolAnnotations
received from untrusted servers.
"""
title: str | None = None
"""A human-readable title for the tool."""
readOnlyHint: bool | None = None
"""
If true, the tool does not modify its environment.
Default: false
"""
destructiveHint: bool | None = None
"""
If true, the tool may perform destructive updates to its environment.
If false, the tool performs only additive updates.
(This property is meaningful only when `readOnlyHint == false`)
Default: true
"""
idempotentHint: bool | None = None
"""
If true, calling the tool repeatedly with the same arguments
will have no additional effect on the its environment.
(This property is meaningful only when `readOnlyHint == false`)
Default: false
"""
openWorldHint: bool | None = None
"""
If true, this tool may interact with an "open world" of external
entities. If false, the tool's domain of interaction is closed.
For example, the world of a web search tool is open, whereas that
of a memory tool is not.
Default: true
"""
model_config = ConfigDict(extra="allow")
class Tool(BaseModel):
"""Definition for a tool the client can call."""
@@ -714,6 +762,8 @@ class Tool(BaseModel):
"""A human-readable description of the tool."""
inputSchema: dict[str, Any]
"""A JSON Schema object defining the expected parameters for the tool."""
annotations: ToolAnnotations | None = None
"""Optional additional tool information."""
model_config = ConfigDict(extra="allow")