Compare commits

...

5 Commits

Author SHA1 Message Date
km-anthropic
340104d9cf fix: use proper type guards instead of manual property checks
Address review feedback by using isEntityContext() type guard instead of
checking 'isPR' in context manually. This provides better type safety
and uses the existing type guard infrastructure.
2025-08-01 15:43:07 -07:00
km-anthropic
9abdfa8a3a Merge branch 'main' into km/add-mcp-to-agent
Resolved conflict by keeping both MCP server changes and generatePrompt method
2025-08-01 15:38:20 -07:00
km-anthropic
6c5d11c8c3 fix: remove generatePrompt method to match Mode interface
Remove the generatePrompt method from agent mode since it's not part of the Mode interface in the current main branch. Also remove unused PreparedContext import.
2025-08-01 14:35:42 -07:00
km-anthropic
106183c4c0 bun format 2025-08-01 14:26:31 -07:00
km-anthropic
7cc3cff20b feat: add MCP servers to agent mode
- Update agent mode to use prepareMcpConfig instead of empty config
- Update prepareMcpConfig to accept both ParsedGitHubContext and AutomationContext
- Add type guards for context-specific properties (isPR, entityNumber)
- This enables bot actors to use full MCP capabilities via workflow_dispatch
2025-08-01 14:26:15 -07:00
2 changed files with 23 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import { GITHUB_API_URL, GITHUB_SERVER_URL } from "../github/api/config"; import { GITHUB_API_URL, GITHUB_SERVER_URL } from "../github/api/config";
import type { ParsedGitHubContext } from "../github/context"; import type { GitHubContext } from "../github/context";
import { isEntityContext } from "../github/context";
import { Octokit } from "@octokit/rest"; import { Octokit } from "@octokit/rest";
type PrepareConfigParams = { type PrepareConfigParams = {
@@ -12,7 +13,7 @@ type PrepareConfigParams = {
additionalMcpConfig?: string; additionalMcpConfig?: string;
claudeCommentId?: string; claudeCommentId?: string;
allowedTools: string[]; allowedTools: string[];
context: ParsedGitHubContext; context: GitHubContext;
}; };
async function checkActionsReadPermission( async function checkActionsReadPermission(
@@ -115,7 +116,7 @@ export async function prepareMcpConfig(
const hasActionsReadPermission = const hasActionsReadPermission =
context.inputs.additionalPermissions.get("actions") === "read"; context.inputs.additionalPermissions.get("actions") === "read";
if (context.isPR && hasActionsReadPermission) { if (isEntityContext(context) && context.isPR && hasActionsReadPermission) {
// Verify the token actually has actions:read permission // Verify the token actually has actions:read permission
const actuallyHasPermission = await checkActionsReadPermission( const actuallyHasPermission = await checkActionsReadPermission(
process.env.ACTIONS_TOKEN || "", process.env.ACTIONS_TOKEN || "",
@@ -141,7 +142,9 @@ export async function prepareMcpConfig(
GITHUB_TOKEN: process.env.ACTIONS_TOKEN, GITHUB_TOKEN: process.env.ACTIONS_TOKEN,
REPO_OWNER: owner, REPO_OWNER: owner,
REPO_NAME: repo, REPO_NAME: repo,
PR_NUMBER: context.entityNumber?.toString() || "", PR_NUMBER: isEntityContext(context)
? context.entityNumber?.toString() || ""
: "",
RUNNER_TEMP: process.env.RUNNER_TEMP || "/tmp", RUNNER_TEMP: process.env.RUNNER_TEMP || "/tmp",
}, },
}; };

View File

@@ -2,6 +2,7 @@ import * as core from "@actions/core";
import type { Mode, ModeOptions, ModeResult } from "../types"; import type { Mode, ModeOptions, ModeResult } from "../types";
import { isAutomationContext } from "../../github/context"; import { isAutomationContext } from "../../github/context";
import type { PreparedContext } from "../../create-prompt/types"; import type { PreparedContext } from "../../create-prompt/types";
import { prepareMcpConfig } from "../../mcp/install-mcp-server";
/** /**
* Agent mode implementation. * Agent mode implementation.
@@ -39,7 +40,7 @@ export const agentMode: Mode = {
return false; return false;
}, },
async prepare({ context }: ModeOptions): Promise<ModeResult> { async prepare({ context, githubToken }: ModeOptions): Promise<ModeResult> {
// Agent mode handles automation events (workflow_dispatch, schedule) only // Agent mode handles automation events (workflow_dispatch, schedule) only
// Agent mode doesn't need to create prompt files here - handled by createPrompt // Agent mode doesn't need to create prompt files here - handled by createPrompt
@@ -67,26 +68,21 @@ export const agentMode: Mode = {
core.exportVariable("INPUT_ALLOWED_TOOLS", allowedTools.join(",")); core.exportVariable("INPUT_ALLOWED_TOOLS", allowedTools.join(","));
core.exportVariable("INPUT_DISALLOWED_TOOLS", disallowedTools.join(",")); core.exportVariable("INPUT_DISALLOWED_TOOLS", disallowedTools.join(","));
// Agent mode uses a minimal MCP configuration // Get MCP configuration using the same setup as other modes
// We don't need comment servers or PR-specific tools for automation
const mcpConfig: any = {
mcpServers: {},
};
// Add user-provided additional MCP config if any
const additionalMcpConfig = process.env.MCP_CONFIG || ""; const additionalMcpConfig = process.env.MCP_CONFIG || "";
if (additionalMcpConfig.trim()) { const mcpConfig = await prepareMcpConfig({
try { githubToken,
const additional = JSON.parse(additionalMcpConfig); owner: context.repository.owner,
if (additional && typeof additional === "object") { repo: context.repository.repo,
Object.assign(mcpConfig, additional); branch: "", // Agent mode doesn't use branches
} baseBranch: "",
} catch (error) { additionalMcpConfig,
core.warning(`Failed to parse additional MCP config: ${error}`); claudeCommentId: undefined, // Agent mode doesn't track comments
} allowedTools: [...baseTools, ...context.inputs.allowedTools],
} context,
});
core.setOutput("mcp_config", JSON.stringify(mcpConfig)); core.setOutput("mcp_config", mcpConfig);
return { return {
commentId: undefined, commentId: undefined,
@@ -95,7 +91,7 @@ export const agentMode: Mode = {
currentBranch: "", currentBranch: "",
claudeBranch: undefined, claudeBranch: undefined,
}, },
mcpConfig: JSON.stringify(mcpConfig), mcpConfig: mcpConfig,
}; };
}, },