Skip to content

[Bug] MCP server loses environment variables on automatic restart after GitHub authentication #744

@andrearaponi

Description

@andrearaponi

Describe the bug

When Copilot CLI automatically restarts an MCP server after GitHub authentication, the environment variables defined in mcp-config.json are not passed to the restarted process.

This causes any MCP server relying on environment variables (e.g., for API tokens or configuration) to fail or crash immediately after the restart (approx. 5-10 seconds after initial startup)

Affected version

0.0.367 (and 0.0.368-2)

Steps to reproduce the behavior

  1. Configure a local MCP server in ~/.copilot/mcp-config.json that relies on environment variables (e.g., HELLO_VAR).
  2. Start Copilot CLI (or VS Code with Copilot).
  3. Observe the first startup logs: the environment variables are correctly present.
  4. Interact with Copilot to trigger GitHub MCP authentication.
  5. Wait for the automatic restart message: "GitHub MCP server configured after authentication".
  6. Observe the logs for the restarted process: the environment variables are missing (undefined).

Expected behavior

Environment variables defined in mcp-config.json should be consistently passed to the MCP server process on every startup, including automatic restarts triggered by the Copilot CLI lifecycle (e.g., after GitHub authentication).

debug-repro.js

[2025-12-09T19:21:26.047Z] [PID:61339] CHECK: HELLO_VAR=WORLD
[2025-12-09T19:21:26.051Z] [PID:61339] Server started
[2025-12-09T19:21:29.552Z] [PID:61416] CHECK: HELLO_VAR=MISSING
[2025-12-09T19:21:29.556Z] [PID:61416] Server started

The restarted process should have the same environment context as the initial process.

   "mcpServers":{
      "repro-test":{
         "type":"local",
         "command":"node",
         "tools":[
            "ping"
         ],
         "args":[
            "/absolute/path/to/debug-repro.js"
         ],
         "env":{
            "HELLO_VAR":"WORLD"
         }
      }
   }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions