Skip to content

Commit e46ae33

Browse files
committed
document startup flow
1 parent 37b417f commit e46ae33

File tree

1 file changed

+53
-21
lines changed

1 file changed

+53
-21
lines changed

client/bin/start.js

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ async function main() {
2323
let configPath = null;
2424
let serverName = null;
2525

26+
// Inspector can either be ran with a config file or a command to start an MCP server
27+
// Order of precedence is:
28+
// 1. Load configuration from MCP server config file
29+
// 2. Use direct command (and args) provided on the command line (if no config file is provided)
30+
31+
// Early check if an MCP server config file is provided to make logic simpler below
32+
const configProvided = args.includes("--config");
33+
2634
for (let i = 0; i < args.length; i++) {
2735
const arg = args[i];
2836

@@ -31,32 +39,51 @@ async function main() {
3139
continue;
3240
}
3341

34-
if (parsingFlags && arg === "--config" && i + 1 < args.length) {
35-
configPath = args[++i];
36-
continue;
37-
}
42+
if (parsingFlags) {
43+
// Parse a file path to an MCP servers' config file where each server has:
44+
// - Server type (sse, streamable-http, or stdio)
45+
// - Server URL (for sse/streamable-http)
46+
// - Command and args (for stdio)
47+
// - Environment variables
48+
if (arg === "--config" && i + 1 < args.length) {
49+
configPath = args[++i];
50+
continue;
51+
}
3852

39-
if (parsingFlags && arg === "--server" && i + 1 < args.length) {
40-
serverName = args[++i];
41-
continue;
42-
}
53+
// Parse a server name to use from the relevant config file
54+
if (arg === "--server" && i + 1 < args.length) {
55+
serverName = args[++i];
56+
continue;
57+
}
4358

44-
if (parsingFlags && arg === "-e" && i + 1 < args.length) {
45-
const envVar = args[++i];
46-
const equalsIndex = envVar.indexOf("=");
59+
// Process any environment variables (in addition to those provided in the config file)
60+
// CLI env vars will override those in the config file - handled below
61+
// Format: -e KEY=VALUE or -e KEY (empty value)
62+
if (arg === "-e" && i + 1 < args.length) {
63+
const envVar = args[++i];
64+
const equalsIndex = envVar.indexOf("=");
65+
66+
if (equalsIndex !== -1) {
67+
const key = envVar.substring(0, equalsIndex);
68+
const value = envVar.substring(equalsIndex + 1);
69+
envVars[key] = value;
70+
} else {
71+
envVars[envVar] = "";
72+
}
73+
continue;
74+
}
75+
}
4776

48-
if (equalsIndex !== -1) {
49-
const key = envVar.substring(0, equalsIndex);
50-
const value = envVar.substring(equalsIndex + 1);
51-
envVars[key] = value;
77+
// If a config file isn't provided, then an explicit command (and args) can be provided instead
78+
// eg. node //some/path/to/a/build/index.js
79+
if (!configProvided) {
80+
// Set the first argument as the command to run
81+
if (!command) {
82+
command = arg;
5283
} else {
53-
envVars[envVar] = "";
84+
// If a command has already been provided, then the remaining args as passed to the command
85+
mcpServerArgs.push(arg);
5486
}
55-
// If loading a config file, we don't need to pass the command or args
56-
} else if (!command && !configPath) {
57-
command = arg;
58-
} else {
59-
mcpServerArgs.push(arg);
6087
}
6188
}
6289

@@ -110,6 +137,11 @@ async function main() {
110137

111138
// Build server arguments based on config or command line
112139
let serverArgs = [];
140+
141+
// Environment variables precedence:
142+
// 1. Command line env vars (-e flag) take highest precedence
143+
// 2. Config file env vars are next
144+
// 3. System environment variables are lowest precedence
113145
let envVarsToPass = { ...envVars };
114146

115147
let serverEnv = {

0 commit comments

Comments
 (0)