Skip to content

Commit a280a6b

Browse files
CopilotMossakaclaudeCopilotGH-AW Smoke Test
authored
fix: Gemini engine uses .gemini/settings.json instead of unsupported --mcp-config flag (#16938)
* Initial plan * fix: Gemini engine uses .gemini/settings.json instead of unsupported --mcp-config flag Remove --mcp-config CLI flag from Gemini engine execution (Gemini CLI does not support it). Instead, add convert_gateway_config_gemini.sh that writes MCP server configuration to .gemini/settings.json (project-level), which is the format Gemini CLI expects. Update start_mcp_gateway.sh to route Gemini engine to the new conversion script. Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com> * fix: recompile smoke-gemini workflow with --mcp-config flag removed Recompiled with dev build. The lock file now uses .gemini/settings.json for MCP config instead of the unsupported --mcp-config CLI flag. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add changeset [skip-ci] * test: Add smoke test file for run 22204310776 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com> Co-authored-by: Jiaxiao (mossaka) Zhou <duibao55328@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot <copilot@github.com> Co-authored-by: GH-AW Smoke Test <gh-aw-smoke@github.com>
1 parent ccbec75 commit a280a6b

7 files changed

Lines changed: 123 additions & 10 deletions

File tree

.changeset/patch-fix-gemini-mcp-config.md

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/smoke-gemini.lock.yml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env bash
2+
# Convert MCP Gateway Configuration to Gemini Format
3+
# This script converts the gateway's standard HTTP-based MCP configuration
4+
# to the JSON format expected by Gemini CLI (.gemini/settings.json)
5+
#
6+
# Gemini CLI reads MCP server configuration from settings.json files:
7+
# - Global: ~/.gemini/settings.json
8+
# - Project: .gemini/settings.json (used here)
9+
#
10+
# See: https://geminicli.com/docs/tools/mcp-server/
11+
12+
set -e
13+
14+
# Required environment variables:
15+
# - MCP_GATEWAY_OUTPUT: Path to gateway output configuration file
16+
# - MCP_GATEWAY_DOMAIN: Domain to use for MCP server URLs (e.g., host.docker.internal)
17+
# - MCP_GATEWAY_PORT: Port for MCP gateway (e.g., 80)
18+
# - GITHUB_WORKSPACE: Workspace directory for project-level settings
19+
20+
if [ -z "$MCP_GATEWAY_OUTPUT" ]; then
21+
echo "ERROR: MCP_GATEWAY_OUTPUT environment variable is required"
22+
exit 1
23+
fi
24+
25+
if [ ! -f "$MCP_GATEWAY_OUTPUT" ]; then
26+
echo "ERROR: Gateway output file not found: $MCP_GATEWAY_OUTPUT"
27+
exit 1
28+
fi
29+
30+
if [ -z "$MCP_GATEWAY_DOMAIN" ]; then
31+
echo "ERROR: MCP_GATEWAY_DOMAIN environment variable is required"
32+
exit 1
33+
fi
34+
35+
if [ -z "$MCP_GATEWAY_PORT" ]; then
36+
echo "ERROR: MCP_GATEWAY_PORT environment variable is required"
37+
exit 1
38+
fi
39+
40+
if [ -z "$GITHUB_WORKSPACE" ]; then
41+
echo "ERROR: GITHUB_WORKSPACE environment variable is required"
42+
exit 1
43+
fi
44+
45+
echo "Converting gateway configuration to Gemini format..."
46+
echo "Input: $MCP_GATEWAY_OUTPUT"
47+
echo "Target domain: $MCP_GATEWAY_DOMAIN:$MCP_GATEWAY_PORT"
48+
49+
# Convert gateway output to Gemini settings.json format
50+
# Gateway format:
51+
# {
52+
# "mcpServers": {
53+
# "server-name": {
54+
# "type": "http",
55+
# "url": "http://domain:port/mcp/server-name",
56+
# "headers": {
57+
# "Authorization": "apiKey"
58+
# }
59+
# }
60+
# }
61+
# }
62+
#
63+
# Gemini settings.json format:
64+
# {
65+
# "mcpServers": {
66+
# "server-name": {
67+
# "url": "http://domain:port/mcp/server-name",
68+
# "headers": {
69+
# "Authorization": "apiKey"
70+
# }
71+
# }
72+
# }
73+
# }
74+
#
75+
# The main differences:
76+
# 1. Remove "type" field (Gemini uses transport auto-detection from url/httpUrl)
77+
# 2. Remove "tools" field (Copilot-specific)
78+
# 3. URLs must use the correct domain (host.docker.internal) for container access
79+
80+
# Build the correct URL prefix using the configured domain and port
81+
URL_PREFIX="http://${MCP_GATEWAY_DOMAIN}:${MCP_GATEWAY_PORT}"
82+
83+
# Create .gemini directory in the workspace (project-level settings)
84+
GEMINI_SETTINGS_DIR="${GITHUB_WORKSPACE}/.gemini"
85+
GEMINI_SETTINGS_FILE="${GEMINI_SETTINGS_DIR}/settings.json"
86+
87+
mkdir -p "$GEMINI_SETTINGS_DIR"
88+
89+
jq --arg urlPrefix "$URL_PREFIX" '
90+
.mcpServers |= with_entries(
91+
.value |= (
92+
(del(.type)) |
93+
(del(.tools)) |
94+
# Fix the URL to use the correct domain
95+
.url |= (. | sub("^http://[^/]+/mcp/"; $urlPrefix + "/mcp/"))
96+
)
97+
)
98+
' "$MCP_GATEWAY_OUTPUT" > "$GEMINI_SETTINGS_FILE"
99+
100+
echo "Gemini configuration written to $GEMINI_SETTINGS_FILE"
101+
echo ""
102+
echo "Converted configuration:"
103+
cat "$GEMINI_SETTINGS_FILE"

actions/setup/sh/start_mcp_gateway.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,10 @@ case "$ENGINE_TYPE" in
365365
echo "Using Claude converter..."
366366
bash /opt/gh-aw/actions/convert_gateway_config_claude.sh
367367
;;
368+
gemini)
369+
echo "Using Gemini converter..."
370+
bash /opt/gh-aw/actions/convert_gateway_config_gemini.sh
371+
;;
368372
*)
369373
echo "No agent-specific converter found for engine: $ENGINE_TYPE"
370374
echo "Using gateway output directly"

