Skip to content

feat: add --stdio-env option for passing environment variables#1

Merged
pro-vi merged 1 commit into
pro-vi:masterfrom
ddnowicki:feature/stdio-env-passthrough
Jul 10, 2026
Merged

feat: add --stdio-env option for passing environment variables#1
pro-vi merged 1 commit into
pro-vi:masterfrom
ddnowicki:feature/stdio-env-passthrough

Conversation

@ddnowicki

@ddnowicki ddnowicki commented Dec 29, 2025

Copy link
Copy Markdown
Contributor

Add support for passing environment variables to the upstream stdio subprocess. This enables use cases where the upstream MCP server requires environment variables (e.g., API tokens, URLs) that need to be passed through the filter.

Changes:

  • Add stdio_env field to UpstreamConfig model
  • Add --stdio-env KEY=VALUE CLI option (repeatable)
  • Add MF_STDIO_ENV environment variable support (semicolon-separated)
  • Pass env vars to NpxStdioTransport, PythonStdioTransport, and StdioTransport

Usage:
mcp-filter run -t stdio --stdio-command npx \ --stdio-arg "-y @some/mcp-server" \ --stdio-env "API_KEY=secret" \ --stdio-env "API_URL=https://example.com"

@ddnowicki

Copy link
Copy Markdown
Contributor Author

Hi @pro-vi,

I was trying to use mcp-filter with Claude Code to proxy a GitLab MCP server (@zereight/mcp-gitlab) that requires environment variables like GITLAB_PERSONAL_ACCESS_TOKEN and GITLAB_API_URL.

The problem: The env section only sets environment variables for mcp-filter itself, but these variables are not forwarded to the spawned subprocess (npx @zereight/mcp-gitlab).

The upstream GitLab MCP server failed with:
GITLAB_PERSONAL_ACCESS_TOKEN environment variable is not set

Solution

I added a --stdio-env option that allows passing environment variables directly to the upstream subprocess:

mcp-filter run -t stdio --stdio-command npx
--stdio-arg "-y @zereight/mcp-gitlab"
--stdio-env "GITLAB_PERSONAL_ACCESS_TOKEN=glpat-xxx"
--stdio-env "GITLAB_API_URL=https://gitlab.example.com/api/v4"
-a "get_merge_request,mr_discussions"

The implementation uses the existing env_vars/env parameters that fastmcp transports already support (NpxStdioTransport, PythonStdioTransport, StdioTransport).

Changes

  • config.py: Added stdio_env: Dict[str, str] field + MF_STDIO_ENV env var parsing
  • cli.py: Added --stdio-env KEY=VALUE CLI option (repeatable)
  • upstream.py: Pass env to transport constructors

Could you please review this PR? This feature would enable mcp-filter to work with any MCP server that requires environment variables.

@ddnowicki ddnowicki changed the title feat: add --stdio-env option for passing environment variables to sub… feat: add --stdio-env option for passing environment variables Dec 29, 2025
…process

Add support for passing environment variables to the upstream stdio subprocess.
This enables use cases where the upstream MCP server requires environment
variables (e.g., API tokens, URLs) that need to be passed through the filter.

Changes:
- Add `stdio_env` field to `UpstreamConfig` model
- Add `--stdio-env KEY=VALUE` CLI option (repeatable)
- Add `MF_STDIO_ENV` environment variable support (semicolon-separated)
- Pass env vars to NpxStdioTransport, PythonStdioTransport, and StdioTransport

Usage:
  mcp-filter run -t stdio --stdio-command npx \
    --stdio-arg "-y @some/mcp-server" \
    --stdio-env "API_KEY=secret" \
    --stdio-env "API_URL=https://example.com"

Or via environment variable:
  MF_STDIO_ENV="API_KEY=secret;API_URL=https://example.com" mcp-filter run ...
@ddnowicki ddnowicki force-pushed the feature/stdio-env-passthrough branch from 5d46b0a to 4fe82b3 Compare December 29, 2025 14:51
@pro-vi pro-vi merged commit 84364fd into pro-vi:master Jul 10, 2026
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