fix: always load github_file_ops server regardless of allowed_tools

- Only apply conditional loading to the github MCP server
- Always load github_file_ops server as it contains essential tools
- Update tests to reflect this behavior

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
This commit is contained in:
claude[bot]
2025-06-04 01:06:00 +00:00
committed by Ashwin Bhat
parent b4a5fb3de6
commit 2c0d6b1a1e
2 changed files with 20 additions and 25 deletions

View File

@@ -32,9 +32,6 @@ export async function prepareMcpConfig(
const hasGitHubMcpTools = allowedToolsList.some((tool) => const hasGitHubMcpTools = allowedToolsList.some((tool) =>
tool.startsWith("mcp__github__"), tool.startsWith("mcp__github__"),
); );
const hasGitHubFileOpsTools = allowedToolsList.some((tool) =>
tool.startsWith("mcp__github_file_ops__"),
);
// Start with an empty servers object // Start with an empty servers object
const mcpServers: Record<string, any> = {}; const mcpServers: Record<string, any> = {};
@@ -59,26 +56,24 @@ export async function prepareMcpConfig(
// Always include github_file_ops server as it contains essential tools // Always include github_file_ops server as it contains essential tools
// (mcp__github_file_ops__commit_files, mcp__github_file_ops__update_claude_comment) // (mcp__github_file_ops__commit_files, mcp__github_file_ops__update_claude_comment)
// These are in the BASE_ALLOWED_TOOLS // These are in the BASE_ALLOWED_TOOLS and should always be available
if (hasGitHubFileOpsTools || !allowedTools) { mcpServers.github_file_ops = {
mcpServers.github_file_ops = { command: "bun",
command: "bun", args: [
args: [ "run",
"run", `${process.env.GITHUB_ACTION_PATH}/src/mcp/github-file-ops-server.ts`,
`${process.env.GITHUB_ACTION_PATH}/src/mcp/github-file-ops-server.ts`, ],
], env: {
env: { GITHUB_TOKEN: githubToken,
GITHUB_TOKEN: githubToken, REPO_OWNER: owner,
REPO_OWNER: owner, REPO_NAME: repo,
REPO_NAME: repo, BRANCH_NAME: branch,
BRANCH_NAME: branch, REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd(),
REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd(), ...(claudeCommentId && { CLAUDE_COMMENT_ID: claudeCommentId }),
...(claudeCommentId && { CLAUDE_COMMENT_ID: claudeCommentId }), GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || "",
GITHUB_EVENT_NAME: process.env.GITHUB_EVENT_NAME || "", IS_PR: process.env.IS_PR || "false",
IS_PR: process.env.IS_PR || "false", },
}, };
};
}
const baseMcpConfig = { const baseMcpConfig = {
mcpServers, mcpServers,

View File

@@ -81,7 +81,7 @@ describe("prepareMcpConfig", () => {
expect(parsed.mcpServers.github_file_ops).toBeDefined(); expect(parsed.mcpServers.github_file_ops).toBeDefined();
}); });
test("should not include any MCP servers when no GitHub tools are allowed", async () => { test("should include file_ops server even when no GitHub tools are allowed", async () => {
const result = await prepareMcpConfig({ const result = await prepareMcpConfig({
githubToken: "test-token", githubToken: "test-token",
owner: "test-owner", owner: "test-owner",
@@ -93,7 +93,7 @@ describe("prepareMcpConfig", () => {
const parsed = JSON.parse(result); const parsed = JSON.parse(result);
expect(parsed.mcpServers).toBeDefined(); expect(parsed.mcpServers).toBeDefined();
expect(parsed.mcpServers.github).not.toBeDefined(); expect(parsed.mcpServers.github).not.toBeDefined();
expect(parsed.mcpServers.github_file_ops).not.toBeDefined(); expect(parsed.mcpServers.github_file_ops).toBeDefined();
}); });
test("should return base config when additional config is empty string", async () => { test("should return base config when additional config is empty string", async () => {