mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
Simplify MCP configuration to use multiple --mcp-config flags
- Remove MCP config merging logic from prepareMcpConfig - Update agent and tag modes to pass multiple --mcp-config flags - Let Claude handle config merging natively through multiple flags - Fix TypeScript errors in test file This approach is cleaner and relies on Claude's built-in support for multiple --mcp-config flags instead of manual JSON merging.
This commit is contained in:
@@ -65,24 +65,37 @@ export const agentMode: Mode = {
|
||||
const currentBranch =
|
||||
process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || "main";
|
||||
|
||||
// Get MCP configuration with GitHub servers when requested
|
||||
const additionalMcpConfig = process.env.MCP_CONFIG || "";
|
||||
const mcpConfig = await prepareMcpConfig({
|
||||
// Get our GitHub MCP servers config
|
||||
const ourMcpConfig = await prepareMcpConfig({
|
||||
githubToken,
|
||||
owner: context.repository.owner,
|
||||
repo: context.repository.repo,
|
||||
branch: currentBranch,
|
||||
baseBranch: context.inputs.baseBranch || "main",
|
||||
additionalMcpConfig,
|
||||
claudeCommentId: undefined, // No tracking comment in agent mode
|
||||
allowedTools,
|
||||
context,
|
||||
});
|
||||
|
||||
// Build final claude_args
|
||||
const escapedMcpConfig = mcpConfig.replace(/'/g, "'\\''");
|
||||
const claudeArgs =
|
||||
`--mcp-config '${escapedMcpConfig}' ${userClaudeArgs}`.trim();
|
||||
// Build final claude_args with multiple --mcp-config flags
|
||||
let claudeArgs = "";
|
||||
|
||||
// Add our GitHub servers config if we have any
|
||||
const ourConfig = JSON.parse(ourMcpConfig);
|
||||
if (ourConfig.mcpServers && Object.keys(ourConfig.mcpServers).length > 0) {
|
||||
const escapedOurConfig = ourMcpConfig.replace(/'/g, "'\\''");
|
||||
claudeArgs = `--mcp-config '${escapedOurConfig}'`;
|
||||
}
|
||||
|
||||
// Add user's MCP_CONFIG env var as separate --mcp-config
|
||||
const userMcpConfig = process.env.MCP_CONFIG;
|
||||
if (userMcpConfig?.trim()) {
|
||||
const escapedUserConfig = userMcpConfig.replace(/'/g, "'\\''");
|
||||
claudeArgs = `${claudeArgs} --mcp-config '${escapedUserConfig}'`.trim();
|
||||
}
|
||||
|
||||
// Append user's claude_args (which may have more --mcp-config flags)
|
||||
claudeArgs = `${claudeArgs} ${userClaudeArgs}`.trim();
|
||||
|
||||
core.setOutput("claude_args", claudeArgs);
|
||||
|
||||
@@ -93,7 +106,7 @@ export const agentMode: Mode = {
|
||||
currentBranch,
|
||||
claudeBranch: undefined,
|
||||
},
|
||||
mcpConfig,
|
||||
mcpConfig: ourMcpConfig,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
@@ -100,15 +100,13 @@ export const tagMode: Mode = {
|
||||
|
||||
await createPrompt(tagMode, modeContext, githubData, context);
|
||||
|
||||
// Get MCP configuration
|
||||
const additionalMcpConfig = process.env.MCP_CONFIG || "";
|
||||
const mcpConfig = await prepareMcpConfig({
|
||||
// Get our GitHub MCP servers configuration
|
||||
const ourMcpConfig = await prepareMcpConfig({
|
||||
githubToken,
|
||||
owner: context.repository.owner,
|
||||
repo: context.repository.repo,
|
||||
branch: branchInfo.claudeBranch || branchInfo.currentBranch,
|
||||
baseBranch: branchInfo.baseBranch,
|
||||
additionalMcpConfig,
|
||||
claudeCommentId: commentId.toString(),
|
||||
allowedTools: [],
|
||||
context,
|
||||
@@ -150,14 +148,26 @@ export const tagMode: Mode = {
|
||||
|
||||
const userClaudeArgs = process.env.CLAUDE_ARGS || "";
|
||||
|
||||
// Build complete claude_args with MCP config (as JSON string), tools, and user args
|
||||
// Note: Once Claude supports multiple --mcp-config flags, we can pass as file path
|
||||
// Escape single quotes in JSON to prevent shell injection
|
||||
const escapedMcpConfig = mcpConfig.replace(/'/g, "'\\''");
|
||||
let claudeArgs = `--mcp-config '${escapedMcpConfig}' `;
|
||||
claudeArgs += `--allowedTools "${tagModeTools.join(",")}" `;
|
||||
// Build complete claude_args with multiple --mcp-config flags
|
||||
let claudeArgs = "";
|
||||
|
||||
// Add our GitHub servers config
|
||||
const escapedOurConfig = ourMcpConfig.replace(/'/g, "'\\''");
|
||||
claudeArgs = `--mcp-config '${escapedOurConfig}'`;
|
||||
|
||||
// Add user's MCP_CONFIG env var as separate --mcp-config
|
||||
const userMcpConfig = process.env.MCP_CONFIG;
|
||||
if (userMcpConfig?.trim()) {
|
||||
const escapedUserConfig = userMcpConfig.replace(/'/g, "'\\''");
|
||||
claudeArgs = `${claudeArgs} --mcp-config '${escapedUserConfig}'`;
|
||||
}
|
||||
|
||||
// Add required tools for tag mode
|
||||
claudeArgs += ` --allowedTools "${tagModeTools.join(",")}"`;
|
||||
|
||||
// Append user's claude_args (which may have more --mcp-config flags)
|
||||
if (userClaudeArgs) {
|
||||
claudeArgs += userClaudeArgs;
|
||||
claudeArgs += ` ${userClaudeArgs}`;
|
||||
}
|
||||
|
||||
core.setOutput("claude_args", claudeArgs.trim());
|
||||
@@ -165,7 +175,7 @@ export const tagMode: Mode = {
|
||||
return {
|
||||
commentId,
|
||||
branchInfo,
|
||||
mcpConfig,
|
||||
mcpConfig: ourMcpConfig,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user