# How to use environment variables in mcp.json

**URL:** <https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296>\
**Category:** Help\
**Created:** [April 15, 2025, 1:30am UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296 "2025-04-15T01:30:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francois](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/francois/32/47075_2.png) [@Francois](https://forum.cursor.com/u/Francois)\
**Post date:** [April 15, 2025, 1:30am UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/1 "2025-04-15T01:30:15Z")

</div>

mcp.json lets me define a github mcp like this:

```json
{
    "mcpServers": {
        "github-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "@modelcontextprotocol/server-github"
            ],
            "env": {
                "GITHUB_TOKEN": "<MySecretTokenHere>"
            }
        }
    }
}

```

a recent cursor update has added the possibility to define an mcp.json scoped to a project, which is great.  
However, I want to commit this mcp file to the project’s repo … but I don’t want to commit my secret token (I would want all of my colleagues to input theirs instead).  
Is there a way to get this server definition to actually lookup an environment variable??  
I have tried a lot of variations of $TOKEN / ${TOKEN} / etc and nothing seems to take (I did source the token value in my local environment).  
alternatively, if I could at least refer to a file (e.g. `~/.my_secret`), that would work too, that would still be scaleable to a team.

---

<div class="post-metadata">

**Author:** ![DeanBaron](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/deanbaron/32/46693_2.png) [@DeanBaron](https://forum.cursor.com/u/DeanBaron)\
**Post date:** [April 15, 2025, 8:59am UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/2 "2025-04-15T08:59:04Z")

</div>

I’m in the same situation as you. Not sure how to solve this, been going through a lot of topics in this forum and can’t find anything. Would highly appreciate a solution for this.  
I know that vscode solves this by allowing an “inputs” fields in the mcp configuration which prompts for manual inputs for these sensitive values.

---

<div class="post-metadata">

**Author:** ![normalnormie](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/normalnormie/32/18258_2.png) [@normalnormie](https://forum.cursor.com/u/normalnormie)\
**Post date:** [April 15, 2025, 9:02am UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/3 "2025-04-15T09:02:18Z")

</div>

check this to directly use a command [Cant get MCP running - #2 by normalnormie](https://forum.cursor.com/t/cant-get-mcp-running/78977/2)

---

<div class="post-metadata">

**Author:** ![DeanBaron](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/deanbaron/32/46693_2.png) [@DeanBaron](https://forum.cursor.com/u/DeanBaron)\
**Post date:** [April 15, 2025, 9:10am UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/4 "2025-04-15T09:10:03Z")

</div>

I’ve seen this, and I don’t think it really solves the issue described here if I understood the tool correctly.  
The issue is that we don’t want environment variables in git, so having a custom script for each MCP server which exports these ENV vars feels like a solution that isn’t really scalable for a team, because each team member will need to have his own copy of this script with his own configuration..

---

<div class="post-metadata">

**Author:** ![normalnormie](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/normalnormie/32/18258_2.png) [@normalnormie](https://forum.cursor.com/u/normalnormie)\
**Post date:** [April 15, 2025, 9:33am UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/5 "2025-04-15T09:33:22Z")

</div>

> **[Cursor – Model Context Protocol](https://docs.cursor.com/context/model-context-protocol#configuring-mcp-servers)**
>
> Connect external tools and data sources to Cursor using the Model Context Protocol (MCP) plugin system

@Francois code seems correct, it should work from 0.47+, try replacing “\<MySecretTokenHere\>”  
with “value” as shown in docs  
@DeanBaron that tool only outputs a string with variables that is setup inside Cursor mcp config under preferences, no edit file needed, the drawback is each member should add the mcp tool with their variable

other solution found: [mcp governance tool](https://www.ithena.one/) (complex, Enterprise-level)

---

<div class="post-metadata">

**Author:** ![YuvalNeuhaus](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/yuvalneuhaus/32/47294_2.png) [@YuvalNeuhaus](https://forum.cursor.com/u/YuvalNeuhaus)\
**Post date:** [April 15, 2025, 4:50pm UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/6 "2025-04-15T16:50:34Z")

</div>

Created a feature request for this issue: [Resolve local environment variables in MCP server definitions](https://forum.cursor.com/t/resolve-local-environment-variables-in-mcp-server-definitions/79639)

---

<div class="post-metadata">

**Author:** ![Spartee](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/spartee/32/49346_2.png) [@Spartee](https://forum.cursor.com/u/Spartee)\
**Post date:** [April 23, 2025, 11:19am UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/7 "2025-04-23T11:19:22Z")

</div>

Hi all!

This problem is called “Tool Authorization” and right now MCP is limited to single tenant usage because of this problem

However, this won’t be a problem for long. Anthropic, Arcade, and many other companies are working on making MCP servers “multi-tenent” if you will. [Multi-user Authorization · modelcontextprotocol/modelcontextprotocol · Discussion #234 · GitHub](https://github.com/modelcontextprotocol/modelcontextprotocol/discussions/234)

there are solutions to this.

Arcade will do the auth flow (for secrets and OAuth) at runtime and store/refresh/hold tokens, and if not auth’d, the user gets a link to auth the agent actions. this enables multi-tenancy. Sadly this isn’t currently possible with the MCP protocol as it stands. Only supported in the Arcade native protocol. Despite Arcade supporting MCP HTTP stream (new web standard over deprecated http+sse) the tool auth component is lacking. This is why you’re forced to deal with env vars. Specifically MCP hasn’t had methods for specifying the scopes/claims/perms etc of each action an agent takes so server devs are forced to endure this problem.

creds: I’m the founder of Arcade.dev

---

<div class="post-metadata">

**Author:** ![griffithsbs](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/griffithsbs/32/49791_2.png) [@griffithsbs](https://forum.cursor.com/u/griffithsbs)\
**Post date:** [April 26, 2025, 9:29pm UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/9 "2025-04-26T21:29:45Z")

</div>

I made this little package that provides a convenient solution for stdio MCP server definitions: [envmcp - npm](https://www.npmjs.com/package/envmcp)

You just need to prefix the command with `npx envmcp` in order to load your environment variables from an env file.

For your example, you could use it like this:

```auto
{
    "mcpServers": {
        "github-mcp": {
            "command": "npx",
            "args": [
                "envmcp",
                "npx",
                "-y",
                "@modelcontextprotocol/server-github"
            ],
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![AuspiciousSolitude](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@AuspiciousSolitude](https://forum.cursor.com/u/AuspiciousSolitude)\
**Post date:** [June 13, 2025, 3:48pm UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/10 "2025-06-13T15:48:00Z")

</div>

For those posting in this thread, please vote for this: [MCP.json pass secrets securely](https://forum.cursor.com/t/mcp-json-pass-secrets-securely/72942)

---

<div class="post-metadata">

**Author:** ![kirso](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/kirso/32/68870_2.png) [@kirso](https://forum.cursor.com/u/kirso)\
**Post date:** [July 6, 2025, 1:03pm UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/11 "2025-07-06T13:03:03Z")

</div>

Can I check that the only way right now is to hardcode these variables in the MCP.json?

---

<div class="post-metadata">

**Author:** ![griffithsbs](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/griffithsbs/32/49791_2.png) [@griffithsbs](https://forum.cursor.com/u/griffithsbs)\
**Post date:** [July 7, 2025, 4:53pm UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/12 "2025-07-07T16:53:23Z")

</div>

For now, yes, but if you’re using stdio-based MCP servers, you can always use [envmcp](https://www.npmjs.com/package/envmcp) or [mcpipe](https://www.npmjs.com/package/mcpipe), which both let you store your environment variables in a .env file and reference them by name in your MCP config. They also make the environment variables available to be read directly by the server itself.

N.B. both packages provide the same environment-loading functionality so you can use either one, but mcpipe includes a few more features in addition.

---

<div class="post-metadata">

**Author:** ![codekiln](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/codekiln/32/22614_2.png) [@codekiln](https://forum.cursor.com/u/codekiln)\
**Post date:** [August 5, 2025, 9:04am UTC](https://forum.cursor.com/t/how-to-use-environment-variables-in-mcp-json/79296/13 "2025-08-05T09:04:57Z")

</div>

I added my workarounds to this in [MCP.json pass secrets securely - Feature Requests - Cursor - Community Forum](https://forum.cursor.com/t/mcp-json-pass-secrets-securely/72942/6) - quoting from there:

> Here are my personal knowledge garden entries which mention workarounds that use the [1Password CLI](https://developer.1password.com/docs/cli/get-started/) `op` to wrap invocation of various MCPs:
> 
> [GitHub/MCP/How To/Set up in Cursor with 1Password GH token](https://codekiln.github.io/logseq-encode-garden/#/page/github%2Fmcp%2Fhow%20to%2Fset%20up%20in%20cursor%20with%201password%20gh%20token)
> 
> [Anthropic/App/Claude Code/How To/Set Up Github MCP with 1Password GH token and mise](https://codekiln.github.io/logseq-encode-garden/#/page/anthropic%2Fapp%2Fclaude%20code%2Fhow%20to%2Fset%20up%20github%20mcp%20with%201password%20gh%20token%20and%20mise)

The basic approach I use is to create an executable script which controls the environment variables used to instantiate the process that runs the MCP server.
