Skip to content

Commit 3408be3

Browse files
committed
Merge branch 'bugfix/issue-114' of https://github.com/jacksteamdev/inspector into bugfix/issue-114
2 parents 406828a + f8052df commit 3408be3

File tree

12 files changed

+535
-265
lines changed

12 files changed

+535
-265
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616

17+
- name: Check formatting
18+
run: npx prettier --check .
19+
1720
- uses: actions/setup-node@v4
1821
with:
1922
node-version: 18

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
packages
22
server/build
3+
CODE_OF_CONDUCT.md
4+
SECURITY.md

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ To inspect an MCP server implementation, there's no need to clone this repo. Ins
1414
npx @modelcontextprotocol/inspector build/index.js
1515
```
1616

17-
You can also pass arguments along which will get passed as arguments to your MCP server:
17+
You can pass both arguments and environment variables to your MCP server. Arguments are passed directly to your server, while environment variables can be set using the `-e` flag:
1818

19-
```
20-
npx @modelcontextprotocol/inspector build/index.js arg1 arg2 ...
19+
```bash
20+
# Pass arguments only
21+
npx @modelcontextprotocol/inspector build/index.js arg1 arg2
22+
23+
# Pass environment variables only
24+
npx @modelcontextprotocol/inspector -e KEY=value -e KEY2=$VALUE2 build/index.js
25+
26+
# Pass both environment variables and arguments
27+
npx @modelcontextprotocol/inspector -e KEY=value -e KEY2=$VALUE2 build/index.js arg1 arg2
28+
29+
# Use -- to separate inspector flags from server arguments
30+
npx @modelcontextprotocol/inspector -e KEY=$VALUE -- build/index.js -e server-flag
2131
```
2232

2333
The inspector runs both a client UI (default port 5173) and an MCP proxy server (default port 3000). Open the client UI in your browser to use the inspector. You can customize the ports if needed:
@@ -26,7 +36,7 @@ The inspector runs both a client UI (default port 5173) and an MCP proxy server
2636
CLIENT_PORT=8080 SERVER_PORT=9000 npx @modelcontextprotocol/inspector build/index.js
2737
```
2838

29-
For more details on ways to use the inspector, see the [Inspector section of the MCP docs site](https://modelcontextprotocol.io/docs/tools/inspector).
39+
For more details on ways to use the inspector, see the [Inspector section of the MCP docs site](https://modelcontextprotocol.io/docs/tools/inspector). For help with debugging, see the [Debugging guide](https://modelcontextprotocol.io/docs/tools/debugging).
3040

3141
### From this repository
3242

bin/cli.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,32 @@ function delay(ms) {
1111
}
1212

1313
async function main() {
14-
// Get command line arguments
15-
const [, , command, ...mcpServerArgs] = process.argv;
14+
// Parse command line arguments
15+
const args = process.argv.slice(2);
16+
const envVars = {};
17+
const mcpServerArgs = [];
18+
let command = null;
19+
let parsingFlags = true;
20+
21+
for (let i = 0; i < args.length; i++) {
22+
const arg = args[i];
23+
24+
if (parsingFlags && arg === "--") {
25+
parsingFlags = false;
26+
continue;
27+
}
28+
29+
if (parsingFlags && arg === "-e" && i + 1 < args.length) {
30+
const [key, value] = args[++i].split("=");
31+
if (key && value) {
32+
envVars[key] = value;
33+
}
34+
} else if (!command) {
35+
command = arg;
36+
} else {
37+
mcpServerArgs.push(arg);
38+
}
39+
}
1640

1741
const inspectorServerPath = resolve(
1842
__dirname,
@@ -52,7 +76,11 @@ async function main() {
5276
...(mcpServerArgs ? [`--args=${mcpServerArgs.join(" ")}`] : []),
5377
],
5478
{
55-
env: { ...process.env, PORT: SERVER_PORT },
79+
env: {
80+
...process.env,
81+
PORT: SERVER_PORT,
82+
MCP_ENV_VARS: JSON.stringify(envVars),
83+
},
5684
signal: abort.signal,
5785
echoOutput: true,
5886
},

0 commit comments

Comments
 (0)