fix(skill-mcp): always inherit process.env for MCP servers
- Always merge parent process.env when spawning MCP child processes - Overlay config.env on top if present (for skill-specific overrides) - Fixes issue where skills without explicit env: block started with zero environment variables - Adds 2 tests for env inheritance behavior 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -55,18 +55,20 @@ export class SkillMcpManager {
|
||||
const command = config.command
|
||||
const args = config.args || []
|
||||
|
||||
// Always inherit parent process environment
|
||||
const mergedEnv: Record<string, string> = {}
|
||||
for (const [key, value] of Object.entries(process.env)) {
|
||||
if (value !== undefined) mergedEnv[key] = value
|
||||
}
|
||||
// Overlay with skill-specific env vars if present
|
||||
if (config.env) {
|
||||
for (const [key, value] of Object.entries(process.env)) {
|
||||
if (value !== undefined) mergedEnv[key] = value
|
||||
}
|
||||
Object.assign(mergedEnv, config.env)
|
||||
}
|
||||
|
||||
const transport = new StdioClientTransport({
|
||||
command,
|
||||
args,
|
||||
env: config.env ? mergedEnv : undefined,
|
||||
env: mergedEnv,
|
||||
})
|
||||
|
||||
const client = new Client(
|
||||
|
||||
Reference in New Issue
Block a user