mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
fix: only load GitHub MCP server when its tools are allowed (#124)
* fix: only load GitHub MCP server when its tools are allowed - Add allowedTools parameter to prepareMcpConfig - Check for mcp__github__ and mcp__github_file_ops__ tool prefixes - Only include MCP servers when their tools are in allowed_tools - Maintain backward compatibility when allowed_tools is not specified - Update tests to reflect the new conditional loading behavior This optimizes resource usage by not loading unnecessary MCP servers when their tools are not allowed in the configuration. Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com> * 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> * refactor: move allowedTools/disallowedTools parsing to parseGitHubContext - Change allowedTools and disallowedTools from string to string[] in ParsedGitHubContext type - Parse comma-separated environment variables into arrays in parseGitHubContext function - Update create-prompt and install-mcp-server to use pre-parsed arrays - Update all affected test files to use array syntax - Eliminate duplicate parsing logic across the codebase * style: apply prettier formatting --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
This commit is contained in:
@@ -652,7 +652,7 @@ describe("buildAllowedToolsString", () => {
|
||||
});
|
||||
|
||||
test("should append custom tools when provided", () => {
|
||||
const customTools = "Tool1,Tool2,Tool3";
|
||||
const customTools = ["Tool1", "Tool2", "Tool3"];
|
||||
const result = buildAllowedToolsString(customTools);
|
||||
|
||||
// Base tools should be present
|
||||
@@ -683,7 +683,7 @@ describe("buildDisallowedToolsString", () => {
|
||||
});
|
||||
|
||||
test("should append custom disallowed tools when provided", () => {
|
||||
const customDisallowedTools = "BadTool1,BadTool2";
|
||||
const customDisallowedTools = ["BadTool1", "BadTool2"];
|
||||
const result = buildDisallowedToolsString(customDisallowedTools);
|
||||
|
||||
// Base disallowed tools should be present
|
||||
@@ -701,8 +701,8 @@ describe("buildDisallowedToolsString", () => {
|
||||
});
|
||||
|
||||
test("should remove hardcoded disallowed tools if they are in allowed tools", () => {
|
||||
const customDisallowedTools = "BadTool1,BadTool2";
|
||||
const allowedTools = "WebSearch,SomeOtherTool";
|
||||
const customDisallowedTools = ["BadTool1", "BadTool2"];
|
||||
const allowedTools = ["WebSearch", "SomeOtherTool"];
|
||||
const result = buildDisallowedToolsString(
|
||||
customDisallowedTools,
|
||||
allowedTools,
|
||||
@@ -720,7 +720,7 @@ describe("buildDisallowedToolsString", () => {
|
||||
});
|
||||
|
||||
test("should remove all hardcoded disallowed tools if they are all in allowed tools", () => {
|
||||
const allowedTools = "WebSearch,WebFetch,SomeOtherTool";
|
||||
const allowedTools = ["WebSearch", "WebFetch", "SomeOtherTool"];
|
||||
const result = buildDisallowedToolsString(undefined, allowedTools);
|
||||
|
||||
// Both hardcoded disallowed tools should be removed
|
||||
@@ -732,8 +732,8 @@ describe("buildDisallowedToolsString", () => {
|
||||
});
|
||||
|
||||
test("should handle custom disallowed tools when all hardcoded tools are overridden", () => {
|
||||
const customDisallowedTools = "BadTool1,BadTool2";
|
||||
const allowedTools = "WebSearch,WebFetch";
|
||||
const customDisallowedTools = ["BadTool1", "BadTool2"];
|
||||
const allowedTools = ["WebSearch", "WebFetch"];
|
||||
const result = buildDisallowedToolsString(
|
||||
customDisallowedTools,
|
||||
allowedTools,
|
||||
|
||||
Reference in New Issue
Block a user