Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

MCP env var references (${VAR}) not expanded for Agent Plugin powers

Open yomo07 opened this issue 2 months ago • 8 comments

Before opening, please confirm:

Operating System

win32

Kiro Version

1.0.437

Bug Description

Environment variable references like ${MSSQLPOWER_HOST} in an Agent Plugin power's mcp.json are passed to the MCP server literally, unexpanded.

Setup (all verified correct on my side):

  • System env vars created, correct UPPERCASE names (checked with if defined).
  • Names added to both kiro.mcp.approvedEnvVars and kiroAgent.mcpApprovedEnvVars, matching character-for-character.
  • Kiro fully restarted afterwards.
  • Node.js v24.20.0, Windows / cmd.exe.

Expected: ${MSSQLPOWER_HOST} etc. expanded to their values before the server starts.

Actual: server receives the placeholder literally. Error: Failed to connect to ${MSSQLPOWER_HOST}:1433 - getaddrinfo ENOTFOUND ${mssqlpower_host} Also note: port fell back to default 1433 instead of the configured value (${MSSQLPOWER_PORT} not expanded either), and the tail appears lowercased.

Workaround: hardcoding the real values in the installed mcp.json makes it work, confirming the issue is env var expansion, not the connection itself.

Repro:

  1. Install an Agent Plugin power whose mcp.json uses ${VAR} env references.
  2. Create those system env vars and add their names to approved env vars.
  3. Restart Kiro.
  4. Invoke a tool from the power that needs those vars.
  5. Server receives ${VAR} literally.

Related power (I'm the author): https://github.com/yomo07/dbmssqlpowerkiro This is a published Agent Plugin power (submitted for catalog approval, still pending review — mentioned only as context, not part of this bug). Its mcp.json uses ${VAR} env references, the exact config that triggers the bug, so it can serve as a reproducible reference case. Happy to help reproduce.

Steps to Reproduce

Repro:

  1. Install an Agent Plugin power whose mcp.json uses ${VAR} env references.
  2. Create those system env vars and add their names to approved env vars.
  3. Restart Kiro.
  4. Invoke a tool from the power that needs those vars.
  5. Server receives ${VAR} literally.

Expected Behavior

Expected behaviour

${MSSQLPOWER_HOST}, ${MSSQLPOWER_PORT}, etc. in the power's mcp.json should be resolved to their system environment values before the MCP server process is spawned. The server should receive the actual values (e.g. host 127.0.0.1, port 1443), never the literal ${VAR} placeholder.

Conversation ID

No response

Additional Context

  • Reproduced across multiple machines and users (different environments), not isolated to a single setup — points to a runtime-level issue, not local misconfiguration.
  • Config verified correct on my side: env vars present (checked via if defined, exact UPPERCASE names), approved in both kiro.mcp.approvedEnvVars and kiroAgent.mcpApprovedEnvVars, Kiro fully restarted.
  • Node.js v24.20.0, Windows / cmd.exe.
  • Hardcoding the values in the installed mcp.json works, which isolates the fault to ${VAR} expansion (not the connection or the server itself).
  • Related power (I'm the author, submitted for catalog review): https://github.com/yomo07/dbmssqlpowerkiro — its mcp.json uses ${VAR} references, the exact config that triggers the bug. Happy to help reproduce.

yomo07 avatar Sep 08 '26 02:09 yomo07

🤖 Potential Duplicate Detected

This issue appears to be similar to:

What happens next?

  • ⏰ This issue will be automatically closed in 3 days
  • 🏷️ If this is not a duplicate, you can prevent automatic closure by adding a comment or reacting with 👎 to this message.
  • 💬 Comment on the original issue if you have additional information

Why is this marked as duplicate? Both issues report the same core problem: environment variables using ${VAR} syntax in MCP configuration are not being expanded/resolved at runtime, with the literal placeholder strings being passed to the MCP server instead of the actual values. Issue #8391 specifically mentions kiro-cli not expanding environment variables when loading MCP servers, which is semantically identical to the new issue about ${VAR} references not being expanded for Agent Plugin powers in MCP configuration.

github-actions[bot] avatar Sep 08 '26 02:09 github-actions[bot]

Thanks for triaging. I want to flag that the linked duplicate (#8391) describes a different scenario: kiro-cli, Docker, "registry" server type, WSL Ubuntu. My report is specifically about the IDE (not CLI), "stdio" transport via npx (not Docker/registry), on Windows. Given the different execution paths, could this be reconsidered as a distinct issue, or is there evidence the underlying expansion code is shared between both paths? Happy to provide more repro detail if useful.

yomo07 avatar Sep 08 '26 03:09 yomo07

Thank you for your feedback! 🙏

The duplicate label has been removed and this issue has been sent back for maintainer review.

A maintainer will review this issue shortly.

github-actions[bot] avatar Sep 08 '26 03:09 github-actions[bot]

Thanks for the auto-link. Adding another data point: my case is on the IDE (not CLI), stdio transport (not registry/Docker), triggered specifically through an Agent Plugin power's mcp.json — full repro in #11258. Combined with chunyichan828's report of the same symptom on plain stdio (no Docker), this looks like it spans more surfaces than the "cli" label suggests, and possibly traces back to a shared expansion path. Given this has been open since May 11 with multiple confirmed reports (registry, stdio-CLI, Kiro Web, Snowflake, Agent Plugin/IDE) and no maintainer engagement yet, could this get prioritized?

yomo07 avatar Sep 08 '26 03:09 yomo07

Thanks @yomo07, and thank you for the well-structured repro and the detailed self-diagnosis. Your rebuttal of #8391 as a duplicate is correct: #8391 is kiro-cli registry/Docker transport, this is the IDE Agent Plugin power path with stdio — different surfaces, though they share the same underlying ${VAR} expansion code.

The expansion path for Agent Plugin powers does call process.env[varName] as the fallback when the variable is not in the approved-env scope. The most likely cause for variables passing through as ${MSSQLPOWER_HOST} literally is that process.env in the IDE's Node process does not see the system environment variables you added — either because they were added after the IDE launched (a full OS restart is sometimes needed on Windows for system env var visibility, not just an app restart), or because of a Windows environment inheritance path that the IDE process chain doesn't traverse.

A quick check that distinguishes the cases: in a Kiro terminal panel, run node -e "console.log(process.env.MSSQLPOWER_HOST)" — if it prints undefined, the variable isn't reaching the IDE process regardless of the Kiro setting. If it prints the value, the issue is in how the setting is applied.

Your note about multi-machine reproduction and the chunyichan828 report on plain stdio is useful signal and suggests this may be a more systematic gap in the approved-env vars path for non-user-origin servers.

Marking this as a bug to investigate further.

AnilMaktala avatar Sep 08 '26 13:09 AnilMaktala

Thanks for the quick and thorough response — really appreciate the detailed breakdown and the diagnostic step, it's helpful to see this being taken seriously.

Ran the diagnostic in Kiro's built-in cmd terminal (the default one Kiro provides) — the same local session the power actually runs in. node -e "console.log(process.env.MSSQLPOWER_HOST)" prints the defined value (not undefined). So the variable does reach the IDE's Node process correctly, in the exact same session context the power uses — this rules out the OS/system-restart hypothesis. The fault must be in how Kiro applies the approved-env-var setting when expanding ${VAR} into the spawned MCP server's env, rather than in environment inheritance from the OS.

Happy to run any further diagnostics if that helps narrow it down

yomo07 avatar Sep 12 '26 13:09 yomo07

Hi, I've found this issue when I was about to report the same behavior.

To add more info, I've used the "Build a power" power to migrate a Power.md where the MCPs and env vars worked. Kiro states that environment substitution is against the agents plugin standard: https://agent-plugins.org/specification#9-environment-variables-and-placeholder-expansion

But I have not found how to configure it in Kiro, provided I cannot do it in the mcp.json.

tonig avatar Sep 22 '26 08:09 tonig

This issue has been fixed in v2.45.0 (released October 22, 2026).

Fix: Powers in agent plugin format now expand ${var} references in their MCP server config.

Changelog entry: 20261022-2242-fixed

Please upgrade to the latest version. If you're still experiencing this after upgrading, please open a new issue with your version and a link back to this issue.

AnilMaktala avatar Oct 29 '26 18:10 AnilMaktala