561 lines
20 KiB
TypeScript
561 lines
20 KiB
TypeScript
import { useState } from "react";
|
||
import {
|
||
Play,
|
||
ChevronDown,
|
||
ChevronRight,
|
||
CircleHelp,
|
||
Bug,
|
||
Github,
|
||
Eye,
|
||
EyeOff,
|
||
RotateCcw,
|
||
Settings,
|
||
HelpCircle,
|
||
RefreshCwOff,
|
||
} from "lucide-react";
|
||
import { Button } from "@/components/ui/button";
|
||
import { Input } from "@/components/ui/input";
|
||
import {
|
||
Select,
|
||
SelectContent,
|
||
SelectItem,
|
||
SelectTrigger,
|
||
SelectValue,
|
||
} from "@/components/ui/select";
|
||
import { StdErrNotification } from "@/lib/notificationTypes";
|
||
import {
|
||
LoggingLevel,
|
||
LoggingLevelSchema,
|
||
} from "@modelcontextprotocol/sdk/types.js";
|
||
import { InspectorConfig } from "@/lib/configurationTypes";
|
||
import { ConnectionStatus } from "@/lib/constants";
|
||
import useTheme from "../lib/useTheme";
|
||
import { version } from "../../../package.json";
|
||
import {
|
||
Tooltip,
|
||
TooltipTrigger,
|
||
TooltipContent,
|
||
} from "@/components/ui/tooltip";
|
||
|
||
interface SidebarProps {
|
||
connectionStatus: ConnectionStatus;
|
||
transportType: "stdio" | "sse";
|
||
setTransportType: (type: "stdio" | "sse") => void;
|
||
command: string;
|
||
setCommand: (command: string) => void;
|
||
args: string;
|
||
setArgs: (args: string) => void;
|
||
sseUrl: string;
|
||
setSseUrl: (url: string) => void;
|
||
env: Record<string, string>;
|
||
setEnv: (env: Record<string, string>) => void;
|
||
bearerToken: string;
|
||
setBearerToken: (token: string) => void;
|
||
headerName?: string;
|
||
setHeaderName?: (name: string) => void;
|
||
onConnect: () => void;
|
||
onDisconnect: () => void;
|
||
stdErrNotifications: StdErrNotification[];
|
||
logLevel: LoggingLevel;
|
||
sendLogLevelRequest: (level: LoggingLevel) => void;
|
||
loggingSupported: boolean;
|
||
config: InspectorConfig;
|
||
setConfig: (config: InspectorConfig) => void;
|
||
}
|
||
|
||
const Sidebar = ({
|
||
connectionStatus,
|
||
transportType,
|
||
setTransportType,
|
||
command,
|
||
setCommand,
|
||
args,
|
||
setArgs,
|
||
sseUrl,
|
||
setSseUrl,
|
||
env,
|
||
setEnv,
|
||
bearerToken,
|
||
setBearerToken,
|
||
headerName,
|
||
setHeaderName,
|
||
onConnect,
|
||
onDisconnect,
|
||
stdErrNotifications,
|
||
logLevel,
|
||
sendLogLevelRequest,
|
||
loggingSupported,
|
||
config,
|
||
setConfig,
|
||
}: SidebarProps) => {
|
||
const [theme, setTheme] = useTheme();
|
||
const [showEnvVars, setShowEnvVars] = useState(false);
|
||
const [showBearerToken, setShowBearerToken] = useState(false);
|
||
const [showConfig, setShowConfig] = useState(false);
|
||
const [shownEnvVars, setShownEnvVars] = useState<Set<string>>(new Set());
|
||
|
||
return (
|
||
<div className="w-80 bg-card border-r border-border flex flex-col h-full">
|
||
<div className="flex items-center justify-between p-4 border-b border-gray-200">
|
||
<div className="flex items-center">
|
||
<h1 className="ml-2 text-lg font-semibold">
|
||
MCP Inspector v{version}
|
||
</h1>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="p-4 flex-1 overflow-auto">
|
||
<div className="space-y-4">
|
||
<div className="space-y-2">
|
||
<label className="text-sm font-medium">Transport Type</label>
|
||
<Select
|
||
value={transportType}
|
||
onValueChange={(value: "stdio" | "sse") =>
|
||
setTransportType(value)
|
||
}
|
||
>
|
||
<SelectTrigger>
|
||
<SelectValue placeholder="Select transport type" />
|
||
</SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="stdio">STDIO</SelectItem>
|
||
<SelectItem value="sse">SSE</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
</div>
|
||
|
||
{transportType === "stdio" ? (
|
||
<>
|
||
<div className="space-y-2">
|
||
<label className="text-sm font-medium">Command</label>
|
||
<Input
|
||
placeholder="Command"
|
||
value={command}
|
||
onChange={(e) => setCommand(e.target.value)}
|
||
className="font-mono"
|
||
/>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<label className="text-sm font-medium">Arguments</label>
|
||
<Input
|
||
placeholder="Arguments (space-separated)"
|
||
value={args}
|
||
onChange={(e) => setArgs(e.target.value)}
|
||
className="font-mono"
|
||
/>
|
||
</div>
|
||
</>
|
||
) : (
|
||
<>
|
||
<div className="space-y-2">
|
||
<label className="text-sm font-medium">URL</label>
|
||
<Input
|
||
placeholder="URL"
|
||
value={sseUrl}
|
||
onChange={(e) => setSseUrl(e.target.value)}
|
||
className="font-mono"
|
||
/>
|
||
</div>
|
||
<div className="space-y-2">
|
||
<Button
|
||
variant="outline"
|
||
onClick={() => setShowBearerToken(!showBearerToken)}
|
||
className="flex items-center w-full"
|
||
>
|
||
{showBearerToken ? (
|
||
<ChevronDown className="w-4 h-4 mr-2" />
|
||
) : (
|
||
<ChevronRight className="w-4 h-4 mr-2" />
|
||
)}
|
||
Authentication
|
||
</Button>
|
||
{showBearerToken && (
|
||
<div className="space-y-2">
|
||
<label className="text-sm font-medium">Header Name</label>
|
||
<Input
|
||
placeholder="Authorization"
|
||
onChange={(e) => setHeaderName && setHeaderName(e.target.value)}
|
||
className="font-mono"
|
||
value={headerName}
|
||
/>
|
||
<label className="text-sm font-medium">Bearer Token</label>
|
||
<Input
|
||
placeholder="Bearer Token"
|
||
value={bearerToken}
|
||
onChange={(e) => setBearerToken(e.target.value)}
|
||
className="font-mono"
|
||
type="password"
|
||
/>
|
||
</div>
|
||
)}
|
||
</div>
|
||
</>
|
||
)}
|
||
{transportType === "stdio" && (
|
||
<div className="space-y-2">
|
||
<Button
|
||
variant="outline"
|
||
onClick={() => setShowEnvVars(!showEnvVars)}
|
||
className="flex items-center w-full"
|
||
data-testid="env-vars-button"
|
||
>
|
||
{showEnvVars ? (
|
||
<ChevronDown className="w-4 h-4 mr-2" />
|
||
) : (
|
||
<ChevronRight className="w-4 h-4 mr-2" />
|
||
)}
|
||
Environment Variables
|
||
</Button>
|
||
{showEnvVars && (
|
||
<div className="space-y-2">
|
||
{Object.entries(env).map(([key, value], idx) => (
|
||
<div key={idx} className="space-y-2 pb-4">
|
||
<div className="flex gap-2">
|
||
<Input
|
||
placeholder="Key"
|
||
value={key}
|
||
onChange={(e) => {
|
||
const newKey = e.target.value;
|
||
const newEnv = Object.entries(env).reduce(
|
||
(acc, [k, v]) => {
|
||
if (k === key) {
|
||
acc[newKey] = value;
|
||
} else {
|
||
acc[k] = v;
|
||
}
|
||
return acc;
|
||
},
|
||
{} as Record<string, string>,
|
||
);
|
||
setEnv(newEnv);
|
||
setShownEnvVars((prev) => {
|
||
const next = new Set(prev);
|
||
if (next.has(key)) {
|
||
next.delete(key);
|
||
next.add(newKey);
|
||
}
|
||
return next;
|
||
});
|
||
}}
|
||
className="font-mono"
|
||
/>
|
||
<Button
|
||
variant="destructive"
|
||
size="icon"
|
||
className="h-9 w-9 p-0 shrink-0"
|
||
onClick={() => {
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||
const { [key]: _removed, ...rest } = env;
|
||
setEnv(rest);
|
||
}}
|
||
>
|
||
×
|
||
</Button>
|
||
</div>
|
||
<div className="flex gap-2">
|
||
<Input
|
||
type={shownEnvVars.has(key) ? "text" : "password"}
|
||
placeholder="Value"
|
||
value={value}
|
||
onChange={(e) => {
|
||
const newEnv = { ...env };
|
||
newEnv[key] = e.target.value;
|
||
setEnv(newEnv);
|
||
}}
|
||
className="font-mono"
|
||
/>
|
||
<Button
|
||
variant="outline"
|
||
size="icon"
|
||
className="h-9 w-9 p-0 shrink-0"
|
||
onClick={() => {
|
||
setShownEnvVars((prev) => {
|
||
const next = new Set(prev);
|
||
if (next.has(key)) {
|
||
next.delete(key);
|
||
} else {
|
||
next.add(key);
|
||
}
|
||
return next;
|
||
});
|
||
}}
|
||
aria-label={
|
||
shownEnvVars.has(key) ? "Hide value" : "Show value"
|
||
}
|
||
aria-pressed={shownEnvVars.has(key)}
|
||
title={
|
||
shownEnvVars.has(key) ? "Hide value" : "Show value"
|
||
}
|
||
>
|
||
{shownEnvVars.has(key) ? (
|
||
<Eye className="h-4 w-4" aria-hidden="true" />
|
||
) : (
|
||
<EyeOff className="h-4 w-4" aria-hidden="true" />
|
||
)}
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
))}
|
||
<Button
|
||
variant="outline"
|
||
className="w-full mt-2"
|
||
onClick={() => {
|
||
const key = "";
|
||
const newEnv = { ...env };
|
||
newEnv[key] = "";
|
||
setEnv(newEnv);
|
||
}}
|
||
>
|
||
Add Environment Variable
|
||
</Button>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{/* Configuration */}
|
||
<div className="space-y-2">
|
||
<Button
|
||
variant="outline"
|
||
onClick={() => setShowConfig(!showConfig)}
|
||
className="flex items-center w-full"
|
||
data-testid="config-button"
|
||
>
|
||
{showConfig ? (
|
||
<ChevronDown className="w-4 h-4 mr-2" />
|
||
) : (
|
||
<ChevronRight className="w-4 h-4 mr-2" />
|
||
)}
|
||
<Settings className="w-4 h-4 mr-2" />
|
||
Configuration
|
||
</Button>
|
||
{showConfig && (
|
||
<div className="space-y-2">
|
||
{Object.entries(config).map(([key, configItem]) => {
|
||
const configKey = key as keyof InspectorConfig;
|
||
return (
|
||
<div key={key} className="space-y-2">
|
||
<div className="flex items-center gap-1">
|
||
<label className="text-sm font-medium text-green-600">
|
||
{configKey}
|
||
</label>
|
||
<Tooltip>
|
||
<TooltipTrigger asChild>
|
||
<HelpCircle className="h-4 w-4 text-muted-foreground" />
|
||
</TooltipTrigger>
|
||
<TooltipContent>
|
||
{configItem.description}
|
||
</TooltipContent>
|
||
</Tooltip>
|
||
</div>
|
||
{typeof configItem.value === "number" ? (
|
||
<Input
|
||
type="number"
|
||
data-testid={`${configKey}-input`}
|
||
value={configItem.value}
|
||
onChange={(e) => {
|
||
const newConfig = { ...config };
|
||
newConfig[configKey] = {
|
||
...configItem,
|
||
value: Number(e.target.value),
|
||
};
|
||
setConfig(newConfig);
|
||
}}
|
||
className="font-mono"
|
||
/>
|
||
) : typeof configItem.value === "boolean" ? (
|
||
<Select
|
||
data-testid={`${configKey}-select`}
|
||
value={configItem.value.toString()}
|
||
onValueChange={(val) => {
|
||
const newConfig = { ...config };
|
||
newConfig[configKey] = {
|
||
...configItem,
|
||
value: val === "true",
|
||
};
|
||
setConfig(newConfig);
|
||
}}
|
||
>
|
||
<SelectTrigger>
|
||
<SelectValue />
|
||
</SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="true">True</SelectItem>
|
||
<SelectItem value="false">False</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
) : (
|
||
<Input
|
||
data-testid={`${configKey}-input`}
|
||
value={configItem.value}
|
||
onChange={(e) => {
|
||
const newConfig = { ...config };
|
||
newConfig[configKey] = {
|
||
...configItem,
|
||
value: e.target.value,
|
||
};
|
||
setConfig(newConfig);
|
||
}}
|
||
className="font-mono"
|
||
/>
|
||
)}
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
<div className="space-y-2">
|
||
{connectionStatus === "connected" && (
|
||
<div className="grid grid-cols-2 gap-4">
|
||
<Button data-testid="connect-button" onClick={onConnect}>
|
||
<RotateCcw className="w-4 h-4 mr-2" />
|
||
{transportType === "stdio" ? "Restart" : "Reconnect"}
|
||
</Button>
|
||
<Button onClick={onDisconnect}>
|
||
<RefreshCwOff className="w-4 h-4 mr-2" />
|
||
Disconnect
|
||
</Button>
|
||
</div>
|
||
)}
|
||
{connectionStatus !== "connected" && (
|
||
<Button className="w-full" onClick={onConnect}>
|
||
<Play className="w-4 h-4 mr-2" />
|
||
Connect
|
||
</Button>
|
||
)}
|
||
|
||
<div className="flex items-center justify-center space-x-2 mb-4">
|
||
<div
|
||
className={`w-2 h-2 rounded-full ${(() => {
|
||
switch (connectionStatus) {
|
||
case "connected":
|
||
return "bg-green-500";
|
||
case "error":
|
||
return "bg-red-500";
|
||
case "error-connecting-to-proxy":
|
||
return "bg-red-500";
|
||
default:
|
||
return "bg-gray-500";
|
||
}
|
||
})()}`}
|
||
/>
|
||
<span className="text-sm text-gray-600">
|
||
{(() => {
|
||
switch (connectionStatus) {
|
||
case "connected":
|
||
return "Connected";
|
||
case "error":
|
||
return "Connection Error, is your MCP server running?";
|
||
case "error-connecting-to-proxy":
|
||
return "Error Connecting to MCP Inspector Proxy - Check Console logs";
|
||
default:
|
||
return "Disconnected";
|
||
}
|
||
})()}
|
||
</span>
|
||
</div>
|
||
|
||
{loggingSupported && connectionStatus === "connected" && (
|
||
<div className="space-y-2">
|
||
<label className="text-sm font-medium">Logging Level</label>
|
||
<Select
|
||
value={logLevel}
|
||
onValueChange={(value: LoggingLevel) =>
|
||
sendLogLevelRequest(value)
|
||
}
|
||
>
|
||
<SelectTrigger>
|
||
<SelectValue placeholder="Select logging level" />
|
||
</SelectTrigger>
|
||
<SelectContent>
|
||
{Object.values(LoggingLevelSchema.enum).map((level) => (
|
||
<SelectItem value={level}>{level}</SelectItem>
|
||
))}
|
||
</SelectContent>
|
||
</Select>
|
||
</div>
|
||
)}
|
||
|
||
{stdErrNotifications.length > 0 && (
|
||
<>
|
||
<div className="mt-4 border-t border-gray-200 pt-4">
|
||
<h3 className="text-sm font-medium">
|
||
Error output from MCP server
|
||
</h3>
|
||
<div className="mt-2 max-h-80 overflow-y-auto">
|
||
{stdErrNotifications.map((notification, index) => (
|
||
<div
|
||
key={index}
|
||
className="text-sm text-red-500 font-mono py-2 border-b border-gray-200 last:border-b-0"
|
||
>
|
||
{notification.params.content}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div className="p-4 border-t">
|
||
<div className="flex items-center justify-between">
|
||
<Select
|
||
value={theme}
|
||
onValueChange={(value: string) =>
|
||
setTheme(value as "system" | "light" | "dark")
|
||
}
|
||
>
|
||
<SelectTrigger className="w-[100px]" id="theme-select">
|
||
<SelectValue />
|
||
</SelectTrigger>
|
||
<SelectContent>
|
||
<SelectItem value="system">System</SelectItem>
|
||
<SelectItem value="light">Light</SelectItem>
|
||
<SelectItem value="dark">Dark</SelectItem>
|
||
</SelectContent>
|
||
</Select>
|
||
|
||
<div className="flex items-center space-x-2">
|
||
<Button variant="ghost" title="Inspector Documentation" asChild>
|
||
<a
|
||
href="https://modelcontextprotocol.io/docs/tools/inspector"
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
>
|
||
<CircleHelp className="w-4 h-4 text-foreground" />
|
||
</a>
|
||
</Button>
|
||
<Button variant="ghost" title="Debugging Guide" asChild>
|
||
<a
|
||
href="https://modelcontextprotocol.io/docs/tools/debugging"
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
>
|
||
<Bug className="w-4 h-4 text-foreground" />
|
||
</a>
|
||
</Button>
|
||
<Button
|
||
variant="ghost"
|
||
title="Report bugs or contribute on GitHub"
|
||
asChild
|
||
>
|
||
<a
|
||
href="https://github.com/modelcontextprotocol/inspector"
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
>
|
||
<Github className="w-4 h-4 text-foreground" />
|
||
</a>
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default Sidebar;
|