From f7111a5d2bb6d2d2d385f29f9768f230932b0b35 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Thu, 21 Aug 2025 11:50:21 -0700 Subject: [PATCH] feat: Improve error message for 403 permission errors when committing When the github_file_ops MCP server gets a 403 error, it now shows a cleaner message suggesting to rebase from main/master branch to fix the issue. --- src/mcp/github-file-ops-server.ts | 36 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/mcp/github-file-ops-server.ts b/src/mcp/github-file-ops-server.ts index b4e8a19..9fcf00e 100644 --- a/src/mcp/github-file-ops-server.ts +++ b/src/mcp/github-file-ops-server.ts @@ -385,15 +385,22 @@ server.tool( if (!updateRefResponse.ok) { const errorText = await updateRefResponse.text(); + + // Provide a more helpful error message for 403 permission errors + if (updateRefResponse.status === 403) { + const permissionError = new Error( + `Permission denied: Unable to push commits to branch '${branch}'. ` + + `Please rebase your branch from the main/master branch to allow Claude to commit.\n\n` + + `Original error: ${errorText}`, + ); + throw permissionError; + } + + // For other errors, use the original message const error = new Error( `Failed to update reference: ${updateRefResponse.status} - ${errorText}`, ); - // Only retry on 403 errors - these are the intermittent failures we're targeting - if (updateRefResponse.status === 403) { - throw error; - } - // For non-403 errors, fail immediately without retry console.error("Non-retryable error:", updateRefResponse.status); throw error; @@ -591,16 +598,23 @@ server.tool( if (!updateRefResponse.ok) { const errorText = await updateRefResponse.text(); + + // Provide a more helpful error message for 403 permission errors + if (updateRefResponse.status === 403) { + console.log("Received 403 error, will retry..."); + const permissionError = new Error( + `Permission denied: Unable to push commits to branch '${branch}'. ` + + `Please rebase your branch from the main/master branch to allow Claude to commit.\n\n` + + `Original error: ${errorText}`, + ); + throw permissionError; + } + + // For other errors, use the original message const error = new Error( `Failed to update reference: ${updateRefResponse.status} - ${errorText}`, ); - // Only retry on 403 errors - these are the intermittent failures we're targeting - if (updateRefResponse.status === 403) { - console.log("Received 403 error, will retry..."); - throw error; - } - // For non-403 errors, fail immediately without retry console.error("Non-retryable error:", updateRefResponse.status); throw error;