Skip to content

Support of ${} environment variable in mcp-config #1232

Closed

Description

@miadisabelle

Describe the feature or problem you'd like to solve

Support of environment variable in MCP-Config

Proposed solution

Simply supports that. It is major I think because it forces us to add our secrets into the MCP config (which I am not a fan of ;) )

best regards

Example prompts or workflows

in $HOME/.copilot/mcp-config.json

	   "${COPI_COAIAN_MCP_NAME}": {
		   "type": "local",
         "command": "npx",
	 "tools": [ "*" ],
         "args": ["-y", "${CNCV}", "--memory-path", "${COPI_COAIAN_MCP_MF}"]
    }
{
  "mcpServers": {
    "github_mcp": {
      "command": "npx",
      "args": [
              "-y",
              "@modelcontextprotocol/server-github"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"
      }
    }
  }
}

Additional context

  • Gemini-cli, claude-code supports that...

Activity

  1. stefanbosak commented on Feb 3, 2026

    @stefanbosak

    working:

    "mcpServers": {
    "postgres": {
    "tools": [
    ""
    ],
    "type": "local",
    "command": "/usr/local/bin/toolbox",
    "args": [
    "--prebuilt",
    "postgres",
    "--stdio"
    ],
    "env": {
    "POSTGRES_HOST": "${POSTGRES_HOST}",
    "POSTGRES_PORT": "{POSTGRES_PORT}",
    "POSTGRES_DATABASE": "${POSTGRES_DATABASE}",
    "POSTGRES_USER": "${POSTGRES_USER}",
    "POSTGRES_PASSWORD": "${POSTGRES_PASSWORD}"
    }
    },
    "ref": {
    "tools": [
    "
    "
    ],
    "type": "http",
    "url": "https://api.ref.tools/mcp",
    "headers": {
    "x-ref-api-key": "${REF_API_KEY}"
    }
    }
    }

    does not working:
    "mcpServers": {
    "graylog-tst": {
    "tools": [
    "*"
    ],
    "type": "http",
    "url": "https://graylog.tst.domain.tld/api/mcp",
    "headers": {
    "Authorization": "Basic ${GRAYLOG_TST_TOKEN}"
    }
    }
    }

    Notes:

    • environment variables: consistent support to pass them for any attributes within MCP configuration
    • mcpServer configurations in general: consistent support to add MCP config as JSON on-demand within skills or agents/skills (very valuable)
  2. therealvio commented on Mar 1, 2026

    @therealvio

    @stefanbosak I am not getting this to work with Context7 using copilot 0.0.420. I can verify that inserting the credential as-is without the string expansion works, but when I use string expansion, copilot returns:

    I'm unable to access the Context7 MCP due to an API key issue. Please provide a valid Context7 API
    key, or let me know if you'd like me to fetch the Renovate documentation directly from the web.
    

    I am using direnv to set the environment variable, and I can confirm it loads when I run echo $CONTEXT7_API_KEY

    My .mcp.json config (support has been added for this file location) is the following:

    {
      "mcpServers": {
        "context7": {
          "type": "http",
          "url": "https://mcp.context7.com/mcp",
          "headers": {
            "CONTEXT7_API_KEY": "${CONTEXT7_API_KEY}"
          },
          "tools": ["*"]
        }
      }
    }

    Does anyone have any idea if this is actually supported?

  3. stefanbosak commented on Mar 6, 2026

    @stefanbosak

    Hi @therealvio ,

    CONTEXT7_API_KEY use case is just example and it is working as stated.

    See more details regarding:
    "mcpServers": {
    "graylog-tst": {
    "tools": [
    "*"
    ],
    "type": "http",
    "url": "https://graylog.tst.domain.tld/api/mcp",
    "headers": {
    "Authorization": "Basic ${GRAYLOG_TST_TOKEN}"
    }
    }
    }

    which means passing environment variable into related inner attribute in structure such as headers entities.
    Would be great is passing of environment variables would be supported in general not tight to specific use cases only or depth of given element in structure especially including agent configuration like which also does not work - example .copilot/agents/graylog-tst.agent.md (this is really valuable within agent definitions):

    name: graylog-tst
    description: "Tools for interaction with graylog testing environment. Use when asked about log analysis, searching logs, or graylog in the test/staging environment."
    mcp-servers:
    graylog-tst:
    type: http
    url: https://graylog.tst.domain.tld/api/mcp
    headers:
    Authorization: "Basic ${GRAYLOG_TST_TOKEN}"
    tools:
    - "*"

    Use the graylog-tst MCP server tools to search and analyze logs in the Graylog testing environment.

    Search logs, create streams, manage alerts. Use the #graylog-tst skill for detailed guidance.

    Thank you.

  4. nick-pape commented on Mar 6, 2026

    @nick-pape

    ${workspaceFolder} not expanded when reading .vscode/mcp.json

    Since v0.0.407 added .vscode/mcp.json support, Copilot CLI reads the file but does not expand ${workspaceFolder} — the most commonly used variable in workspace MCP configs. The literal string ${workspaceFolder} gets treated as a relative path segment, so every server that uses it in args fails immediately:

    Error: Cannot find module '/workspaces/my-repo/${workspaceFolder}/common/scripts/my-mcp-server.js'
    

    This is particularly painful in repos that also use Copilot CLI plugins (which Copilot CLI and Claude Code can read, but VS Code Copilot cannot). The result:

    1. Copilot CLI reads .vscode/mcp.json → all servers fail because ${workspaceFolder} isn't expanded
    2. The same servers are also available via a plugin (which works correctly in Copilot CLI)
    3. Users see every MCP server listed twice — one failing copy from .vscode/mcp.json and one working copy from the plugin
    4. There's no way to tell Copilot CLI to skip .vscode/mcp.json

    Expected behavior: Either fully expand VS Code variables (${workspaceFolder}, ${input:...}, etc.) when reading .vscode/mcp.json, or provide an opt-out so repos that use plugins aren't forced into a broken state.

    Environment: Copilot CLI v0.0.423, running in GitHub Codespaces. The .vscode/mcp.json uses ${workspaceFolder} in args for all stdio-type MCP servers — standard VS Code pattern per VS Code MCP docs.

  5. added
    area:configuration
    on Apr 6, 2026
  6. added
    area:mcp
    on Apr 6, 2026
  7. examon commented on Apr 7, 2026

    @examon

    I believe this has been addressed in current versions. ${VAR} expansion works in MCP config value fields including env, command, args, cwd, URLs, and HTTP headers. Note that ${workspaceFolder} is a VS Code-specific variable rather than a shell environment variable, so that case is handled differently. If this still doesn't work for your specific configuration, feel free to reopen the issue with a minimal example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:configurationarea:mcp

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions