Skip to content

fix: use mcp-scripts for traffic API auth#30

Merged
DanWahlin merged 1 commit intomainfrom
feature/traffic-updater-mcp-script
Mar 31, 2026
Merged

fix: use mcp-scripts for traffic API auth#30
DanWahlin merged 1 commit intomainfrom
feature/traffic-updater-mcp-script

Conversation

@DanWahlin
Copy link
Copy Markdown
Collaborator

Summary

Replaces the previous approaches (manual lock file edits, sandbox.agent.env) with the proper mcp-scripts mechanism for passing the traffic API token.

What changed

  • Added mcp-scripts.fetch-traffic — a shell tool that runs gh api repos/$GITHUB_REPOSITORY/traffic/views outside the sandbox, with GH_TOKEN set from GH_AW_GITHUB_TOKEN
  • Removed sandbox.agent.env and strict: false — no longer needed
  • Removed gh from bash tools — the agent calls the MCP script instead of gh directly
  • Updated Step 2 — instructions now tell the agent to call the fetch-traffic tool

Why

The AWF sandbox explicitly excludes security-sensitive env vars (GH_TOKEN, COPILOT_GITHUB_TOKEN, etc.) via --exclude-env. MCP scripts run on the runner host outside the sandbox, so they can safely access secrets.

Replace sandbox.agent.env approach with mcp-scripts tool.
The fetch-traffic MCP script runs outside the sandbox with
GH_AW_GITHUB_TOKEN, bypassing the sandbox's token exclusion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 31, 2026 21:16
Copy link
Copy Markdown
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.

Pull request overview

Updates the Traffic Updater agentic workflow to fetch GitHub Traffic API data via a new mcp-scripts tool (executed outside the AWF sandbox) so the workflow can use the traffic API token without manual lockfile edits or relying on sandboxed env injection.

Changes:

  • Add mcp-scripts.fetch-traffic tool that calls gh api repos/$GITHUB_REPOSITORY/traffic/views with GH_TOKEN sourced from secrets.GH_AW_GITHUB_TOKEN.
  • Remove gh from the agent’s allowed bash tools and update Step 2 instructions to call the MCP tool instead.
  • Extend the compiled workflow to start an MCP Scripts HTTP server, register it with the MCP gateway, and parse/upload MCP Scripts logs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/traffic-updater.md Defines the new mcp-scripts.fetch-traffic tool and updates instructions to use it.
.github/workflows/traffic-updater.lock.yml Compiled workflow updates to run the MCP Scripts server, wire it into the MCP gateway, and adjust sandbox/tool allowlists accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +484 to +489
mkdir -p ${RUNNER_TEMP}/gh-aw/mcp-scripts/logs
cat > ${RUNNER_TEMP}/gh-aw/mcp-scripts/tools.json << 'GH_AW_MCP_SCRIPTS_TOOLS_ea355407aff34b08_EOF'
{
"serverName": "mcpscripts",
"version": "1.0.0",
"logDir": "${RUNNER_TEMP}/gh-aw/mcp-scripts/logs",
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

The generated mcp-scripts server writes logs under ${RUNNER_TEMP}/gh-aw/mcp-scripts/logs (see tools.json logDir), but the artifact upload later collects /tmp/gh-aw/mcp-scripts/logs/. As-is, the uploaded artifact path will likely be empty/missing. Align the server logDir and created directory with the artifact path (or update the artifact path to upload from ${RUNNER_TEMP}) so MCP scripts logs are actually captured.

Suggested change
mkdir -p ${RUNNER_TEMP}/gh-aw/mcp-scripts/logs
cat > ${RUNNER_TEMP}/gh-aw/mcp-scripts/tools.json << 'GH_AW_MCP_SCRIPTS_TOOLS_ea355407aff34b08_EOF'
{
"serverName": "mcpscripts",
"version": "1.0.0",
"logDir": "${RUNNER_TEMP}/gh-aw/mcp-scripts/logs",
mkdir -p /tmp/gh-aw/mcp-scripts/logs
cat > ${RUNNER_TEMP}/gh-aw/mcp-scripts/tools.json << 'GH_AW_MCP_SCRIPTS_TOOLS_ea355407aff34b08_EOF'
{
"serverName": "mcpscripts",
"version": "1.0.0",
"logDir": "/tmp/gh-aw/mcp-scripts/logs",

Copilot uses AI. Check for mistakes.
startHttpServer(configPath, {
port: port,
stateless: true,
logDir: "${RUNNER_TEMP}/gh-aw/mcp-scripts/logs"
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

In the generated mcp-server.cjs, apiKey is read from GH_AW_MCP_SCRIPTS_API_KEY but never used/passed into startHttpServer. If the HTTP server is supposed to enforce the Authorization header configured in the MCP gateway, wire this API key into the server options (or remove the unused key generation/header to avoid a false sense of authentication).

Suggested change
logDir: "${RUNNER_TEMP}/gh-aw/mcp-scripts/logs"
logDir: "${RUNNER_TEMP}/gh-aw/mcp-scripts/logs",
apiKey: apiKey

Copilot uses AI. Check for mistakes.

mkdir -p /home/runner/.copilot
cat << GH_AW_MCP_CONFIG_fd45b3cda1bf069e_EOF | bash ${RUNNER_TEMP}/gh-aw/actions/start_mcp_gateway.sh
cat << GH_AW_MCP_CONFIG_e84d94fd3aaff811_EOF | bash ${RUNNER_TEMP}/gh-aw/actions/start_mcp_gateway.sh
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

GH_TOKEN (traffic API token) is being passed into the MCP Gateway container via -e GH_TOKEN. The gateway config shown doesn’t appear to need this secret, and propagating it into an extra container increases exposure surface (and the chance of accidental logging). Prefer not passing GH_TOKEN to the MCP gateway unless it is strictly required.

Suggested change
cat << GH_AW_MCP_CONFIG_e84d94fd3aaff811_EOF | bash ${RUNNER_TEMP}/gh-aw/actions/start_mcp_gateway.sh
cat << GH_AW_MCP_CONFIG_e84d94fd3aaff811_EOF | env -u GH_TOKEN bash ${RUNNER_TEMP}/gh-aw/actions/start_mcp_gateway.sh

Copilot uses AI. Check for mistakes.
@DanWahlin DanWahlin merged commit 50f5834 into main Mar 31, 2026
7 checks passed
@DanWahlin DanWahlin deleted the feature/traffic-updater-mcp-script branch March 31, 2026 22:25
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.

2 participants