claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[FEATURE] MCP Servers configuration : add expanding variables support

Open PhilipGarnero opened this issue 8 months ago • 2 comments

In order for the project scope mcp servers to really be useful, it would be great that the config allowed for expanding environment variables.

For instance in a project .mcp.json :

{
  "mcpServers": {
    "mysql_local": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "--with",
        "pymysql",
        "mcp-alchemy"
      ],
      "env": {
        "DB_URL": "mysql+pymysql://$USER@localhost:3306/database"
      }
    }
  }
}

The $USER variable isn't expanding, forcing everyone to install this mcp server locally and rendering it useless as a project mcp.

PhilipGarnero avatar Apr 30 '25 22:04 PhilipGarnero

We're currently supporting the same MCP config format that most other clients are. One approach to solving this is to make the command a script inside your repo that invokes the MCP server with variables that it pulls from elsewhere.

ashwin-ant avatar May 03 '25 04:05 ashwin-ant

@ashwin-ant This is however not possible when using HTTP:

{
  "mcpServers": {
	"github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer ${THIS SHOULD BE A SECRET}"
      }
    }
}

See: https://github.com/github/github-mcp-server

moltar avatar Jun 28 '25 15:06 moltar

Please support this feature. Without it, the project mcp json is unusable with many useful mcp servers like figma, github.

vast00 avatar Jul 07 '25 10:07 vast00

Hey all - just a heads up, I've picked this up and this feature should hopefully be released very shortly, in the next few releases

ollie-anthropic avatar Jul 08 '25 22:07 ollie-anthropic

Hey all - this is now available in the latest release (1.0.48).

Docs are here! https://docs.anthropic.com/en/docs/claude-code/mcp#environment-variable-expansion-in-mcp-json

ollie-anthropic avatar Jul 10 '25 17:07 ollie-anthropic

Beautiful! Thanks

moltar avatar Jul 10 '25 17:07 moltar

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Aug 10 '25 14:08 github-actions[bot]