@modelcontextprotocol/inspector-cli 0.16.1 → 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 CHANGED
@@ -32,8 +32,26 @@ async function runWebClient(args) {
32
32
  cancelled = true;
33
33
  abort.abort();
34
34
  });
35
+ // Build arguments to pass to start.js
36
+ const startArgs = [];
37
+ // Pass environment variables
38
+ for (const [key, value] of Object.entries(args.envArgs)) {
39
+ startArgs.push("-e", `${key}=${value}`);
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
+ }
49
+ // Pass command and args (using -- to separate them)
50
+ if (args.command) {
51
+ startArgs.push("--", args.command, ...args.args);
52
+ }
35
53
  try {
36
- await spawnPromise("node", [inspectorClientPath], {
54
+ await spawnPromise("node", [inspectorClientPath, ...startArgs], {
37
55
  signal: abort.signal,
38
56
  echoOutput: true,
39
57
  });
@@ -53,7 +71,17 @@ async function runCli(args) {
53
71
  abort.abort();
54
72
  });
55
73
  try {
56
- await spawnPromise("node", [cliPath, args.command, ...args.args], {
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, {
57
85
  env: { ...process.env, ...args.envArgs },
58
86
  signal: abort.signal,
59
87
  echoOutput: true,
@@ -114,38 +142,88 @@ function parseArgs() {
114
142
  .option("-e <env>", "environment variables in KEY=VALUE format", parseKeyValuePair, {})
115
143
  .option("--config <path>", "config file path")
116
144
  .option("--server <n>", "server name from config file")
117
- .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");
118
148
  // Parse only the arguments before --
119
149
  program.parse(preArgs);
120
150
  const options = program.opts();
121
151
  const remainingArgs = program.args;
122
152
  // Add back any arguments that came after --
123
153
  const finalArgs = [...remainingArgs, ...postArgs];
124
- // Validate that config and server are provided together
125
- if ((options.config && !options.server) ||
126
- (!options.config && options.server)) {
127
- throw new Error("Both --config and --server must be provided together. If you specify one, you must specify the other.");
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
+ }
128
176
  }
129
177
  // If config file is specified, load and use the options from the file. We must merge the args
130
178
  // from the command line and the file together, or we will miss the method options (--method,
131
179
  // etc.)
132
180
  if (options.config && options.server) {
133
181
  const config = loadConfigFile(options.config, options.server);
134
- return {
135
- command: config.command,
136
- args: [...(config.args || []), ...finalArgs],
137
- envArgs: { ...(config.env || {}), ...(options.e || {}) },
138
- cli: options.cli || false,
139
- };
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
+ }
140
211
  }
141
212
  // Otherwise use command line arguments
142
213
  const command = finalArgs[0] || "";
143
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
+ }
144
220
  return {
145
221
  command,
146
222
  args,
147
223
  envArgs: options.e || {},
148
224
  cli: options.cli || false,
225
+ transport: transport,
226
+ serverUrl: options.serverUrl,
149
227
  };
150
228
  }
151
229
  async function main() {
@@ -155,7 +233,7 @@ async function main() {
155
233
  try {
156
234
  const args = parseArgs();
157
235
  if (args.cli) {
158
- runCli(args);
236
+ await runCli(args);
159
237
  }
160
238
  else {
161
239
  await runWebClient(args);
@@ -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)}`);
package/build/index.js CHANGED
@@ -193,6 +193,8 @@ async function main() {
193
193
  try {
194
194
  const args = parseArgs();
195
195
  await callMethod(args);
196
+ // Explicitly exit to ensure process terminates in CI
197
+ process.exit(0);
196
198
  }
197
199
  catch (error) {
198
200
  handleError(error);
@@ -2,20 +2,6 @@ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
2
2
  import { getDefaultEnvironment, StdioClientTransport, } from "@modelcontextprotocol/sdk/client/stdio.js";
3
3
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
4
4
  import { findActualExecutable } from "spawn-rx";
5
- function createSSETransport(options) {
6
- const baseUrl = new URL(options.url ?? "");
7
- const sseUrl = baseUrl.pathname.endsWith("/sse")
8
- ? baseUrl
9
- : new URL("/sse", baseUrl);
10
- return new SSEClientTransport(sseUrl);
11
- }
12
- function createHTTPTransport(options) {
13
- const baseUrl = new URL(options.url ?? "");
14
- const mcpUrl = baseUrl.pathname.endsWith("/mcp")
15
- ? baseUrl
16
- : new URL("/mcp", baseUrl);
17
- return new StreamableHTTPClientTransport(mcpUrl);
18
- }
19
5
  function createStdioTransport(options) {
20
6
  let args = [];
21
7
  if (options.args !== undefined) {
@@ -46,11 +32,16 @@ export function createTransport(options) {
46
32
  if (transportType === "stdio") {
47
33
  return createStdioTransport(options);
48
34
  }
35
+ // If not STDIO, then it must be either SSE or HTTP.
36
+ if (!options.url) {
37
+ throw new Error("URL must be provided for SSE or HTTP transport types.");
38
+ }
39
+ const url = new URL(options.url);
49
40
  if (transportType === "sse") {
50
- return createSSETransport(options);
41
+ return new SSEClientTransport(url);
51
42
  }
52
43
  if (transportType === "http") {
53
- return createHTTPTransport(options);
44
+ return new StreamableHTTPClientTransport(url);
54
45
  }
55
46
  throw new Error(`Unsupported transport type: ${transportType}`);
56
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelcontextprotocol/inspector-cli",
3
- "version": "0.16.1",
3
+ "version": "0.16.3",
4
4
  "description": "CLI for the Model Context Protocol inspector",
5
5
  "license": "MIT",
6
6
  "author": "Anthropic, PBC (https://anthropic.com)",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "devDependencies": {},
23
23
  "dependencies": {
24
- "@modelcontextprotocol/sdk": "^1.13.1",
24
+ "@modelcontextprotocol/sdk": "^1.17.0",
25
25
  "commander": "^13.1.0",
26
26
  "spawn-rx": "^5.1.2"
27
27
  }