mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
- Add error field to MCP error responses to fix 'undefined' errors - Add REPO_DIR environment variable to fix file path resolution - Use GITHUB_WORKSPACE for correct repository directory - Simplify path processing logic in commit_files tool This fixes the issue where mcp__github_file_ops__commit_files would fail with 'Error calling tool commit_files: undefined' by ensuring error messages are properly formatted and files are read from the correct directory.
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import * as core from "@actions/core";
|
|
|
|
export async function prepareMcpConfig(
|
|
githubToken: string,
|
|
owner: string,
|
|
repo: string,
|
|
branch: string,
|
|
): Promise<string> {
|
|
try {
|
|
const mcpConfig = {
|
|
mcpServers: {
|
|
github: {
|
|
command: "docker",
|
|
args: [
|
|
"run",
|
|
"-i",
|
|
"--rm",
|
|
"-e",
|
|
"GITHUB_PERSONAL_ACCESS_TOKEN",
|
|
"ghcr.io/anthropics/github-mcp-server:sha-7382253",
|
|
],
|
|
env: {
|
|
GITHUB_PERSONAL_ACCESS_TOKEN: githubToken,
|
|
},
|
|
},
|
|
github_file_ops: {
|
|
command: "bun",
|
|
args: [
|
|
"run",
|
|
`${process.env.GITHUB_ACTION_PATH}/src/mcp/github-file-ops-server.ts`,
|
|
],
|
|
env: {
|
|
GITHUB_TOKEN: githubToken,
|
|
REPO_OWNER: owner,
|
|
REPO_NAME: repo,
|
|
BRANCH_NAME: branch,
|
|
REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd(), // Use GitHub workspace directory
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
return JSON.stringify(mcpConfig, null, 2);
|
|
} catch (error) {
|
|
core.setFailed(`Install MCP server failed with error: ${error}`);
|
|
process.exit(1);
|
|
}
|
|
}
|