Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/patch-fix-gemini-mcp-config.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .github/workflows/smoke-gemini.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions actions/setup/sh/convert_gateway_config_gemini.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env bash
# Convert MCP Gateway Configuration to Gemini Format
# This script converts the gateway's standard HTTP-based MCP configuration
# to the JSON format expected by Gemini CLI (.gemini/settings.json)
#
# Gemini CLI reads MCP server configuration from settings.json files:
# - Global: ~/.gemini/settings.json
# - Project: .gemini/settings.json (used here)
#
# See: https://geminicli.com/docs/tools/mcp-server/

set -e

# Required environment variables:
# - MCP_GATEWAY_OUTPUT: Path to gateway output configuration file
# - MCP_GATEWAY_DOMAIN: Domain to use for MCP server URLs (e.g., host.docker.internal)
# - MCP_GATEWAY_PORT: Port for MCP gateway (e.g., 80)
# - GITHUB_WORKSPACE: Workspace directory for project-level settings

if [ -z "$MCP_GATEWAY_OUTPUT" ]; then
echo "ERROR: MCP_GATEWAY_OUTPUT environment variable is required"
exit 1
fi

if [ ! -f "$MCP_GATEWAY_OUTPUT" ]; then
echo "ERROR: Gateway output file not found: $MCP_GATEWAY_OUTPUT"
exit 1
fi

if [ -z "$MCP_GATEWAY_DOMAIN" ]; then
echo "ERROR: MCP_GATEWAY_DOMAIN environment variable is required"
exit 1
fi

if [ -z "$MCP_GATEWAY_PORT" ]; then
echo "ERROR: MCP_GATEWAY_PORT environment variable is required"
exit 1
fi

if [ -z "$GITHUB_WORKSPACE" ]; then
echo "ERROR: GITHUB_WORKSPACE environment variable is required"
exit 1
fi

echo "Converting gateway configuration to Gemini format..."
echo "Input: $MCP_GATEWAY_OUTPUT"
echo "Target domain: $MCP_GATEWAY_DOMAIN:$MCP_GATEWAY_PORT"

# Convert gateway output to Gemini settings.json format
# Gateway format:
# {
# "mcpServers": {
# "server-name": {
# "type": "http",
# "url": "http://domain:port/mcp/server-name",
# "headers": {
# "Authorization": "apiKey"
# }
# }
# }
# }
#
# Gemini settings.json format:
# {
# "mcpServers": {
# "server-name": {
# "url": "http://domain:port/mcp/server-name",
# "headers": {
# "Authorization": "apiKey"
# }
# }
# }
# }
#
# The main differences:
# 1. Remove "type" field (Gemini uses transport auto-detection from url/httpUrl)
# 2. Remove "tools" field (Copilot-specific)
# 3. URLs must use the correct domain (host.docker.internal) for container access

# Build the correct URL prefix using the configured domain and port
URL_PREFIX="http://${MCP_GATEWAY_DOMAIN}:${MCP_GATEWAY_PORT}"

# Create .gemini directory in the workspace (project-level settings)
GEMINI_SETTINGS_DIR="${GITHUB_WORKSPACE}/.gemini"
GEMINI_SETTINGS_FILE="${GEMINI_SETTINGS_DIR}/settings.json"

mkdir -p "$GEMINI_SETTINGS_DIR"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jq transformation correctly strips the type and tools fields that Gemini doesn't support. Consider adding a check for an empty mcpServers object in case the gateway output has no servers, to avoid writing an invalid settings file.

jq --arg urlPrefix "$URL_PREFIX" '
.mcpServers |= with_entries(
.value |= (
(del(.type)) |
(del(.tools)) |
# Fix the URL to use the correct domain
.url |= (. | sub("^http://[^/]+/mcp/"; $urlPrefix + "/mcp/"))
)
)
' "$MCP_GATEWAY_OUTPUT" > "$GEMINI_SETTINGS_FILE"

echo "Gemini configuration written to $GEMINI_SETTINGS_FILE"
echo ""
echo "Converted configuration:"
cat "$GEMINI_SETTINGS_FILE"
4 changes: 4 additions & 0 deletions actions/setup/sh/start_mcp_gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ case "$ENGINE_TYPE" in
echo "Using Claude converter..."
bash /opt/gh-aw/actions/convert_gateway_config_claude.sh
;;
gemini)
echo "Using Gemini converter..."
bash /opt/gh-aw/actions/convert_gateway_config_gemini.sh
;;
*)
echo "No agent-specific converter found for engine: $ENGINE_TYPE"
echo "Using gateway output directly"
Expand Down
11 changes: 5 additions & 6 deletions pkg/workflow/gemini_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@ func (e *GeminiEngine) GetExecutionSteps(workflowData *WorkflowData, logFile str
geminiArgs = append(geminiArgs, "--model", workflowData.EngineConfig.Model)
}

// Add MCP config if servers are present
if HasMCPServers(workflowData) {
geminiArgs = append(geminiArgs, "--mcp-config", "/tmp/gh-aw/mcp-config/mcp-servers.json")
}
// Gemini CLI reads MCP config from .gemini/settings.json (project-level)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix! Removing the --mcp-config flag and delegating config to .gemini/settings.json aligns with how Gemini CLI actually works. The comment clearly explains the intent.

// The conversion script (convert_gateway_config_gemini.sh) writes settings.json
// during the MCP setup step, so no --mcp-config flag is needed here.

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

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

// Add safe outputs env
Expand Down
5 changes: 3 additions & 2 deletions pkg/workflow/gemini_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ func TestGeminiEngineExecution(t *testing.T) {

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

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

t.Run("with custom command", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions tmp-smoke-test-22204310776.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Smoke test file for PR push test - Run 22204310776