Skip to content

feat: Add tool annotations for improved LLM tool understanding#862

Merged
MischaPanch merged 1 commit into
oraios:mainfrom
bryankthompson:feat/add-tool-annotations
Jan 1, 2026
Merged

feat: Add tool annotations for improved LLM tool understanding#862
MischaPanch merged 1 commit into
oraios:mainfrom
bryankthompson:feat/add-tool-annotations

Conversation

@bryankthompson

Copy link
Copy Markdown

Summary

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

Changes

Enhanced Annotation Generation (src/serena/mcp.py)

  • Added destructiveHint: true to tools that can modify data (those inheriting ToolMarkerCanEdit)
  • Added title annotations with human-readable display names (e.g., find_symbol → "Find Symbol")
  • Set readOnlyHint: true for read-only tools, destructiveHint: true for edit tools

Fixed Memory Tools (src/serena/tools/memory_tools.py)

  • WriteMemoryTool, DeleteMemoryTool, and EditMemoryTool now correctly inherit ToolMarkerCanEdit
  • This ensures these tools properly receive destructiveHint: true instead of incorrectly being marked as read-only

Why This Matters

  • Safety: LLMs can distinguish read-only from destructive operations before execution
  • Better Tool Selection: Helps LLMs prioritize read-only tools for information gathering
  • Human Readability: Title annotations provide clear display names for tool interfaces

Before/After

Before:

annotations = ToolAnnotations(readOnlyHint=not tool.can_edit())
# WriteMemoryTool incorrectly marked as readOnlyHint=True

After:

annotations = ToolAnnotations(
    title=tool_title,
    readOnlyHint=not can_edit,
    destructiveHint=can_edit,
)
# WriteMemoryTool correctly marked as destructiveHint=True

Testing

  • Server builds successfully (uv sync)
  • Type checker passes (pyright)
  • Linter passes (ruff check)
  • Memory tool inheritance verified:
    • WriteMemoryTool.can_edit()True
    • DeleteMemoryTool.can_edit()True
    • EditMemoryTool.can_edit()True
    • ReadMemoryTool.can_edit()False
    • ListMemoriesTool.can_edit()False

🤖 Generated with Claude Code

Add readOnlyHint, destructiveHint, and title annotations to all tools
to help LLMs better understand tool behavior and make safer decisions.

Changes:
- Added destructiveHint: true to tools that modify data
- Added title annotations for human-readable display (e.g., "Find Symbol")
- Fixed memory tools (WriteMemoryTool, DeleteMemoryTool, EditMemoryTool)
  to correctly inherit ToolMarkerCanEdit, ensuring they get destructiveHint: true

This improves tool safety metadata for MCP clients by:
- Helping LLMs distinguish read-only from destructive operations
- Providing human-readable titles for tool display
- Correctly categorizing all memory-modifying tools as destructive

Co-Authored-By: Claude <noreply@anthropic.com>
@bryankthompson

Copy link
Copy Markdown
Author

Hi maintainers,

The CI test failures appear to be pre-existing issues unrelated to this PR's changes. This PR only adds MCP tool annotations (metadata hints like readOnlyHint and destructiveHint) to help LLMs better understand tool behavior - no functional code changes.

The failing tests are all in the Vue language server test suite:

  • test_find_referencing_symbols[vue]
  • test_cross_file_references_vue_to_typescript[vue]
  • test_cross_file_references_typescript_to_vue[vue]

These failures relate to Vue/TypeScript cross-file reference resolution, which my annotation-only changes don't touch.

Happy to rebase if needed, but wanted to flag that these failures seem to be a separate issue in the test suite.

@MischaPanch

Copy link
Copy Markdown
Member

Thank you and sorry for the late review - I wanted to make sure everything still works by performing manual checks and hadn't found time for that. Now I did, everything does work.

Merging

@MischaPanch MischaPanch merged commit 823e7c6 into oraios:main Jan 1, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants