Set read-only annotation hints on each tool for security

This commit is contained in:
Fahad
2025-06-26 13:16:00 +04:00
parent 2bed3a0774
commit 0237fb3419
7 changed files with 67 additions and 12 deletions

View File

@@ -47,6 +47,7 @@ from mcp.types import ( # noqa: E402
ServerCapabilities,
TextContent,
Tool,
ToolAnnotations,
ToolsCapability,
)
@@ -559,11 +560,16 @@ async def handle_list_tools() -> list[Tool]:
# Add all registered AI-powered tools from the TOOLS registry
for tool in TOOLS.values():
# Get optional annotations from the tool
annotations = tool.get_annotations()
tool_annotations = ToolAnnotations(**annotations) if annotations else None
tools.append(
Tool(
name=tool.name,
description=tool.description,
inputSchema=tool.get_input_schema(),
annotations=tool_annotations,
)
)