-
Notifications
You must be signed in to change notification settings - Fork 245
fix: Gemini engine uses .gemini/settings.json instead of unsupported --mcp-config flag #16938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ecd125b
8071e54
7a19e37
dcd4d8b
44ed384
9e7ee95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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" | ||
|
|
||
| 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" | ||
github-actions[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good fix! Removing the |
||
| // 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") | ||
|
|
@@ -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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Smoke test file for PR push test - Run 22204310776 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
jqtransformation correctly strips thetypeandtoolsfields that Gemini doesn't support. Consider adding a check for an emptymcpServersobject in case the gateway output has no servers, to avoid writing an invalid settings file.