Add env_provider and Extra.env support to MCP stdio transport - #69225
Merged
Conversation
MCPHook's stdio branch built StdioTransport without ever passing an env argument, so subprocess-based MCP servers had no way to receive credentials except by inheriting the worker's ambient environment. Extra.env now reaches the subprocess, and env_provider (mirroring the existing token_provider for HTTP/SSE) lets a credential that lives in a different connection, or one minted fresh per call, be resolved lazily at connection-establish time instead of being duplicated into this connection's static config.
Contributor
|
Oh, very interesting change. Didn't expect this, but this seems very logical to add |
vikramkoka
approved these changes
Jul 1, 2026
vikramkoka
left a comment
Contributor
There was a problem hiding this comment.
Yes, makes sense to me.
Also, is nice and localized.
sphinx-spelling tokenizes hyphenated compounds as a single word, so the unquoted "MCP-server" didn't match the wordlist entry for "MCP" even though standalone MCP is already allowlisted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MCPHook'sstdiotransport builtStdioTransportwithout ever passing anenvargument, so a local MCP server subprocess had no way to receive configuration or credentials except by inheriting the worker's ambient environment. This adds:Extra.env— a staticdict[str, str]in the connection'sextra, now passed through to the subprocess.env_provider— a zero-argument callable returningdict[str, str], mirroring the existingtoken_providerfor HTTP/SSE. Its return value is merged overExtra.env(env_providerwins on key conflicts), and every value it returns is registered with secret masking regardless of key name.Why
env_provider, not justExtra.env?Extra.envis fine for a value that genuinely belongs to this connection.env_providerexists for the same reasontoken_providerdoes on HTTP/SSE: the credential has no stable static form to store here at all — either because it lives in a different Airflow connection (avoiding two places to rotate the same secret), or because it's minted fresh per call (an OAuth token, a Vault lease) with nothing fixed to store anywhere.Usage
Gotchas
Extra.envis Fernet-encrypted at rest like the rest of the connection'sextra, but it's only masked in the Connections UI/API and task logs if a key's name happens to match a fixed set of sensitive-looking names (api_key,token,secret,password, etc.).env_providervalues are always masked regardless of key name.token_providerandenv_providerare invoked once, the first time a given hook/toolset instance establishes a connection — not on every reconnect of that same instance.env=None(no staticExtra.envand noenv_provider) does not inherit the full parent process environment; the MCP stdio client falls back to a small allowlist of variables (see themcppackage'sget_default_environment()).Extra.envvalues andenv_provider's return value are validated (non-empty string keys/values) at connection-build time, so a misconfigured connection fails with a clear, attributed error instead of a bareTypeErrordeep insidesubprocess.Popen.