@mcpjam/inspector 0.9.21 → 0.9.25

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/README.md CHANGED
@@ -80,6 +80,14 @@ The application will be available at `http://localhost:3001`.
80
80
 
81
81
  ## Connecting to MCP servers
82
82
 
83
+ ### mcp.json
84
+
85
+ You can import your `mcp.json` MCP server configs from Claude Desktop and Cursor with the command:
86
+
87
+ ```
88
+ npx @mcpjam/inspector@latest --config mcp.json
89
+ ```
90
+
83
91
  ### STDIO
84
92
 
85
93
  Note: Always use global file paths
package/bin/start.js CHANGED
@@ -5,7 +5,7 @@ import { spawn } from "child_process";
5
5
  import { fileURLToPath } from "url";
6
6
  import { createServer } from "net";
7
7
  import { execSync } from "child_process";
8
- import { existsSync } from "fs";
8
+ import { existsSync, readFileSync } from "fs";
9
9
 
10
10
  const __dirname = dirname(fileURLToPath(import.meta.url));
11
11
 
@@ -336,6 +336,8 @@ async function main() {
336
336
  let ollamaModel = null;
337
337
  let mcpServerCommand = null;
338
338
  let mcpServerArgs = [];
339
+ let mcpConfigFile = null;
340
+ let mcpServerName = null;
339
341
 
340
342
  for (let i = 0; i < args.length; i++) {
341
343
  const arg = args[i];
@@ -357,6 +359,16 @@ async function main() {
357
359
  continue;
358
360
  }
359
361
 
362
+ if (parsingFlags && arg === "--config" && i + 1 < args.length) {
363
+ mcpConfigFile = args[++i];
364
+ continue;
365
+ }
366
+
367
+ if (parsingFlags && arg === "--server" && i + 1 < args.length) {
368
+ mcpServerName = args[++i];
369
+ continue;
370
+ }
371
+
360
372
  if (parsingFlags && arg === "-e" && i + 1 < args.length) {
361
373
  const envVar = args[++i];
362
374
  const equalsIndex = envVar.indexOf("=");
@@ -380,8 +392,59 @@ async function main() {
380
392
  }
381
393
  }
382
394
 
383
- // Handle MCP server configuration if provided
384
- if (mcpServerCommand) {
395
+ // Handle MCP config file if provided
396
+ if (mcpConfigFile) {
397
+ logStep("MCP Server", `Configuring auto-connection to: ${mcpConfigFile}`);
398
+
399
+ try {
400
+ const configPath = resolve(mcpConfigFile);
401
+ if (!existsSync(configPath)) {
402
+ logError(`MCP config file not found: ${configPath}`);
403
+ process.exit(1);
404
+ }
405
+
406
+ const configContent = readFileSync(configPath, "utf-8");
407
+ const configData = JSON.parse(configContent);
408
+
409
+ if (
410
+ !configData.mcpServers ||
411
+ Object.keys(configData.mcpServers).length === 0
412
+ ) {
413
+ logWarning("No MCP servers found in config file");
414
+ } else {
415
+ // If --server flag is provided, validate it exists but don't filter config
416
+ if (mcpServerName) {
417
+ if (!configData.mcpServers[mcpServerName]) {
418
+ logError(
419
+ `Server '${mcpServerName}' not found in config file. Available servers: ${Object.keys(configData.mcpServers).join(", ")}`,
420
+ );
421
+ process.exit(1);
422
+ }
423
+ logInfo(`Auto-connecting only to server: ${mcpServerName}`);
424
+ // Pass the server filter separately
425
+ envVars.MCP_AUTO_CONNECT_SERVER = mcpServerName;
426
+ }
427
+
428
+ // Pass the full config (all servers will show in UI)
429
+ envVars.MCP_CONFIG_DATA = JSON.stringify(configData);
430
+ const serverCount = Object.keys(configData.mcpServers).length;
431
+ const serverNames = Object.keys(configData.mcpServers).join(", ");
432
+ logSuccess(
433
+ `MCP config loaded with ${serverCount} server(s) - showing all in UI`,
434
+ );
435
+ logInfo(`Servers: ${serverNames}`);
436
+ if (mcpServerName) {
437
+ logInfo(`Will auto-connect only to: ${mcpServerName}`);
438
+ } else {
439
+ logInfo(`Will auto-connect to all servers`);
440
+ }
441
+ }
442
+ } catch (error) {
443
+ logError(`Failed to read MCP config file: ${error.message}`);
444
+ process.exit(1);
445
+ }
446
+ } else if (mcpServerCommand) {
447
+ // Handle single MCP server command if provided (legacy mode)
385
448
  logStep(
386
449
  "MCP Server",
387
450
  `Configuring auto-connection to: ${mcpServerCommand} ${mcpServerArgs.join(" ")}`,
@@ -429,8 +492,8 @@ async function main() {
429
492
  // Apply parsed environment variables to process.env first
430
493
  Object.assign(process.env, envVars);
431
494
 
432
- // Port discovery and configuration
433
- const requestedPort = parseInt(process.env.PORT ?? "6274", 10);
495
+ // Port configuration (fixed default to 3000)
496
+ const requestedPort = parseInt(process.env.PORT ?? "3000", 10);
434
497
  let PORT;
435
498
 
436
499
  try {
@@ -450,18 +513,16 @@ async function main() {
450
513
  throw new Error(`Port ${requestedPort} is already in use`);
451
514
  }
452
515
  } else {
453
- // Dynamic port discovery
454
- logInfo("No specific port requested, using dynamic port discovery");
516
+ // Fixed port policy: use default port 3000 and fail fast if unavailable
517
+ logInfo("No specific port requested, using fixed default port 3000");
455
518
  if (await isPortAvailable(requestedPort)) {
456
519
  PORT = requestedPort.toString();
457
520
  logSuccess(`Default port ${requestedPort} is available`);
458
521
  } else {
459
- logWarning(
460
- `Default port ${requestedPort} is in use, searching for next available port...`,
522
+ logError(
523
+ `Default port ${requestedPort} is already in use. Please free the port`,
461
524
  );
462
- const availablePort = await findAvailablePort(requestedPort + 1);
463
- PORT = availablePort.toString();
464
- logSuccess(`Found available port: ${availablePort}`);
525
+ throw new Error(`Port ${requestedPort} is already in use`);
465
526
  }
466
527
  }
467
528