Skip to content

fix(mcp): derive the remote request-level ok from the tool result, not HTTP status - #10231

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-10035
Jul 31, 2026
Merged

fix(mcp): derive the remote request-level ok from the tool result, not HTTP status#10231
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-10035

Conversation

@bitfathers94

Copy link
Copy Markdown
Contributor

fix(mcp): derive the remote request-level ok from the tool result, not HTTP status

enableJsonResponse means a refused tools/call is still HTTP 200, so the legacy
mcp_tool_call event and the product-usage outcome -- both keyed off
response.status -- reported every refusal as a success even though the
dispatch chokepoint's own usage_event already recorded it as a failure.
handleMcpRequest now reads the JSON-RPC body the same way it already reads the
request, falling back to the status on any parse failure, and only for
tools/call so every other request keeps its current behavior.

Closes #10035

…t HTTP status

enableJsonResponse means a refused tools/call is still HTTP 200, so the legacy
mcp_tool_call event and the product-usage outcome -- both keyed off
response.status -- reported every refusal as a success even though the
dispatch chokepoint's own usage_event already recorded it as a failure.
handleMcpRequest now reads the JSON-RPC body the same way it already reads the
request, falling back to the status on any parse failure, and only for
tools/call so every other request keeps its current behavior.
@bitfathers94
bitfathers94 requested a review from JSONbored as a code owner July 31, 2026 13:23
@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-31 13:34:30 UTC

4 files · 1 AI reviewer · no blockers · readiness 93/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR fixes a real bug: enableJsonResponse:true makes a refused tools/call return HTTP 200, so both the legacy telemetry event and the product-usage outcome were reading response.status and misreporting every tool refusal as a success, even though dispatch-telemetry.ts's own usage_event already correctly recorded it as a failure. The fix adds resolveMcpToolCallOk, which clones and parses the JSON-RPC body for tools/call requests only, checking result.isError/error before falling back to statusOk, and threads that ok through both the toolTelemetry call and the outcome field. The scope is tightly targeted (only tools/call is affected, every other method keeps status-derived behavior), the clone-before-read is correct so the caller's own response body is untouched, and the fallback-to-statusOk-on-parse-failure preserves the never-throw telemetry guarantee. Tests cover isError, top-level error, normal success, JSON-parse-failure fallback, and body-still-readable-after-clone, plus an integration test exercising the real refusal path end-to-end.

Nits — 3 non-blocking
  • src/mcp/server.ts:694/809 and dispatch-telemetry.ts:85 use bare 400/200 literals instead of named constants, though this matches the pre-existing status<400 convention already in the file.
  • resolveMcpToolCallOk only checks result.isError === true and a top-level error object truthiness — if the SDK ever returns error: null explicitly that would still correctly fall through to statusOk, but worth double-checking the SDK never sends error: false or similar falsy-but-present shapes.
  • Consider extracting the magic 400 status threshold used in both statusOk and the pre-existing status<400 checks into a shared HTTP_OK_THRESHOLD constant for consistency across the file.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #10035
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ⚠️ 20/25 Preflight is ready, but the PR body does not name the validation run.
Contributor workload ✅ 10/10 Author activity: 130 registered-repo PR(s), 92 merged, 3 issue(s).
Contributor context ✅ Confirmed Gittensor contributor bitfathers94; Gittensor profile; 130 PR(s), 3 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The diff derives `ok`/`outcome` from the JSON-RPC body via a new resolveMcpToolCallOk helper (cloning the response, falling back to statusOk on parse failure) for tools/call requests, threads it into both recordMcpToolTelemetry and the product-usage outcome, updates the stale comment in dispatch-telemetry.ts, and adds both the required integration regression test and the unit test covering the non

Review context
  • Author: bitfathers94
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: TypeScript
  • Official Gittensor activity: 130 PR(s), 3 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Add validation command/output.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

Decision record
  • action: merge · clause: success
  • config: 023c0a60442dfa13083e23a8dd9f241cbb946da8631e2b887cf70df068258fa2 · pack: oss-anti-slop · ci: passed
  • record: 2e2832ffb22b91dac7654a2ac8ddb12e23c4d8bb684795bd2549a39de01b64bd (schema v6, head 727cc8d)

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.87%. Comparing base (bde62d6) to head (727cc8d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10231      +/-   ##
==========================================
+ Coverage   80.47%   80.87%   +0.39%     
==========================================
  Files         282      284       +2     
  Lines       58856    60240    +1384     
  Branches     6978     7302     +324     
==========================================
+ Hits        47366    48719    +1353     
- Misses      11199    11207       +8     
- Partials      291      314      +23     
Flag Coverage Δ
backend 97.76% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/mcp/dispatch-telemetry.ts 100.00% <ø> (ø)
src/mcp/server.ts 97.70% <100.00%> (ø)

@loopover-orb loopover-orb Bot 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.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Queued in the merge train behind #10225, which touches overlapping work and was opened first. This PR merges automatically once #10225 completes (or leaves the train). No action needed. This is an automated maintenance action.

@loopover-orb
loopover-orb Bot merged commit e055c59 into JSONbored:main Jul 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp(telemetry): derive the remote request-level ok from the tool result, not the HTTP status

1 participant