From 05d98891652edcfe8ea79aca5577cb52687f1a5b Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Tue, 12 Aug 2025 08:54:10 -0700 Subject: [PATCH] Fix: Use correct MCP server names and add inline comment server for PRs - Changed github-comment-server to github_comment (correct registration name) - Added github_inline_comment server for PR contexts - Updated workflow to use correct tool names (mcp__github_inline_comment__) - Simplified prompt to use inline comments instead of full PR reviews --- .github/workflows/claude-auto-review-test.yml | 12 ++++----- src/mcp/install-mcp-server.ts | 25 +++++++++++++++--- src/modes/agent/index.ts | 26 ++++++++++++++++++- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/.github/workflows/claude-auto-review-test.yml b/.github/workflows/claude-auto-review-test.yml index b909a80..b9031fe 100644 --- a/.github/workflows/claude-auto-review-test.yml +++ b/.github/workflows/claude-auto-review-test.yml @@ -22,11 +22,9 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} prompt: | - Please review this PR using the GitHub review tools. You MUST: - 1. First, use mcp__github-comment-server__get_pull_request_diff to get the PR changes - 2. Then, use mcp__github-comment-server__create_pending_pull_request_review to start a review - 3. Use mcp__github-comment-server__add_comment_to_pending_review to add inline comments where needed - 4. Finally, use mcp__github-comment-server__submit_pending_pull_request_review with event="COMMENT" to submit the review + Please review this PR and provide comprehensive feedback. + + Use the mcp__github_inline_comment__create_inline_comment tool to add inline comments on specific lines where you have feedback. In your review, provide thoughtful feedback on: - Code quality and best practices @@ -35,6 +33,6 @@ jobs: - Overall architecture and design decisions - Documentation consistency - IMPORTANT: You must submit the review as a COMMENT, not APPROVE or REQUEST_CHANGES. + Be constructive and specific in your feedback. anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - claude_args: "--allowedTools mcp__github-comment-server__create_pending_pull_request_review,mcp__github-comment-server__add_comment_to_pending_review,mcp__github-comment-server__submit_pending_pull_request_review,mcp__github-comment-server__get_pull_request_diff" + claude_args: "--allowedTools mcp__github_inline_comment__create_inline_comment,Read,Grep,Glob" diff --git a/src/mcp/install-mcp-server.ts b/src/mcp/install-mcp-server.ts index 2925d43..9a87f12 100644 --- a/src/mcp/install-mcp-server.ts +++ b/src/mcp/install-mcp-server.ts @@ -111,10 +111,29 @@ export async function prepareMcpConfig( }; } - // CI server is included when we have a workflow token and context is a PR - const hasWorkflowToken = !!process.env.DEFAULT_WORKFLOW_TOKEN; + // Include inline comment server for experimental review mode + if (context.inputs.mode === "experimental-review" && context.isPR) { + baseMcpConfig.mcpServers.github_inline_comment = { + command: "bun", + args: [ + "run", + `${process.env.GITHUB_ACTION_PATH}/src/mcp/github-inline-comment-server.ts`, + ], + env: { + GITHUB_TOKEN: githubToken, + REPO_OWNER: owner, + REPO_NAME: repo, + PR_NUMBER: context.entityNumber?.toString() || "", + GITHUB_API_URL: GITHUB_API_URL, + }, + }; + } - if (context.isPR && hasWorkflowToken) { + // Only add CI server if we have actions:read permission and we're in a PR context + const hasActionsReadPermission = + context.inputs.additionalPermissions.get("actions") === "read"; + + if (context.isPR && hasActionsReadPermission) { // Verify the token actually has actions:read permission const actuallyHasPermission = await checkActionsReadPermission( process.env.DEFAULT_WORKFLOW_TOKEN || "", diff --git a/src/modes/agent/index.ts b/src/modes/agent/index.ts index 07fe742..c47b97d 100644 --- a/src/modes/agent/index.ts +++ b/src/modes/agent/index.ts @@ -67,7 +67,7 @@ export const agentMode: Mode = { // without requiring users to manually configure the MCP server const mcpConfig: any = { mcpServers: { - "github-comment-server": { + github_comment: { command: "bun", args: [ "run", @@ -77,6 +77,7 @@ export const agentMode: Mode = { GITHUB_TOKEN: githubToken || "", REPO_OWNER: context.repository.owner, REPO_NAME: context.repository.repo, + CLAUDE_COMMENT_ID: process.env.CLAUDE_COMMENT_ID || "", GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || "", GITHUB_API_URL: process.env.GITHUB_API_URL || "https://api.github.com", @@ -84,6 +85,29 @@ export const agentMode: Mode = { }, }, }; + + // Include inline comment server for PR contexts + if (context.eventName === "pull_request" || context.eventName === "pull_request_review") { + // Get PR number from the context payload + const prNumber = (context as any).payload?.pull_request?.number || + (context as any).entityNumber || + ""; + + mcpConfig.mcpServers.github_inline_comment = { + command: "bun", + args: [ + "run", + `${process.env.GITHUB_ACTION_PATH}/src/mcp/github-inline-comment-server.ts`, + ], + env: { + GITHUB_TOKEN: githubToken || "", + REPO_OWNER: context.repository.owner, + REPO_NAME: context.repository.repo, + PR_NUMBER: prNumber.toString(), + GITHUB_API_URL: process.env.GITHUB_API_URL || "https://api.github.com", + }, + }; + } // Add user-provided additional MCP config if any const additionalMcpConfig = process.env.MCP_CONFIG || "";