feat: add --stdio-env option for passing environment variables#1
feat: add --stdio-env option for passing environment variables#1ddnowicki wants to merge 1 commit intopro-vi:masterfrom
Conversation
|
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: 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 The implementation uses the existing env_vars/env parameters that fastmcp transports already support (NpxStdioTransport, PythonStdioTransport, StdioTransport). Changes
Could you please review this PR? This feature would enable mcp-filter to work with any MCP server that requires environment variables. |
…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 ...
5d46b0a to
4fe82b3
Compare
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:
stdio_envfield toUpstreamConfigmodel--stdio-env KEY=VALUECLI option (repeatable)MF_STDIO_ENVenvironment variable support (semicolon-separated)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"