Skip to content

Set isError on MCP tool-level failures - #2725

Open
ayushcodes10 wants to merge 1 commit into
Graphify-Labs:v8from
ayushcodes10:fix-2714-mcp-tool-error-flag
Open

ayushcodes10 wants to merge 1 commit into
Graphify-Labs:v8from
ayushcodes10:fix-2714-mcp-tool-error-flag

Conversation

@ayushcodes10

Copy link
Copy Markdown
Contributor

A bad project_path, a corrupt project graph, or an unknown tool name all returned isError unset, indistinguishable from success to any caller that branches on the flag rather than reading the text (health checks, CI gates, rollout scripts). call_tool now returns a full CallToolResult with isError set on failure; both the mcp 1.x decorator and the mcp 2.x on_call_tool callback forward it as-is.

Fixes #2714.

@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 reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

This PR changes the MCP call_tool handler in graphify/serve.py to return a types.CallToolResult object instead of a bare list[TextContent], setting isError=True on the failure paths (unknown tool, exceptions, graph selection errors) and leaving it unset on success. It updates both the mcp 1.x decorator registration and the mcp 2.x on_call_tool callback to forward this result directly rather than re-wrapping the content. The test file adds a _call_tool_result helper that returns the full result object and four new tests asserting the isError flag behavior across bad project paths, corrupt graphs, successful calls, and unknown tool names.

Worth a look

  • call_tool binds shared G/communities per-request without locking; concurrent tool calls race on global graph selection — graphify/serve.py:1988 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 460 functions depend on the 161 functions this change touches.

Health — this change adds coupling hotspots:

  • new: test_corrupt_project_graph_sets_is_error() — 0 callers, 7 callees

Verification — 460 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

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

Advisory (not blocking):

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

Formal verification

Could not verify: Could not verify \_build\_server.

The verifier did not have enough to check \_build\_server, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: not verifiable: all 23 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly ImportError — names the real obstacle, not a sampling gap)

· 1 grounded finding(s) anchored inline below.

Comment thread tests/test_serve_http.py Resolved
@ayushcodes10

Copy link
Copy Markdown
Contributor Author

@safishamsi this PR's CI run is waiting on approval (first-time contributor gate) — could you approve the workflow run when you get a chance? Happy to address any review feedback in the meantime.

safishamsi pushed a commit that referenced this pull request Aug 29, 2026
The prs MCP tools (list_prs, triage_prs, get_pr_impact) returned genuine failures (gh
missing/unauth, unresolved PR) as success text. Raise a ToolError propagated as isError on
both the 1.x and 2.x SDK paths, so a client sees the failure; an empty-but-successful result
(0 PRs, PR with no changed files) is unaffected. Mirrors the #2725 MCP-error pattern.
An unknown tool name and any other unexpected failure reaching
call_tool's catch all (a bad project_path, a corrupt project graph)
returned as plain success shaped content, isError unset, so a caller
that branches on the flag rather than reading the text (health
checks, CI gates, rollout scripts) could not tell them from success.

Upstream already built ToolError for exactly this: a handler raises
it to signal a genuine failure, and both the mcp 1.x decorator (via
its own exception wrapping) and the 2.x on_call_tool callback turn it
into a result with isError:true. Routes the two remaining gaps
through that same mechanism instead of a bare return, so all three
failure shapes now carry the same, consistent isError contract.

Fixes Graphify-Labs#2714.
@ayushcodes10
ayushcodes10 force-pushed the fix-2714-mcp-tool-error-flag branch from 6751360 to ecbf7e3 Compare September 5, 2026 23:44
@ayushcodes10

Copy link
Copy Markdown
Contributor Author

Rebased onto current v8. Upstream had since added a ToolError mechanism for handler signalled failures (a few gh/PR tools already raise it), so this now routes the remaining two gaps (unknown tool name, the general failure catch all) through that same mechanism instead of constructing CallToolResult objects directly, which keeps this consistent with how the rest of the file already signals isError. Added dedicated isError assertions to the existing test file; full suite green.

@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 reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Marks tool-level failures with isError:true by raising ToolError from _on_call_tool for unknown tool names, bad project_path values, corrupt project graphs, and any other unexpected handler exception, instead of returning error text in a success-shaped result that programmatic callers can't distinguish from a real answer. Adds a _call_tool_result test helper that returns the full tools/call result so tests can assert on isError, and covers the bad/corrupt/unknown cases plus a check that a successful call leaves isError unset.

No blocking issues surfaced. 5 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 524 functions depend on the 178 functions this change touches.

Health — this change adds coupling hotspots:

  • new: dispatch_command() — 2 callers, 124 callees
  • new: _query_graph_text() — 21 callers, 9 callees
  • new: _score_query() — 15 callers, 6 callees
  • new: _query_terms() — 20 callers, 3 callees
  • new: run_benchmark() — 16 callers, 3 callees
  • new: _build_server() — 2 callers, 16 callees
  • new: _load_graph() — 9 callers, 3 callees
  • new: _query_subgraph_tokens() — 7 callers, 3 callees
  • …and 10 more — each is listed as a finding

Verification — 524 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

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

Advisory (not blocking):

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

Formal verification

Could not verify: Could not verify \_build\_server.

The verifier did not have enough to check \_build\_server, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: not verifiable: all 23 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous

· 2 grounded finding(s) anchored inline below; 16 more finding(s) on lines outside this diff (see the check run).

Comment thread tests/test_serve_http.py
assert result.get("isError") is True, f"expected isError=True, got {result}"


def test_corrupt_project_graph_is_a_tool_error_without_killing_server(tmp_path):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — test_corrupt_project_graph_is_a_tool_error_without_killing_server()

fans out to 7 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread tests/test_serve_http.py
assert "Nodes: 2" in _call_tool(client, headers, "graph_stats", {}, rid=3)


def test_corrupt_project_graph_sets_is_error(tmp_path):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — test_corrupt_project_graph_sets_is_error()

fans out to 7 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

@ayushcodes10

Copy link
Copy Markdown
Contributor Author

@safishamsi rebased onto the latest v8 and all checks are green now — ready for review whenever you get a chance.

@ayushcodes10

Copy link
Copy Markdown
Contributor Author

Closing the loop on the concurrency finding from the first review round (serve.py:1988, never explicitly replied to — a later round dropped it, but I want the reasoning on record rather than leaving it silently unanswered).

Checked directly: `_select_graph(project_path)` and the subsequent `handler(arguments)` call in `call_tool` both run with no `await` between them — `_select_graph` itself has no `await`, and every entry in `_handlers` (e.g. `_tool_query_graph`) is a plain `def`, called without `await`. Under asyncio's single-threaded event loop, a coroutine only yields control at an `await` point, so this whole stretch — rebinding `G`/`communities` and running the handler against them — executes as one uninterruptible unit. A concurrent `call_tool` invocation can't be scheduled in the middle of it, so it can't observe a half-applied graph swap. This matches the reasoning already written into the code right above `_select_graph`'s definition.

No changes needed here.

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.

graphify-mcp: tool failures return isError unset, so a missing project_path graph is indistinguishable from success to any programmatic caller

1 participant