Fix MCP env var handling: add Task.env/Plan.globalEnv with process.env apply/restore around session creation#25
Draft
Fix MCP env var handling: add Task.env/Plan.globalEnv with process.env apply/restore around session creation#25
Conversation
…v, env-validation utils, and process.env application before session creation Co-authored-by: colindembovsky <1932561+colindembovsky@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix MCP server environment variable handling per SDK v0.1.25
Fix MCP env var handling: add Task.env/Plan.globalEnv with process.env apply/restore around session creation
Feb 25, 2026
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.
SDK v0.1.25 standardizes MCP env var propagation via
envValueMode: direct, but Planeteer had no mechanism to set env vars beforecreateSession()is called — and noTask.envorPlan.globalEnvfields at all.Model changes (
plan.ts)Task.env?: Record<string, string>— task-scoped env varsPlan.globalEnv?: Record<string, string>— plan-wide env vars (overridden per-task)New utility (
src/utils/env-validation.ts)isSensitiveKey(name)— detectskey,token,password,secret,credential,authin var namesmaskEnvVars(env)— replaces sensitive values with***for safe displayisValidEnvName(name)— POSIX name validation (^[A-Za-z_][A-Za-z0-9_]*$)Executor changes (
executor.ts)Exported
mergeEnv(globalEnv?, taskEnv?)merges the two maps (task wins), skipping invalid POSIX names. Before eachsendPromptSynccall (which internally callscreateSession), env vars are applied toprocess.envand restored in afinallyblock — covering both task execution and the init bootstrap:Other
package.json:@github/copilot-sdkbumped to^0.1.25globalEnvand task-levelenvOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.