Skip to content

Conversation

@NamesMT
Copy link
Contributor

@NamesMT NamesMT commented May 25, 2025

Related GitHub Issue

Resolves #4014

Description

From @axmo reporting via Discord, some MCPs require inputting secrets via the CLI args, instead of env, and/or for any other reason, user would like to have command or args to have value inferred from the env, like using bunx or npx, configuring mcp args via env without code committing,...

The PR also fixes an unreported problem: env vars is not injected for sse transport, currently it's injected for stdio only.

Test Procedure

There is unit tests covering the usage and I also do some manual tests via VSCode debug to make sure all works good, just add breakpoint at the line.

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

Currently the docs does not note about the ability to reference env variables in the mcp config at all, would be great if anyone can help add it, normal user might not know about this feature and commit API keys.

Additional Notes

Get in Touch

@NamesMT


Important

Inject environment variables into MCP configurations for both stdio and sse transports, fixing a bug in McpHub.ts.

  • Feature:
    • Inject environment variables into MCP configurations for both stdio and sse transports in McpHub.ts.
    • Update injectEnv function in config.ts to support both string and object configurations.
  • Bug Fix:
    • Fix issue where environment variables were not injected for sse transport in McpHub.ts.

This description was created by Ellipsis for 8961614. You can customize this summary. It will automatically update as commits are pushed.

Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Just a nit to improve type assertion. This looks good to me.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 28, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap May 28, 2025
@daniel-lxs daniel-lxs removed the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label May 28, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 28, 2025
@mrubens mrubens merged commit dde71d2 into RooCodeInc:main May 28, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap May 28, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap May 28, 2025
@R-omk
Copy link
Contributor

R-omk commented May 30, 2025

@NamesMT

Please explain how to use this. I can't figure out where to place the secret values so that it works.

,roo/mcp.json

{
  "mcpServers": {
    "mcp-clickhouse-docker": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "--network",
        "host",
        "-i",
        "-e",
        "CLICKHOUSE_HOST",
        "-e",
        "CLICKHOUSE_PORT",
        "-e",
        "CLICKHOUSE_USER",
        "-e",
        "CLICKHOUSE_PASSWORD",
        "-e",
        "CLICKHOUSE_SECURE",
        "-e",
        "CLICKHOUSE_VERIFY",
        "-e",
        "CLICKHOUSE_CONNECT_TIMEOUT",
        "-e",
        "CLICKHOUSE_SEND_RECEIVE_TIMEOUT",
        "-e",
        "CLICKHOUSE_DATABASE",
        "mcp-clickhouse"
      ],
      "env": {
        "CLICKHOUSE_HOST": "127.0.0.1",
        "CLICKHOUSE_PORT": "8123",
        "CLICKHOUSE_USER": "userro",
        "CLICKHOUSE_PASSWORD": "${env:CLICKHOUSE_PASSWORD}",
        "CLICKHOUSE_DATABASE": "default",
        "CLICKHOUSE_SECURE": "false",
        "CLICKHOUSE_VERIFY": "false",
        "CLICKHOUSE_CONNECT_TIMEOUT": "30",
        "CLICKHOUSE_SEND_RECEIVE_TIMEOUT": "30"
      },
      "disabled": false,
      "alwaysAllow": [
        "list_tables"
      ]
    }
  }
}

@NamesMT
Copy link
Contributor Author

NamesMT commented May 30, 2025

Hi @R-omk, that should be correct (${env:NAME}), make sure to restart your VSCode after you have set the env var to your system so that the VSCode process have the envs loaded.

@R-omk
Copy link
Contributor

R-omk commented May 30, 2025

@NamesMT

but i need to load variables from a file inside the project.

the standard location is always the .env file in the root of the project

I don't want secrets to be globally accessible to any processes in the vscode

@daniel-lxs
Copy link
Member

Hey @R-omk,

What if you have multiple .env files across multiple workspaces, Roo Code only creates one instance of each MCP configured.

Which .env files should be used in that case to configure the MCP server?

@R-omk
Copy link
Contributor

R-omk commented May 30, 2025

@daniel-lxs

in my example, roo/mcp.json is located in the root of the project, of course I expect that in each project there will be completely isolated instances even if the names are the same.

Currently, for MCP, I use continue, and it includes functionality for reading from both local and global .env files. I just wanted to share envs along with the roo.

@NamesMT
Copy link
Contributor Author

NamesMT commented May 30, 2025

Hi @R-omk , IIRC currently Roo Code does not support loading the env files in the current workspace/folder, please create an issue for it and someone will pick it up, ty!

SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request Jun 13, 2025
* Fixing OpenAI compatible to support cache token display

* Removing redundant logging and write to file

* Removing redundant logging and write to file

* Splitting constants

---------

Co-authored-by: Cline Evaluation <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer PR - Needs Review size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

MCP configuration Environment Variable expansion does not work in cmd section

5 participants