fix(github): handle non-JSON upstream tool responses#388
Open
fix(github): handle non-JSON upstream tool responses#388
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="github/server/lib/mcp-proxy.ts">
<violation number="1" location="github/server/lib/mcp-proxy.ts:188">
P2: Valid falsy JSON values are misclassified as parse failures because of a truthiness check.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
2 issues found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="github/server/lib/mcp-proxy.ts">
<violation number="1">
P1: Non-JSON tool responses still throw `Failed to parse` instead of falling back to raw text/null.</violation>
<violation number="2" location="github/server/lib/mcp-proxy.ts:171">
P2: Avoid logging full upstream tool results in production; this can expose sensitive payload data and create noisy/large logs.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| @@ -168,6 +168,7 @@ export function buildUpstreamTools( | |||
| name: toolDef.name, | |||
Contributor
There was a problem hiding this comment.
P1: Non-JSON tool responses still throw Failed to parse instead of falling back to raw text/null.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At github/server/lib/mcp-proxy.ts, line 189:
<comment>Non-JSON tool responses still throw `Failed to parse` instead of falling back to raw text/null.</comment>
<file context>
@@ -185,11 +186,10 @@ export function buildUpstreamTools(
const parsed = safeJsonParse(msg);
- if (parsed) {
- return parsed;
+ if (!parsed) {
+ throw new Error(`Failed to parse: ${msg}`);
}
</file context>
| name: toolDef.name, | ||
| arguments: context as Record<string, unknown>, | ||
| }); | ||
| console.log(`[mcp-proxy] callTool result for ${toolDef.name}:`, JSON.stringify(result, null, 2)); |
Contributor
There was a problem hiding this comment.
P2: Avoid logging full upstream tool results in production; this can expose sensitive payload data and create noisy/large logs.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At github/server/lib/mcp-proxy.ts, line 171:
<comment>Avoid logging full upstream tool results in production; this can expose sensitive payload data and create noisy/large logs.</comment>
<file context>
@@ -168,6 +168,7 @@ export function buildUpstreamTools(
name: toolDef.name,
arguments: context as Record<string, unknown>,
});
+ console.log(`[mcp-proxy] callTool result for ${toolDef.name}:`, JSON.stringify(result, null, 2));
const contents = result.content as
| Array<{ type: string; text?: string }>
</file context>
Suggested change
| console.log(`[mcp-proxy] callTool result for ${toolDef.name}:`, JSON.stringify(result, null, 2)); | |
| if ((ctx as AppContext<Env>).env.NODE_ENV !== "production") { | |
| console.log(`[mcp-proxy] callTool result for ${toolDef.name}:`, JSON.stringify(result, null, 2)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_file_contents(and other tools) failing when the upstream GitHub MCP server returns plain text instead of JSON"successfully downloaded text file (SHA: ...)"caused aFailed to parseerrorTest plan
get_file_contentson a text file and verify it returns content without error🤖 Generated with Claude Code
Summary by cubic
Handle non-JSON responses from the upstream GitHub MCP server so tools like
get_file_contentsdon’t fail on plain-text messages. Added debug logging of upstreamcallToolresults to help trace response formats.callToolresponses (tool name and payload) to diagnose non-JSON cases.Written for commit 58eae94. Summary will update on new commits.