mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 23:14: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,
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user