Skip to content

fix: remove shell quoting (@Q) from gateway-api-key step output#18943

Merged
pelikhan merged 2 commits intomainfrom
copilot/fix-mcp-gateway-close-teardown
Mar 1, 2026
Merged

fix: remove shell quoting (@Q) from gateway-api-key step output#18943
pelikhan merged 2 commits intomainfrom
copilot/fix-mcp-gateway-close-teardown

Conversation

Copy link
Contributor

Copilot AI commented Feb 28, 2026

MCP gateway /close teardown fails with Authentication failed: invalid API key because ${MCP_GATEWAY_API_KEY@Q} writes a shell-quoted value (e.g., 'abc123') to GITHUB_OUTPUT. stop_mcp_gateway.sh then sends that quoted string verbatim as the Authorization header, which doesn't match the actual key.

Change

  • actions/setup/sh/start_mcp_gateway.sh: Remove @Q from the gateway-api-key output so the raw key is written to GITHUB_OUTPUT.
# Before — writes 'abc123' (with quotes) to GITHUB_OUTPUT
echo "gateway-api-key=${MCP_GATEWAY_API_KEY@Q}"

# After — writes abc123
echo "gateway-api-key=${MCP_GATEWAY_API_KEY}"

@Q is appropriate when a value will be re-evaluated by a shell; writing to GITHUB_OUTPUT requires the raw value.

Original prompt

This section details on the original issue you should resolve

<issue_title>MCP gateway /close teardown fails with invalid API key (gateway-api-key output quoted)</issue_title>
<issue_description>## Summary
gh aw Codex workflows can fail during teardown when calling MCP gateway /close with:

Authentication failed: invalid API key, path=/close

This causes the main agent step to fail and can skip downstream safe-output processing.

Observed Runs

From aaronspindler/aaronspindler.com:

All three fail at the end of Execute Codex / teardown, with /close auth failure.

Likely Cause

In actions/setup/sh/start_mcp_gateway.sh, gateway API key output is written with shell quoting:

echo "gateway-api-key=${MCP_GATEWAY_API_KEY@Q}"

Later, stop_mcp_gateway.sh uses the output directly as Authorization header:

-H "Authorization: ${MCP_GATEWAY_API_KEY}"

If the output includes shell quotes, /close sees a mismatched key and returns invalid API key.

Workaround (local)

We mitigated by patching start_mcp_gateway.sh in a pre-agent custom step to remove @Q from the emitted output.

Expected

stop_mcp_gateway.sh should authenticate successfully against /close with the key emitted by start_mcp_gateway.sh without requiring local patching.

Environment

  • gh aw CLI: v0.50.5 and v0.50.6
  • Engine: codex
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ay.sh

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix MCP gateway close teardown failing with invalid API key fix: remove shell quoting (@Q) from gateway-api-key step output Feb 28, 2026
@pelikhan pelikhan marked this pull request as ready for review February 28, 2026 23:58
Copilot AI review requested due to automatic review settings February 28, 2026 23:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pelikhan pelikhan merged commit c4e1922 into main Mar 1, 2026
104 checks passed
@pelikhan pelikhan deleted the copilot/fix-mcp-gateway-close-teardown branch March 1, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP gateway /close teardown fails with invalid API key (gateway-api-key output quoted)

3 participants