Skip to content

Utilize Env Vars in arguments #539

Open
@seanstory

Description

@seanstory

Just as it is handy to be able to utilized environment variables in CLI commands, it would be handy to be able to utilize your environment in the arguments for MCP Inspector. However, it seems that currently the environment is not loaded until after the provided arguments are processed.

I came across this issue while trying to use the mcp-remote server tool. This gives me a way to authenticate to a remote MCP Server that uses Authorization: ApiKey headers, rather than Authorization: Bearer. See their docs here, specifically this suggested usage:

{
  // rest of config...
  "args": [
    "mcp-remote",
    "https://remote.mcp.server/sse",
    "--header",
    "Authorization:${AUTH_HEADER}" // note no spaces around ':'
  ],
  "env": {
    "AUTH_HEADER": "Bearer <auth-token>" // spaces OK in env vars
  }
},

Because the AUTH_HEADER would have a space character, this seemed like a good fit. However, I observed logs like:

Query parameters: {"command":"npx","args":"mcp-remote http://localhost:5601/api/mcp --header Authorization:${MCP_REMOTE_AUTH_HEADER}","env":"{\"MCP_REMOTE_AUTH_HEADER\":\"ApiKey OBFUSCATED\"}","transportType":"stdio"}
STDIO transport: command=/Users/seanstory/.nvm/versions/node/v22.16.0/bin/npx, args=mcp-remote,http://localhost:5601/api/mcp,--header,Authorization:
Created server transport

note that the args and env both contain expected references to MCP_REMOTE_AUTH_HEADER, but the actual transport command ends with Authorization: (empty value).

Describe the solution you'd like

It would be ideal if the env was accessible when parsing the command, instead of only exported after forming up the command.

Describe alternatives you've considered

In this case, I was able to work around this by single-quoting my header, and pasting the API key value directly into the arguments. Like:

mcp-remote http://localhost:5601/api/mcp --header 'Authorization:ApiKey OBFUSCATED'

But I'd rather be able to use an environment variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions