@modelcontextprotocol/inspector-cli 0.16.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.js +80 -12
- package/build/client/connection.js +5 -0
- package/package.json +1 -1
package/build/cli.js
CHANGED
|
@@ -38,6 +38,14 @@ async function runWebClient(args) {
|
|
|
38
38
|
for (const [key, value] of Object.entries(args.envArgs)) {
|
|
39
39
|
startArgs.push("-e", `${key}=${value}`);
|
|
40
40
|
}
|
|
41
|
+
// Pass transport type if specified
|
|
42
|
+
if (args.transport) {
|
|
43
|
+
startArgs.push("--transport", args.transport);
|
|
44
|
+
}
|
|
45
|
+
// Pass server URL if specified
|
|
46
|
+
if (args.serverUrl) {
|
|
47
|
+
startArgs.push("--server-url", args.serverUrl);
|
|
48
|
+
}
|
|
41
49
|
// Pass command and args (using -- to separate them)
|
|
42
50
|
if (args.command) {
|
|
43
51
|
startArgs.push("--", args.command, ...args.args);
|
|
@@ -63,7 +71,17 @@ async function runCli(args) {
|
|
|
63
71
|
abort.abort();
|
|
64
72
|
});
|
|
65
73
|
try {
|
|
66
|
-
|
|
74
|
+
// Build CLI arguments
|
|
75
|
+
const cliArgs = [cliPath];
|
|
76
|
+
// Add transport flag if specified
|
|
77
|
+
if (args.transport && args.transport !== "stdio") {
|
|
78
|
+
// Convert streamable-http back to http for CLI mode
|
|
79
|
+
const cliTransport = args.transport === "streamable-http" ? "http" : args.transport;
|
|
80
|
+
cliArgs.push("--transport", cliTransport);
|
|
81
|
+
}
|
|
82
|
+
// Add command and remaining args
|
|
83
|
+
cliArgs.push(args.command, ...args.args);
|
|
84
|
+
await spawnPromise("node", cliArgs, {
|
|
67
85
|
env: { ...process.env, ...args.envArgs },
|
|
68
86
|
signal: abort.signal,
|
|
69
87
|
echoOutput: true,
|
|
@@ -124,38 +142,88 @@ function parseArgs() {
|
|
|
124
142
|
.option("-e <env>", "environment variables in KEY=VALUE format", parseKeyValuePair, {})
|
|
125
143
|
.option("--config <path>", "config file path")
|
|
126
144
|
.option("--server <n>", "server name from config file")
|
|
127
|
-
.option("--cli", "enable CLI mode")
|
|
145
|
+
.option("--cli", "enable CLI mode")
|
|
146
|
+
.option("--transport <type>", "transport type (stdio, sse, http)")
|
|
147
|
+
.option("--server-url <url>", "server URL for SSE/HTTP transport");
|
|
128
148
|
// Parse only the arguments before --
|
|
129
149
|
program.parse(preArgs);
|
|
130
150
|
const options = program.opts();
|
|
131
151
|
const remainingArgs = program.args;
|
|
132
152
|
// Add back any arguments that came after --
|
|
133
153
|
const finalArgs = [...remainingArgs, ...postArgs];
|
|
134
|
-
// Validate
|
|
135
|
-
if (
|
|
136
|
-
(
|
|
137
|
-
|
|
154
|
+
// Validate config and server options
|
|
155
|
+
if (!options.config && options.server) {
|
|
156
|
+
throw new Error("--server requires --config to be specified");
|
|
157
|
+
}
|
|
158
|
+
// If config is provided without server, try to auto-select
|
|
159
|
+
if (options.config && !options.server) {
|
|
160
|
+
const configContent = fs.readFileSync(path.isAbsolute(options.config)
|
|
161
|
+
? options.config
|
|
162
|
+
: path.resolve(process.cwd(), options.config), "utf8");
|
|
163
|
+
const parsedConfig = JSON.parse(configContent);
|
|
164
|
+
const servers = Object.keys(parsedConfig.mcpServers || {});
|
|
165
|
+
if (servers.length === 1) {
|
|
166
|
+
// Use the only server if there's just one
|
|
167
|
+
options.server = servers[0];
|
|
168
|
+
}
|
|
169
|
+
else if (servers.length === 0) {
|
|
170
|
+
throw new Error("No servers found in config file");
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// Multiple servers, require explicit selection
|
|
174
|
+
throw new Error(`Multiple servers found in config file. Please specify one with --server.\nAvailable servers: ${servers.join(", ")}`);
|
|
175
|
+
}
|
|
138
176
|
}
|
|
139
177
|
// If config file is specified, load and use the options from the file. We must merge the args
|
|
140
178
|
// from the command line and the file together, or we will miss the method options (--method,
|
|
141
179
|
// etc.)
|
|
142
180
|
if (options.config && options.server) {
|
|
143
181
|
const config = loadConfigFile(options.config, options.server);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
182
|
+
if (config.type === "stdio") {
|
|
183
|
+
return {
|
|
184
|
+
command: config.command,
|
|
185
|
+
args: [...(config.args || []), ...finalArgs],
|
|
186
|
+
envArgs: { ...(config.env || {}), ...(options.e || {}) },
|
|
187
|
+
cli: options.cli || false,
|
|
188
|
+
transport: "stdio",
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
else if (config.type === "sse" || config.type === "streamable-http") {
|
|
192
|
+
return {
|
|
193
|
+
command: config.url,
|
|
194
|
+
args: finalArgs,
|
|
195
|
+
envArgs: options.e || {},
|
|
196
|
+
cli: options.cli || false,
|
|
197
|
+
transport: config.type,
|
|
198
|
+
serverUrl: config.url,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
// Backwards compatibility: if no type field, assume stdio
|
|
203
|
+
return {
|
|
204
|
+
command: config.command || "",
|
|
205
|
+
args: [...(config.args || []), ...finalArgs],
|
|
206
|
+
envArgs: { ...(config.env || {}), ...(options.e || {}) },
|
|
207
|
+
cli: options.cli || false,
|
|
208
|
+
transport: "stdio",
|
|
209
|
+
};
|
|
210
|
+
}
|
|
150
211
|
}
|
|
151
212
|
// Otherwise use command line arguments
|
|
152
213
|
const command = finalArgs[0] || "";
|
|
153
214
|
const args = finalArgs.slice(1);
|
|
215
|
+
// Map "http" shorthand to "streamable-http"
|
|
216
|
+
let transport = options.transport;
|
|
217
|
+
if (transport === "http") {
|
|
218
|
+
transport = "streamable-http";
|
|
219
|
+
}
|
|
154
220
|
return {
|
|
155
221
|
command,
|
|
156
222
|
args,
|
|
157
223
|
envArgs: options.e || {},
|
|
158
224
|
cli: options.cli || false,
|
|
225
|
+
transport: transport,
|
|
226
|
+
serverUrl: options.serverUrl,
|
|
159
227
|
};
|
|
160
228
|
}
|
|
161
229
|
async function main() {
|
|
@@ -8,6 +8,11 @@ export const validLogLevels = [
|
|
|
8
8
|
export async function connect(client, transport) {
|
|
9
9
|
try {
|
|
10
10
|
await client.connect(transport);
|
|
11
|
+
if (client.getServerCapabilities()?.logging) {
|
|
12
|
+
// default logging level is undefined in the spec, but the user of the
|
|
13
|
+
// inspector most likely wants debug.
|
|
14
|
+
await client.setLoggingLevel("debug");
|
|
15
|
+
}
|
|
11
16
|
}
|
|
12
17
|
catch (error) {
|
|
13
18
|
throw new Error(`Failed to connect to MCP server: ${error instanceof Error ? error.message : String(error)}`);
|