mcp icon indicating copy to clipboard operation
mcp copied to clipboard

feat: Add tool annotations for improved LLM tool understanding

Open bryankthompson opened this issue 11 months ago • 1 comments

Summary

Adds MCP tool annotations (readOnlyHint, destructiveHint, title) to all 13 tools to help LLMs better understand tool behavior and make safer decisions about tool execution.

Changes

  • Added ToolAnnotations type import to ToolSchema
  • Added readOnlyHint: true to read-only tools:
    • wait - Only pauses execution, no browser state changes
    • snapshot - Captures current page state without modification
    • getConsoleLogs - Reads existing console logs
    • screenshot - Captures image of current page state
  • Added destructiveHint: true to tools that interact with/modify the browser:
    • navigate - Changes current URL
    • goBack / goForward - Modifies browser history position
    • pressKey - Simulates keyboard input
    • click - Triggers element interactions
    • drag - Moves elements
    • hover - Can trigger hover events
    • type - Enters text into elements
    • selectOption - Changes form selection state
  • Added title annotations for human-readable display
  • Updated server.ts to include annotations in tools/list response

Why This Matters

  • Annotations provide semantic metadata that helps LLMs understand tool behavior
  • LLMs can make better decisions about when to use tools and in what order
  • readOnlyHint indicates tools safe to call without side effects
  • destructiveHint signals tools that modify browser state, requiring more careful consideration
  • Enables safer tool execution by distinguishing observation from action tools

Testing

  • [x] TypeScript types verified against @modelcontextprotocol/sdk v1.25.1
  • [x] Annotation values correctly categorize read-only vs destructive operations
  • [ ] Note: Full build requires monorepo setup (workspace dependencies)

Before/After Example

Before:

{
  name: "browser_snapshot",
  description: "Take a screenshot of the current browser state"
  // No semantic metadata
}

After:

{
  name: "browser_snapshot",
  description: "Take a screenshot of the current browser state",
  annotations: {
    title: "Snapshot",
    readOnlyHint: true
  }
}

bryankthompson avatar Dec 21 '25 19:12 bryankthompson

Friendly ping! 👋 Just checking if this PR is still on your radar. Happy to address any feedback or make adjustments if needed. No rush - just wanted to make sure it didn't slip through the cracks.

bryankthompson avatar Jan 15 '26 16:01 bryankthompson