Skip to content

Commit be6b167

Browse files
[Draft] Add documentation for read-only tool patterns (#2536)
* 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 <[email protected]> * 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 <[email protected]> --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: William Easton <[email protected]>
1 parent 7b845a8 commit be6b167

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

docs/servers/tools.mdx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,57 @@ FastMCP supports these standard annotations:
824824

825825
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.
826826

827+
### Using Annotation Hints
828+
829+
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.
830+
831+
**Read-only tools** improve user experience by:
832+
- Skipping confirmation prompts for safe operations
833+
- Allowing broader access without security concerns
834+
- Enabling more aggressive batching and caching
835+
836+
Mark a tool as read-only when it retrieves data, performs calculations, or checks status without modifying state:
837+
838+
```python
839+
from fastmcp import FastMCP
840+
from mcp.types import ToolAnnotations
841+
842+
mcp = FastMCP("Data Server")
843+
844+
@mcp.tool(annotations={"readOnlyHint": True})
845+
def get_user(user_id: str) -> dict:
846+
"""Retrieve user information by ID."""
847+
return {"id": user_id, "name": "Alice"}
848+
849+
@mcp.tool(
850+
annotations=ToolAnnotations(
851+
readOnlyHint=True,
852+
idempotentHint=True, # Same result for repeated calls
853+
openWorldHint=False # Only internal data
854+
)
855+
)
856+
def search_products(query: str) -> list[dict]:
857+
"""Search the product catalog."""
858+
return [{"id": 1, "name": "Widget", "price": 29.99}]
859+
860+
# Write operations - no readOnlyHint
861+
@mcp.tool()
862+
def update_user(user_id: str, name: str) -> dict:
863+
"""Update user information."""
864+
return {"id": user_id, "name": name, "updated": True}
865+
866+
@mcp.tool(annotations={"destructiveHint": True})
867+
def delete_user(user_id: str) -> dict:
868+
"""Permanently delete a user account."""
869+
return {"deleted": user_id}
870+
```
871+
872+
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.
873+
874+
Client-specific behavior:
875+
- **ChatGPT**: Skips confirmation prompts for read-only tools in Chat mode (see [ChatGPT integration](/integrations/chatgpt))
876+
- **Claude**: Uses hints to understand tool safety profiles and make better execution decisions
877+
827878
## Notifications
828879

829880
<VersionBadge version="2.9.1" />

0 commit comments

Comments
 (0)