Skip to content

feat(serve): add MCP tool annotations and server instructions - #5300

Open
debojyoti10CC wants to merge 2 commits into
Graphify-Labs:v8from
debojyoti10CC:feat/mcp-tool-annotations
Open

debojyoti10CC wants to merge 2 commits into
Graphify-Labs:v8from
debojyoti10CC:feat/mcp-tool-annotations

Conversation

@debojyoti10CC

Copy link
Copy Markdown
Contributor

What does this PR do?

graphify-mcp sent annotations: null for every tool and no instructions on initialize. Clients that gate calls on readOnlyHint therefore asked for approval on read-only tools such as graph_stats, and models got no hint about when the graph beats grep.

This PR:

  • adds a _TOOL_ANNOTATIONS table (title plus openWorldHint) and applies ToolAnnotations(title, readOnlyHint=True, openWorldHint=...) to every tool where project_path is already injected, so a new tool can't miss it. The table has one entry per tool, including get_section, which the issue's list didn't mention. list_prs, get_pr_impact and triage_prs get openWorldHint=True because they call GitHub through gh; the rest get False.
  • adds a short _SERVER_INSTRUCTIONS string and passes it as Server(..., instructions=...) in both the mcp 1.x and 2.x branches.

Both fields are optional in the spec, so clients that ignore them see no change. I only ran the suite against mcp 2.x. The 1.x branch passes the same constructor argument, but I did not run it.

Fixes #5208

Type of change

  • New feature

Verification & Invariants

Invariant: every tool returned by tools/list is annotated read-only, and only the gh-backed ones are open-world.

  • Read CONTRIBUTING.md
  • Smallest change that does the job
  • Isolated boundary tests added (tests/test_mcp_annotations.py: initialize instructions, per-tool annotations, open-world set, table covers all tools)
  • Description matches the final implementation
  • Limitation: not run against mcp 1.x

How was this tested?

uv run pytest tests/test_mcp_annotations.py tests/test_serve_http.py tests/test_serve.py -q
243 passed, 1 skipped
uv run ruff check graphify tests
All checks passed!

Graphify-specific checklist

  • No skill source fragments touched, so no skillgen bless needed
  • Extraction is unaffected
  • No shell/Python interpolation added
  • No keys or local graph data included
  • AI authorship disclosed: Claude helped write this change, and the commit carries Co-Authored-By: Claude <noreply@anthropic.com>

tools/list returned annotations=null for every tool and initialize sent
no instructions. Mark all tools readOnlyHint=True with a title, and the
three gh-backed PR tools openWorldHint=True, via one table applied where
project_path is injected so new tools stay in lockstep. Pass a short
usage guide as Server(instructions=...) on both mcp 1.x and 2.x paths.

Fixes Graphify-Labs#5208

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

Copy link
Copy Markdown

Thanks for the pull request, @debojyoti10CC. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify code review View in Graphify

Review incomplete · dcb8bb7e959d

Note

Merge confidence: 4/5 · Partly reviewed · 🟠 High impact
No issues reported · 3 of 3 files inspected
The review stopped before it finished; nothing it found blocks this PR.
1 not re-checked

What this review covered
  • The first review pass ran out of time.
  • 3 of 3 changed files inspected. This is scope, not a correctness guarantee.
Code graph and static checks · 896 functions depend on this change

Impact & health

Impact — 896 functions depend on the 225 functions this change touches.

Health — grade B; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • dispatch_command() — 8 callers, 156 callees (high)
  • _query_graph_text() — 55 callers, 7 callees (high)
  • main() — 128 callers, 3 callees (high)
  • _score_query() — 24 callers, 8 callees (high)
  • _shortest_path_text() — 27 callers, 7 callees (high)
  • resolve_seed() — 30 callers, 5 callees (high)
  • _resolve_path_endpoint() — 14 callers, 7 callees (high)
  • _find_node_tiers() — 10 callers, 9 callees (high)
  • …and 2 more

Formal checks — 896 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Gate & verification

✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 665 function(s) in the blast radius were not formally verified this run

Test selection

30 of 594 test file(s) selected (5%) via static blast radius.

  • tests/test_4874_jvm_resolution.py — impact
  • tests/test_affected_cli.py — impact
  • tests/test_affected_path_file_node.py — impact
  • tests/test_affected_seed_reference_forms.py — impact
  • tests/test_benchmark.py — impact
  • tests/test_benchmark_raw_graph.py — impact
  • tests/test_benchmark_real_query.py — impact
  • tests/test_confidence_score_output.py — impact
  • tests/test_edge_also_seen.py — impact
  • tests/test_explain_same_file_tie.py — impact
  • tests/test_extract.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_graph_context_cache_reload.py — impact
  • tests/test_markdown_sections.py — impact
  • tests/test_mcp_annotations.py — impact, changed-test
  • tests/test_mcp_graph_view_cache.py — impact
  • tests/test_path_cli.py — impact
  • tests/test_path_confidence.py — impact
  • tests/test_path_type_member.py — impact
  • tests/test_query_induced_edges.py — impact
  • tests/test_query_mcp_direction.py — impact
  • tests/test_query_names_its_graph.py — impact
  • tests/test_query_seed_order.py — impact
  • tests/test_query_seeds.py — impact
  • tests/test_query_source_first.py — impact
  • tests/test_querylog.py — impact
  • tests/test_serve.py — impact
  • tests/test_serve_http.py — impact
  • tests/test_terraform.py — impact
  • tests/test_truncation_full_answer.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

…and 10 more.

query_graph appends to the query log when GRAPHIFY_QUERY_LOG (or
GRAPHIFY_QUERY_LOG_ENABLE) is set, so advertising readOnlyHint=True is only
accurate when logging is disabled. Add querylog.is_enabled(), derive
query_graph's readOnlyHint from it, and mention the exception in the server
instructions. Addresses the review on this PR.

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

LukeMel commented Nov 20, 2026

Copy link
Copy Markdown

lgtm

@debojyoti10CC

Copy link
Copy Markdown
Contributor Author

Hi! Both of these are ready for review: #5299 (demote_docs config) and #5300 (MCP tool annotations). Tests pass and the bot review is clean. Happy to change anything you'd like.

@debojyoti10CC

Copy link
Copy Markdown
Contributor Author

Thanks @LukeMel!

This branch has not been deployed

No deployments
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.

[Feature]: MCP server: add tool annotations and server instructions

2 participants