Skip to content

Add MCP readOnlyHint annotations to tools - #1124

Merged
1 commit merged into
tirth8205:stagingfrom
jay23606:fix/1123-mcp-read-only-hints
Nov 6, 2026
Merged

1 commit merged into
tirth8205:stagingfrom
jay23606:fix/1123-mcp-read-only-hints

Conversation

@jay23606

Copy link
Copy Markdown
Contributor

Fixes #1123

Change

Every @mcp.tool() in code_review_graph/main.py is now registered with annotations:

  • apply_refactor_tool: readOnlyHint: False, destructiveHint: True (writes source files).
  • build_or_update_graph_tool, run_postprocess_tool, embed_graph_tool, generate_wiki_tool: readOnlyHint: False, destructiveHint: False, idempotentHint: True (write only the graph's own data).
  • The remaining 25 tools: readOnlyHint: True.

The classification follows the one proposed in the issue. No tool behaviour changes.

New test: tests/test_tool_annotations.py lists the tools over the FastMCP API and checks the hints above.

Tests

Before (uv run --python 3.13 python -m pytest tests/test_tool_annotations.py -q): 3 failed. No tool declares annotations (AttributeError: 'NoneType' object has no attribute 'readOnlyHint').

After (same command plus tests/test_public_tool_hints.py, which parses the same decorators): 4 passed.

Not run: the full suite and the surface-marked MCP tests.

Every @mcp.tool() was registered with no annotations, so MCP clients
could not tell read-only query tools from writers. Declare readOnlyHint
on all 30 tools: apply_refactor_tool is destructive, the four graph
writers are non-destructive and idempotent, and the rest are read-only.

Fixes tirth8205#1123

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Signed-off-by: jay23606 <4602056+jay23606@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

code-review-graph review

Overall risk: 0.35 (LOW) — 4 changed function(s)/class(es), 37 affected flow(s), 0 test gap(s)

Risk-scored changes

Risk Level Symbol Location Tested
0.35 low tests/test_tool_annotations.py::test_query_tools_are_read_only tests/test_tool_annotations.py:37 (test)
0.25 low tests/test_tool_annotations.py::_tools tests/test_tool_annotations.py:16 (test)
0.15 low tests/test_tool_annotations.py::test_every_tool_declares_read_only_hint tests/test_tool_annotations.py:20 (test)
0.15 low tests/test_tool_annotations.py::test_write_tools_are_not_read_only tests/test_tool_annotations.py:27 (test)

Affected execution flows

  • build_or_update_graph_tool — criticality 0.73, 619 node(s) across 24 file(s)
  • refactor_tool — criticality 0.72, 159 node(s) across 12 file(s)
  • query_graph_tool — criticality 0.69, 97 node(s) across 11 file(s)
  • semantic_search_nodes_tool — criticality 0.68, 85 node(s) across 13 file(s)
  • traverse_graph_tool — criticality 0.67, 68 node(s) across 11 file(s)
  • ...and 32 more affected flow(s)

Powered by code-review-graph — local-first analysis; no code leaves the CI runner.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Tool safety hints mislabel queries that can create or migrate databases as read-only, destructive operations as additive-only, and identity-changing post-processing as idempotent.

3 open issues
What changed in this PR

Adds MCP tool annotations to help clients distinguish queries from writes, addressing unnecessary permission prompts in plan/read-only modes described in #1123.

Changes:

  • Adds read-only, destructive, and idempotent hints across all 30 tool registrations.
  • Adds FastMCP API tests for annotation presence and read/write classifications.
  • Leaves tool implementations unchanged.
File Description
tests/​test_tool_annotations.py Tests registered tools’ read-only and destructive hints.
code_review_graph/​main.py Adds annotations to every MCP tool decorator.

Review effort: Balanced

Comment thread code_review_graph/main.py


@mcp.tool()
@mcp.tool(annotations={"readOnlyHint": True})
Comment thread code_review_graph/main.py


@mcp.tool()
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": False, "idempotentHint": True})
Comment thread code_review_graph/main.py


@mcp.tool()
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": False, "idempotentHint": True})
@tirth8205 tirth8205 closed this pull request by merging all changes into tirth8205:staging in 0160eb0 Nov 6, 2026
gowrishacv pushed a commit to gowrishacv/code-review-graph that referenced this pull request Nov 6, 2026
gowrishacv pushed a commit to gowrishacv/code-review-graph that referenced this pull request Nov 6, 2026
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.

Add MCP tool annotations (readOnlyHint) so read-only tools don't prompt in client plan/read-only modes

3 participants