π The fast, Pythonic way to build MCP servers and clients.
Add MCP tool annotations to get_file example (#5976)
Shivam Mahajan9607e310e711
diff --git a/examples/get_file.py b/examples/get_file.pyindex b86ca9223..768fea3e8 100644--- a/examples/get_file.py+++ b/examples/get_file.py@@ -5,6 +5,7 @@# uv pip install aiohttp fastmcpimport aiohttp+from mcp_types import ToolAnnotationsfrom fastmcp.server import FastMCPfrom fastmcp.utilities.types import File@@ -13,14 +14,14 @@ from fastmcp.utilities.types import Filedef create_server():mcp = FastMCP(name="File Demo", instructions="Get files from the server or URL.")- @mcp.tool()+ @mcp.tool(annotations=ToolAnnotations(read_only_hint=True, open_world_hint=False))async def get_test_file_from_server(path: str = "requirements.txt") -> File:"""Get a test file from the server. If the path is not provided, it defaults to 'requirements.txt'."""return File(path=path)- @mcp.tool()+ @mcp.tool(annotations=ToolAnnotations(read_only_hint=True, open_world_hint=True))async def get_test_pdf_from_url(url: str = "https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf",) -> File: