Skip to content

fix(agentic-ai): forward configured env vars for STDIO MCP client transport#7163

Merged
maff merged 5 commits into
mainfrom
copilot/fix-env-variables-issue
May 8, 2026
Merged

fix(agentic-ai): forward configured env vars for STDIO MCP client transport#7163
maff merged 5 commits into
mainfrom
copilot/fix-env-variables-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 8, 2026

STDIO MCP client configuration accepted env values but dropped them when building MCP SDK ServerParameters, so spawned MCP server processes did not receive required environment variables (for example tokens/API keys). This change wires env through and adds a focused regression test.

  • Behavior fix: propagate STDIO env to MCP SDK transport

    • Updated McpSdkClientFactory#createStdioTransport to pass StdioMcpClientTransportConfiguration.env() into ServerParameters.
  • Regression coverage

    • Added a test in McpSdkClientFactoryTest that verifies configured STDIO env entries are present in the generated ServerParameters.
return new StdioClientTransport(
    ServerParameters.builder(stdioConfig.command())
        .args(stdioConfig.args())
        .env(stdioConfig.env())
        .build(),
    McpJsonDefaults.getMapper());

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jfrog-prod-euc1-shared-frankfurt-main.s3.amazonaws.com
    • Triggering command: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java --enable-native-access=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 (dns block)
  • repository.jboss.org
    • Triggering command: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java --enable-native-access=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 (dns block)
  • repository.sonatype.org
    • Triggering command: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java --enable-native-access=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix issue with env variables not passed to spawned process Forward configured env vars for STDIO MCP client transport May 8, 2026
Copilot finished work on behalf of maff May 8, 2026 06:49
Copilot AI requested a review from maff May 8, 2026 06:49
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 8, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jfrog-prod-euc1-shared-frankfurt-main.s3.amazonaws.com
    • Triggering command: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java --enable-native-access=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 (dns block)
  • repository.jboss.org
    • Triggering command: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java --enable-native-access=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 (dns block)
  • repository.sonatype.org
    • Triggering command: /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.9-10.0.LTS/x64/bin/java --enable-native-access=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of maff May 8, 2026 07:19
Copilot AI requested a review from maff May 8, 2026 07:19
Covers default, no-args, and no-env configurations in dedicated stdio
client tests instead of a separate env-only test.
@maff maff changed the title Forward configured env vars for STDIO MCP client transport fix(agentic-ai): forward configured env vars for STDIO MCP client transport May 8, 2026
@maff maff requested a review from nikonovd May 8, 2026 07:37
@maff maff marked this pull request as ready for review May 8, 2026 08:19
@maff maff requested a review from a team as a code owner May 8, 2026 08:19
Copilot AI review requested due to automatic review settings May 8, 2026 08:19
@maff maff requested a review from a team as a code owner May 8, 2026 08:19
@maff maff requested a review from chillleader May 8, 2026 08:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes STDIO MCP client process spawning so that configured environment variables are forwarded into the MCP SDK ServerParameters, ensuring spawned MCP servers receive required env (e.g., tokens/API keys).

Changes:

  • Propagate StdioMcpClientTransportConfiguration.env() into MCP SDK ServerParameters when creating STDIO transport.
  • Extend unit tests to assert the generated ServerParameters includes the configured command, args, and env.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
connectors/agentic-ai/src/main/java/io/camunda/connector/agenticai/mcp/client/framework/mcpsdk/McpSdkClientFactory.java Wires STDIO env config into ServerParameters for spawned MCP server processes.
connectors/agentic-ai/src/test/java/io/camunda/connector/agenticai/mcp/client/framework/mcpsdk/McpSdkClientFactoryTest.java Adds regression assertions by extracting ServerParameters from the created client and verifying env propagation.

Replace reflection into McpSyncClient internals with
Mockito.mockConstruction(StdioClientTransport) to capture the
ServerParameters argument directly. Asserts run against the real built
object instead of private SDK fields.
@maff maff force-pushed the copilot/fix-env-variables-issue branch from e9b85c6 to 9cf250c Compare May 8, 2026 09:03
Copy link
Copy Markdown
Contributor

@nikonovd nikonovd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@maff maff enabled auto-merge May 8, 2026 09:05
@maff maff added the agentic-ai label May 8, 2026
@maff maff removed the request for review from chillleader May 8, 2026 09:13
@maff maff added this pull request to the merge queue May 8, 2026
Merged via the queue into main with commit e68f7f9 May 8, 2026
31 checks passed
@maff maff deleted the copilot/fix-env-variables-issue branch May 8, 2026 09:35
@team-connectors-int-automation
Copy link
Copy Markdown
Contributor

maff added a commit that referenced this pull request May 8, 2026
…nsport (#7163) (#7165)

* Initial plan

* fix(agentic-ai): forward stdio env into MCP server parameters

Agent-Logs-Url: https://github.com/camunda/connectors/sessions/a5170b84-1cbf-4652-9fab-0a13e6c22f5c



* test(agentic-ai): assert stdio env via built client path

Agent-Logs-Url: https://github.com/camunda/connectors/sessions/887c1731-fe31-4eab-b4bf-ce11b1eaee87



* test(agentic-ai): assert stdio command/args/env across configurations

Covers default, no-args, and no-env configurations in dedicated stdio
client tests instead of a separate env-only test.

* test(agentic-ai): capture stdio ServerParameters via mockConstruction

Replace reflection into McpSyncClient internals with
Mockito.mockConstruction(StdioClientTransport) to capture the
ServerParameters argument directly. Asserts run against the real built
object instead of private SDK fields.

---------




(cherry picked from commit e68f7f9)

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: maff <27403+maff@users.noreply.github.com>
Co-authored-by: Mathias Geat <mathias.geat@camunda.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

STDIO MCP client does not pass configured env variables to the spawned process

4 participants