feat: add mcp_config input that merges with existing mcp server

- Add mcp_config input parameter to action.yml 
- Modify prepareMcpConfig() to accept and merge additional config
- Provided config overrides built-in servers in case of naming collisions
- Pass MCP_CONFIG environment variable from action to prepare step

Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com>
This commit is contained in:
claude[bot]
2025-05-30 14:30:04 +00:00
committed by GitHub
parent 8da47815ec
commit 850023f24a
3 changed files with 38 additions and 2 deletions

View File

@@ -39,6 +39,10 @@ inputs:
description: "Direct instruction for Claude (bypasses normal trigger detection)" description: "Direct instruction for Claude (bypasses normal trigger detection)"
required: false required: false
default: "" default: ""
mcp_config:
description: "Additional MCP configuration (JSON string) that merges with the built-in GitHub MCP servers"
required: false
default: ""
# Auth configuration # Auth configuration
anthropic_api_key: anthropic_api_key:
@@ -92,6 +96,7 @@ runs:
ALLOWED_TOOLS: ${{ inputs.allowed_tools }} ALLOWED_TOOLS: ${{ inputs.allowed_tools }}
CUSTOM_INSTRUCTIONS: ${{ inputs.custom_instructions }} CUSTOM_INSTRUCTIONS: ${{ inputs.custom_instructions }}
DIRECT_PROMPT: ${{ inputs.direct_prompt }} DIRECT_PROMPT: ${{ inputs.direct_prompt }}
MCP_CONFIG: ${{ inputs.mcp_config }}
OVERRIDE_GITHUB_TOKEN: ${{ inputs.github_token }} OVERRIDE_GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_RUN_ID: ${{ github.run_id }} GITHUB_RUN_ID: ${{ github.run_id }}

View File

@@ -84,11 +84,13 @@ async function run() {
); );
// Step 11: Get MCP configuration // Step 11: Get MCP configuration
const additionalMcpConfig = process.env.MCP_CONFIG || "";
const mcpConfig = await prepareMcpConfig( const mcpConfig = await prepareMcpConfig(
githubToken, githubToken,
context.repository.owner, context.repository.owner,
context.repository.repo, context.repository.repo,
branchInfo.currentBranch, branchInfo.currentBranch,
additionalMcpConfig,
); );
core.setOutput("mcp_config", mcpConfig); core.setOutput("mcp_config", mcpConfig);
} catch (error) { } catch (error) {

View File

@@ -5,9 +5,10 @@ export async function prepareMcpConfig(
owner: string, owner: string,
repo: string, repo: string,
branch: string, branch: string,
additionalMcpConfig?: string,
): Promise<string> { ): Promise<string> {
try { try {
const mcpConfig = { const baseMcpConfig = {
mcpServers: { mcpServers: {
github: { github: {
command: "docker", command: "docker",
@@ -40,7 +41,35 @@ export async function prepareMcpConfig(
}, },
}; };
return JSON.stringify(mcpConfig, null, 2); // Merge with additional MCP config if provided
if (additionalMcpConfig && additionalMcpConfig.trim()) {
try {
const additionalConfig = JSON.parse(additionalMcpConfig);
// Merge mcpServers objects, with additional config overriding base config
if (additionalConfig.mcpServers) {
baseMcpConfig.mcpServers = {
...baseMcpConfig.mcpServers,
...additionalConfig.mcpServers,
};
}
// Merge any other top-level properties from additional config
const mergedConfig = {
...baseMcpConfig,
...additionalConfig,
mcpServers: baseMcpConfig.mcpServers, // Ensure mcpServers uses the merged version
};
return JSON.stringify(mergedConfig, null, 2);
} catch (parseError) {
core.warning(
`Failed to parse additional MCP config: ${parseError}. Using base config only.`,
);
}
}
return JSON.stringify(baseMcpConfig, null, 2);
} catch (error) { } catch (error) {
core.setFailed(`Install MCP server failed with error: ${error}`); core.setFailed(`Install MCP server failed with error: ${error}`);
process.exit(1); process.exit(1);