pkg/workflow/gemini_engine.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ func (e *GeminiEngine) GetExecutionSteps(workflowData *WorkflowData, logFile str
172172
geminiArgs = append(geminiArgs, "--model", workflowData.EngineConfig.Model)
173173
}
174174

175-
// Add MCP config if servers are present
176-
if HasMCPServers(workflowData) {
177-
geminiArgs = append(geminiArgs, "--mcp-config", "/tmp/gh-aw/mcp-config/mcp-servers.json")
178-
}
175+
// Gemini CLI reads MCP config from .gemini/settings.json (project-level)
176+
// The conversion script (convert_gateway_config_gemini.sh) writes settings.json
177+
// during the MCP setup step, so no --mcp-config flag is needed here.
179178

180179
// Add headless mode with JSON output
181180
geminiArgs = append(geminiArgs, "--output-format", "json")
@@ -225,9 +224,9 @@ func (e *GeminiEngine) GetExecutionSteps(workflowData *WorkflowData, logFile str
225224
"GITHUB_WORKSPACE": "${{ github.workspace }}",
226225
}
227226

228-
// Add MCP config env var if needed
227+
// Add MCP config env var if needed (points to .gemini/settings.json for Gemini)
229228
if HasMCPServers(workflowData) {
230-
env["GH_AW_MCP_CONFIG"] = "/tmp/gh-aw/mcp-config/mcp-servers.json"
229+
env["GH_AW_MCP_CONFIG"] = "${{ github.workspace }}/.gemini/settings.json"
231230
}
232231

233232
// Add safe outputs env

pkg/workflow/gemini_engine_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ func TestGeminiEngineExecution(t *testing.T) {
189189

190190
stepContent := strings.Join(steps[0], "\n")
191191

192-
assert.Contains(t, stepContent, "--mcp-config /tmp/gh-aw/mcp-config/mcp-servers.json", "Should include MCP config")
193-
assert.Contains(t, stepContent, "GH_AW_MCP_CONFIG: /tmp/gh-aw/mcp-config/mcp-servers.json", "Should set MCP config env var")
192+
// Gemini CLI reads MCP config from .gemini/settings.json, not --mcp-config flag
193+
assert.NotContains(t, stepContent, "--mcp-config", "Should NOT include --mcp-config flag (Gemini CLI does not support it)")
194+
assert.Contains(t, stepContent, "GH_AW_MCP_CONFIG: ${{ github.workspace }}/.gemini/settings.json", "Should set MCP config env var to Gemini settings.json path")
194195
})
195196

196197
t.Run("with custom command", func(t *testing.T) {

tmp-smoke-test-22204310776.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Smoke test file for PR push test - Run 22204310776

0 commit comments

Comments
 (0)