From be6b1670d39e835d1de044c18e561a421083521b Mon Sep 17 00:00:00 2001 From: Bill Easton Date: Tue, 9 Dec 2025 12:47:29 -0600 Subject: [PATCH] [Draft] Add documentation for read-only tool patterns (#2536) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add comprehensive documentation for read-only tool patterns Created new patterns guide explaining readOnlyHint annotation usage, including practical examples, client-specific behavior, and best practices for marking tools as read-only. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: William Easton * Reorganize read-only tools docs into tools section Moved read-only tools documentation from standalone patterns page into the tools.mdx file as a "Using Annotation Hints" subsection. Condensed from 218 lines to ~50 lines focusing on practical usage while maintaining essential information about readOnlyHint and other annotations. Changes: - Added "Using Annotation Hints" subsection in tools.mdx after MCP Annotations - Removed docs/patterns/read-only-tools.mdx - Updated docs.json navigation to remove patterns entry - Content now positioned as core tool feature rather than advanced pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Bill Easton --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: William Easton --- docs/servers/tools.mdx | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/docs/servers/tools.mdx b/docs/servers/tools.mdx index 553f257dd..89291c3c3 100644 --- a/docs/servers/tools.mdx +++ b/docs/servers/tools.mdx @@ -824,6 +824,57 @@ FastMCP supports these standard annotations: Remember that annotations help make better user experiences but should be treated as advisory hints. They help client applications present appropriate UI elements and safety controls, but won't enforce security boundaries on their own. Always focus on making your annotations accurately represent what your tool actually does. +### Using Annotation Hints + +MCP clients like Claude and ChatGPT use annotation hints to determine when to skip confirmation prompts and how to present tools to users. The most commonly used hint is `readOnlyHint`, which signals that a tool only reads data without making changes. + +**Read-only tools** improve user experience by: +- Skipping confirmation prompts for safe operations +- Allowing broader access without security concerns +- Enabling more aggressive batching and caching + +Mark a tool as read-only when it retrieves data, performs calculations, or checks status without modifying state: + +```python +from fastmcp import FastMCP +from mcp.types import ToolAnnotations + +mcp = FastMCP("Data Server") + +@mcp.tool(annotations={"readOnlyHint": True}) +def get_user(user_id: str) -> dict: + """Retrieve user information by ID.""" + return {"id": user_id, "name": "Alice"} + +@mcp.tool( + annotations=ToolAnnotations( + readOnlyHint=True, + idempotentHint=True, # Same result for repeated calls + openWorldHint=False # Only internal data + ) +) +def search_products(query: str) -> list[dict]: + """Search the product catalog.""" + return [{"id": 1, "name": "Widget", "price": 29.99}] + +# Write operations - no readOnlyHint +@mcp.tool() +def update_user(user_id: str, name: str) -> dict: + """Update user information.""" + return {"id": user_id, "name": name, "updated": True} + +@mcp.tool(annotations={"destructiveHint": True}) +def delete_user(user_id: str) -> dict: + """Permanently delete a user account.""" + return {"deleted": user_id} +``` + +For tools that write to databases, send notifications, create/update/delete resources, or trigger workflows, omit `readOnlyHint` or set it to `False`. Use `destructiveHint=True` for operations that cannot be undone. + +Client-specific behavior: +- **ChatGPT**: Skips confirmation prompts for read-only tools in Chat mode (see [ChatGPT integration](/integrations/chatgpt)) +- **Claude**: Uses hints to understand tool safety profiles and make better execution decisions + ## Notifications