mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 06:54:13 +08:00
Compare commits
5 Commits
v1.0.25
...
km/add-mcp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
340104d9cf | ||
|
|
9abdfa8a3a | ||
|
|
6c5d11c8c3 | ||
|
|
106183c4c0 | ||
|
|
7cc3cff20b |
@@ -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",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user