Skip to content

Commit bbf3a2a

Browse files
committed
Improve inspect command with optional server name
- Make server_name argument optional for inspect command - When no server specified, show helpful panel with options - Prompt user to confirm launching raw MCP Inspector - Provide clear guidance on inspecting MCPM-managed servers - Include examples: 'mcpm inspect filesystem', 'mcpm inspect time' - Show 'mcpm ls' command to discover available servers - Add yellow border panel to make the choice clear and actionable Example flow: mcpm inspect # Shows options, prompts for confirmation mcpm inspect filesystem # Direct inspection of specific server
1 parent 96a9c63 commit bbf3a2a

File tree

1 file changed

+78
-7
lines changed

1 file changed

+78
-7
lines changed

src/mcpm/commands/inspect.py

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,95 @@ def build_inspector_command(server_config, server_name):
3737
return inspector_cmd
3838

3939

40+
def launch_raw_inspector():
41+
"""Launch raw MCP Inspector without a specified server."""
42+
# Show information panel with options
43+
panel_content = """[bold]MCP Inspector without a specific server[/]
44+
45+
This will launch the raw MCP Inspector where you can manually configure
46+
the connection to any MCP server.
47+
48+
[bold]To inspect MCPM-managed servers instead:[/]
49+
• Run [cyan]mcpm ls[/] to see available servers
50+
• Run [cyan]mcpm inspect <server-name>[/] to inspect a specific server
51+
52+
Examples:
53+
[cyan]mcpm inspect filesystem[/] # Inspect filesystem server
54+
[cyan]mcpm inspect time[/] # Inspect time server
55+
56+
[bold yellow]Continue with raw inspector?[/]"""
57+
58+
panel = Panel(
59+
panel_content,
60+
title="🔍 MCP Inspector",
61+
border_style="yellow",
62+
padding=(1, 2)
63+
)
64+
console.print(panel)
65+
66+
# Prompt for confirmation
67+
try:
68+
confirm = click.confirm("Launch raw MCP Inspector", default=True)
69+
if not confirm:
70+
console.print("[yellow]Cancelled.[/]")
71+
sys.exit(0)
72+
except (KeyboardInterrupt, EOFError):
73+
console.print("\n[yellow]Cancelled.[/]")
74+
sys.exit(0)
75+
76+
# Launch raw inspector
77+
raw_inspector_cmd = f"{NPX_CMD} @modelcontextprotocol/inspector"
78+
79+
console.print("\n[bold]Launching raw MCP Inspector...[/]")
80+
console.print("The Inspector UI will open in your web browser.")
81+
console.print("[yellow]Press Ctrl+C to stop the Inspector.[/]")
82+
83+
try:
84+
console.print(f"[dim]Executing: {raw_inspector_cmd}[/]")
85+
cmd_parts = shlex.split(raw_inspector_cmd)
86+
returncode = subprocess.call(cmd_parts)
87+
88+
if returncode == 0:
89+
console.print("[bold green]Inspector process completed successfully.[/]")
90+
elif returncode in (130, -2):
91+
console.print("[bold yellow]Inspector process was terminated.[/]")
92+
else:
93+
console.print(f"[bold red]Inspector process exited with code {returncode}[/]")
94+
95+
sys.exit(returncode)
96+
97+
except KeyboardInterrupt:
98+
console.print("\n[bold yellow]Inspector process terminated by keyboard interrupt.[/]")
99+
sys.exit(130)
100+
except FileNotFoundError:
101+
console.print("[bold red]Error:[/] Could not find npx. Please make sure Node.js is installed.")
102+
console.print("Install Node.js from https://nodejs.org/")
103+
sys.exit(1)
104+
except Exception as e:
105+
console.print(f"[bold red]Error launching Inspector:[/] {str(e)}")
106+
sys.exit(1)
107+
108+
40109
@click.command()
41-
@click.argument("server_name")
110+
@click.argument("server_name", required=False)
42111
@click.help_option("-h", "--help")
43112
def inspect(server_name):
44113
"""Launch MCP Inspector to test and debug a server from global configuration.
45114
46-
Finds the specified server in the global configuration and launches
47-
the MCP Inspector with the correct configuration to connect to and test the server.
115+
If SERVER_NAME is provided, finds the specified server in the global configuration
116+
and launches the MCP Inspector with the correct configuration to connect to and test the server.
117+
118+
If no SERVER_NAME is provided, launches the raw MCP Inspector for manual configuration.
48119
49120
Examples:
50-
mcpm inspect mcp-server-browse # Inspect the browse server
121+
mcpm inspect # Launch raw inspector (manual setup)
122+
mcpm inspect mcp-server-browse # Inspect the browse server
51123
mcpm inspect filesystem # Inspect filesystem server
52124
mcpm inspect time # Inspect the time server
53125
"""
54-
# Validate server name
126+
# Handle case where no server name is provided
55127
if not server_name or not server_name.strip():
56-
console.print("[red]Error: Server name cannot be empty[/]")
57-
sys.exit(1)
128+
return launch_raw_inspector()
58129

59130
server_name = server_name.strip()
60131

0 commit comments

Comments
 (0)