From d7a5b003e46f3806b296783203d14199576611b1 Mon Sep 17 00:00:00 2001 From: km-anthropic Date: Mon, 11 Aug 2025 13:22:11 -0700 Subject: [PATCH] Update agent mode to have github server as a default --- src/modes/agent/index.ts | 37 +++++++++++++++++++++++++++++++------ test/modes/agent.test.ts | 15 +++++++++------ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/modes/agent/index.ts b/src/modes/agent/index.ts index 34e7149..cbae2d4 100644 --- a/src/modes/agent/index.ts +++ b/src/modes/agent/index.ts @@ -60,10 +60,27 @@ export const agentMode: Mode = { // Agent mode: User has full control via claudeArgs // No default tools are enforced - Claude Code's defaults will apply - // Agent mode uses a minimal MCP configuration - // We don't need comment servers or PR-specific tools for automation + // Always include the GitHub comment server in agent mode + // This ensures GitHub tools (PR reviews, comments, etc.) work out of the box + // without requiring users to manually configure the MCP server const mcpConfig: any = { - mcpServers: {}, + mcpServers: { + "github-comment-server": { + command: "bun", + args: [ + "run", + `${process.env.GITHUB_ACTION_PATH}/src/mcp/github-comment-server.ts`, + ], + env: { + GITHUB_TOKEN: process.env.GITHUB_TOKEN || "", + REPO_OWNER: context.repository.owner, + REPO_NAME: context.repository.repo, + GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || "", + GITHUB_API_URL: + process.env.GITHUB_API_URL || "https://api.github.com", + }, + }, + }, }; // Add user-provided additional MCP config if any @@ -72,16 +89,24 @@ export const agentMode: Mode = { try { const additional = JSON.parse(additionalMcpConfig); if (additional && typeof additional === "object") { - Object.assign(mcpConfig, additional); + // Merge mcpServers if both have them + if (additional.mcpServers && mcpConfig.mcpServers) { + Object.assign(mcpConfig.mcpServers, additional.mcpServers); + } else { + Object.assign(mcpConfig, additional); + } } } catch (error) { core.warning(`Failed to parse additional MCP config: ${error}`); } } - // Agent mode: pass through user's claude_args without modification + // Agent mode: pass through user's claude_args with MCP config const userClaudeArgs = process.env.CLAUDE_ARGS || ""; - core.setOutput("claude_args", userClaudeArgs); + const escapedMcpConfig = JSON.stringify(mcpConfig).replace(/'/g, "'\\''"); + const claudeArgs = + `--mcp-config '${escapedMcpConfig}' ${userClaudeArgs}`.trim(); + core.setOutput("claude_args", claudeArgs); return { commentId: undefined, diff --git a/test/modes/agent.test.ts b/test/modes/agent.test.ts index 198535a..d9456f1 100644 --- a/test/modes/agent.test.ts +++ b/test/modes/agent.test.ts @@ -114,11 +114,11 @@ describe("Agent Mode", () => { githubToken: "test-token", }); - // Verify claude_args is passed through - expect(setOutputSpy).toHaveBeenCalledWith( - "claude_args", - "--model claude-sonnet-4 --max-turns 10", - ); + // Verify claude_args includes MCP config and user args + const callArgs = setOutputSpy.mock.calls[0]; + expect(callArgs[0]).toBe("claude_args"); + expect(callArgs[1]).toContain("--mcp-config"); + expect(callArgs[1]).toContain("--model claude-sonnet-4 --max-turns 10"); // Verify return structure expect(result).toEqual({ @@ -151,6 +151,9 @@ describe("Agent Mode", () => { // Note: We can't easily test file creation in this unit test, // but we can verify the method completes without errors - expect(setOutputSpy).toHaveBeenCalledWith("claude_args", ""); + // Agent mode now includes MCP config even with empty user args + const callArgs = setOutputSpy.mock.calls[0]; + expect(callArgs[0]).toBe("claude_args"); + expect(callArgs[1]).toContain("--mcp-config"); }); });