Creating a wrapper script for env variables for MCP server

Hi guys! Do you have any ideas how do we create a wrapper script if we have a environment variables on our MCP server stdio and what is the commands should we use for windows os, let’s talk about the command the working command on windows os is " node C:/user/path/to/brave-search/index.js" this works on me. Can you tell me if what’s the step by step how to use and setup it? If there’s a link it would be better.

2 Likes

For Windows, you can actually add environment variables directly in the command using SET. So if you need to set an API key for example, you can do:

SET APIKEY=your_key && node C:/user/path/to/brave-search/index.js

You should be able to chain multiple environment variables like:

SET APIKEY=key1 && SET OTHERVAR=value2 && node C:/user/path/to/brave-search/index.js

When setting up the MCP server in Cursor settings (Cursor – Model Context Protocol), just paste that full command including the environment variables in the command field

2 Likes

Thank you for this

It’s still not fixed the problem. It’s always saying this

Ah, looks like it doesn’t support that syntax!
Maybe try something like this?

cmd /C "SET APIKEY=your_key && node C:/user/path/to/brave-search/index.js"

1 Like

it’s still not working

2025-02-21 00:26:06.455 [info] [MCP] Listing tools from stdio server with identifier: cmd /C "SET BRAVE_API_KEY=BSA646y53cWqFdAmtKZWlbUDI9boIfo && node C:/Users/ACER/mcp-servers/servers/src/brave-search/dist/index.js"
2025-02-21 00:26:06.455 [info] [MCP] Creating client for stdio server: cmd /C "SET BRAVE_API_KEY=BSA646y53cWqFdAmtKZWlbUDI9boIfo && node C:/Users/ACER/mcp-servers/servers/src/brave-search/dist/index.js"
2025-02-21 00:26:06.455 [info] [MCP] Expanded command path: cmd /C "SET BRAVE_API_KEY=BSA646y53cWqFdAmtKZWlbUDI9boIfo && node C:/Users/ACER/mcp-servers/servers/src/brave-search/dist/index.js"
2025-02-21 00:26:06.456 [info] [MCP] Starting new stdio process with command: cmd /C "SET BRAVE_API_KEY=BSA646y53cWqFdAmtKZWlbUDI9boIfo && node C:/Users/ACER/mcp-servers/servers/src/brave-search/dist/index.js"
2025-02-21 00:26:06.954 [error] [MCP] Failed to connect to stdio server with command 'cmd /C "SET BRAVE_API_KEY=BSA646y53cWqFdAmtKZWlbUDI9boIfo && node C:/Users/ACER/mcp-servers/servers/src/brave-search/dist/index.js"': MCP error -32000: Connection closed
2025-02-21 00:26:06.955 [error] [MCP] Error listing tools for stdio server cmd /C "SET BRAVE_API_KEY=BSA646y53cWqFdAmtKZWlbUDI9boIfo && node C:/Users/ACER/mcp-servers/servers/src/brave-search/dist/index.js": MCP error -32000: Connection closed

Also the npx command is not working when I am installing all of the smithery and other mcp server that’s look like this format " npx -y @smithery/cli@latest run @henryhawke/mcp-titan --config “{}” "

Does the server work if you run it directly, without trying to add the variables inline?

Smithery is a 3rd party tool, so we cannot offer any support for that, unfortunately.

yes! absolutely. I tried it on cmd and powershell and they are connected

even the other npx command that not in the smithery, they are not working on my end. maybe because I am a windows user

i can’t seem to add a command like “GITHUB_PERSONAL_ACCESS_TOKEN={token} npx -y @modelcontextprotocol/server-github” but running it without setting the env variable works until it actually tried to call one of the tools and i get an authentication error

Make sure you use https://smithery.ai/ for MCP servers and make sure the server is live by checking the green light
image