add command history
This commit is contained in:
@@ -19,6 +19,7 @@ import ResourcesTab, { Resource } from "./components/ResourcesTab";
|
||||
import NotificationsTab from "./components/NotificationsTab";
|
||||
import PromptsTab, { Prompt } from "./components/PromptsTab";
|
||||
import ToolsTab, { Tool as ToolType } from "./components/ToolsTab";
|
||||
import CommandHistory from "./components/CommandHistory";
|
||||
|
||||
const App = () => {
|
||||
const [socket, setSocket] = useState<WebSocket | null>(null);
|
||||
@@ -39,6 +40,9 @@ const App = () => {
|
||||
"/Users/ashwin/code/example-servers/build/everything/index.js",
|
||||
);
|
||||
const [mcpConnected, setMcpConnected] = useState<boolean>(false);
|
||||
const [commandHistory, setCommandHistory] = useState<
|
||||
Array<{ command: string; response: string | null }>
|
||||
>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const ws = new WebSocket("ws://localhost:3000");
|
||||
@@ -55,25 +59,33 @@ const App = () => {
|
||||
if (message.type === "resources") {
|
||||
setResources(message.data.resources);
|
||||
setError(null);
|
||||
updateCommandHistory(message);
|
||||
} else if (message.type === "resource") {
|
||||
setResourceContent(JSON.stringify(message.data, null, 2));
|
||||
setError(null);
|
||||
updateCommandHistory(message);
|
||||
} else if (message.type === "prompts") {
|
||||
setPrompts(message.data.prompts);
|
||||
setError(null);
|
||||
updateCommandHistory(message);
|
||||
} else if (message.type === "prompt") {
|
||||
setPromptContent(JSON.stringify(message.data, null, 2));
|
||||
setError(null);
|
||||
updateCommandHistory(message);
|
||||
} else if (message.type === "tools") {
|
||||
setTools(message.data.tools);
|
||||
setError(null);
|
||||
updateCommandHistory(message);
|
||||
} else if (message.type === "toolResult") {
|
||||
setToolResult(JSON.stringify(message.data, null, 2));
|
||||
setError(null);
|
||||
updateCommandHistory(message);
|
||||
} else if (message.type === "error") {
|
||||
setError(message.message);
|
||||
updateCommandHistory(message);
|
||||
} else if (message.type === "connected") {
|
||||
setMcpConnected(true);
|
||||
updateCommandHistory(message);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -89,10 +101,29 @@ const App = () => {
|
||||
return () => ws.close();
|
||||
}, []);
|
||||
|
||||
const updateCommandHistory = (response: unknown) => {
|
||||
setCommandHistory((prev) => {
|
||||
const lastCommand = prev[prev.length - 1];
|
||||
if (lastCommand && lastCommand.response === null) {
|
||||
const updatedHistory = [...prev];
|
||||
updatedHistory[updatedHistory.length - 1] = {
|
||||
...lastCommand,
|
||||
response: JSON.stringify(response),
|
||||
};
|
||||
return updatedHistory;
|
||||
}
|
||||
return prev;
|
||||
});
|
||||
};
|
||||
|
||||
const sendWebSocketMessage = (message: object) => {
|
||||
if (socket) {
|
||||
console.log("Sending WebSocket message:", message);
|
||||
socket.send(JSON.stringify(message));
|
||||
setCommandHistory((prev) => [
|
||||
...prev,
|
||||
{ command: JSON.stringify(message), response: null },
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -136,97 +167,100 @@ const App = () => {
|
||||
<Sidebar connectionStatus={connectionStatus} />
|
||||
<div className="flex-1 flex flex-col overflow-hidden">
|
||||
<h1 className="text-2xl font-bold p-4">MCP Inspector</h1>
|
||||
<div className="flex-1 overflow-auto">
|
||||
<div className="p-4 bg-white shadow-md m-4 rounded-md">
|
||||
<h2 className="text-lg font-semibold mb-2">Connect MCP Server</h2>
|
||||
<div className="flex space-x-2 mb-2">
|
||||
<Input
|
||||
placeholder="Command"
|
||||
value={command}
|
||||
onChange={(e) => setCommand(e.target.value)}
|
||||
/>
|
||||
<Input
|
||||
placeholder="Arguments (space-separated)"
|
||||
value={args}
|
||||
onChange={(e) => setArgs(e.target.value)}
|
||||
/>
|
||||
<Button onClick={connectMcpServer}>
|
||||
<Play className="w-4 h-4 mr-2" />
|
||||
Connect
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{mcpConnected ? (
|
||||
<Tabs defaultValue="resources" className="w-full p-4">
|
||||
<TabsList className="mb-4 p-0">
|
||||
<TabsTrigger value="resources">
|
||||
<Files className="w-4 h-4 mr-2" />
|
||||
Resources
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="prompts">
|
||||
<MessageSquare className="w-4 h-4 mr-2" />
|
||||
Prompts
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="requests" disabled>
|
||||
<Send className="w-4 h-4 mr-2" />
|
||||
Requests
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="notifications" disabled>
|
||||
<Bell className="w-4 h-4 mr-2" />
|
||||
Notifications
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="tools" disabled>
|
||||
<Hammer className="w-4 h-4 mr-2" />
|
||||
Tools
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="console" disabled>
|
||||
<Terminal className="w-4 h-4 mr-2" />
|
||||
Console
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<div className="w-full">
|
||||
<ResourcesTab
|
||||
resources={resources}
|
||||
listResources={listResources}
|
||||
readResource={readResource}
|
||||
selectedResource={selectedResource}
|
||||
setSelectedResource={setSelectedResource}
|
||||
resourceContent={resourceContent}
|
||||
error={error}
|
||||
<div className="flex-1 overflow-auto flex">
|
||||
<div className="flex-1">
|
||||
<div className="p-4 bg-white shadow-md m-4 rounded-md">
|
||||
<h2 className="text-lg font-semibold mb-2">Connect MCP Server</h2>
|
||||
<div className="flex space-x-2 mb-2">
|
||||
<Input
|
||||
placeholder="Command"
|
||||
value={command}
|
||||
onChange={(e) => setCommand(e.target.value)}
|
||||
/>
|
||||
<NotificationsTab />
|
||||
<PromptsTab
|
||||
prompts={prompts}
|
||||
listPrompts={listPrompts}
|
||||
getPrompt={getPrompt}
|
||||
selectedPrompt={selectedPrompt}
|
||||
setSelectedPrompt={setSelectedPrompt}
|
||||
promptContent={promptContent}
|
||||
error={error}
|
||||
<Input
|
||||
placeholder="Arguments (space-separated)"
|
||||
value={args}
|
||||
onChange={(e) => setArgs(e.target.value)}
|
||||
/>
|
||||
<RequestsTab />
|
||||
<ToolsTab
|
||||
tools={tools}
|
||||
listTools={listTools}
|
||||
callTool={callTool}
|
||||
selectedTool={selectedTool}
|
||||
setSelectedTool={setSelectedTool}
|
||||
toolResult={toolResult}
|
||||
error={error}
|
||||
/>
|
||||
<ConsoleTab />
|
||||
<Button onClick={connectMcpServer}>
|
||||
<Play className="w-4 h-4 mr-2" />
|
||||
Connect
|
||||
</Button>
|
||||
</div>
|
||||
</Tabs>
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-full">
|
||||
<p className="text-lg text-gray-500">
|
||||
Connect to an MCP server to start inspecting
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{mcpConnected ? (
|
||||
<Tabs defaultValue="resources" className="w-full p-4">
|
||||
<TabsList className="mb-4 p-0">
|
||||
<TabsTrigger value="resources">
|
||||
<Files className="w-4 h-4 mr-2" />
|
||||
Resources
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="prompts">
|
||||
<MessageSquare className="w-4 h-4 mr-2" />
|
||||
Prompts
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="requests" disabled>
|
||||
<Send className="w-4 h-4 mr-2" />
|
||||
Requests
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="notifications" disabled>
|
||||
<Bell className="w-4 h-4 mr-2" />
|
||||
Notifications
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="tools" disabled>
|
||||
<Hammer className="w-4 h-4 mr-2" />
|
||||
Tools
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="console" disabled>
|
||||
<Terminal className="w-4 h-4 mr-2" />
|
||||
Console
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<div className="w-full">
|
||||
<ResourcesTab
|
||||
resources={resources}
|
||||
listResources={listResources}
|
||||
readResource={readResource}
|
||||
selectedResource={selectedResource}
|
||||
setSelectedResource={setSelectedResource}
|
||||
resourceContent={resourceContent}
|
||||
error={error}
|
||||
/>
|
||||
<NotificationsTab />
|
||||
<PromptsTab
|
||||
prompts={prompts}
|
||||
listPrompts={listPrompts}
|
||||
getPrompt={getPrompt}
|
||||
selectedPrompt={selectedPrompt}
|
||||
setSelectedPrompt={setSelectedPrompt}
|
||||
promptContent={promptContent}
|
||||
error={error}
|
||||
/>
|
||||
<RequestsTab />
|
||||
<ToolsTab
|
||||
tools={tools}
|
||||
listTools={listTools}
|
||||
callTool={callTool}
|
||||
selectedTool={selectedTool}
|
||||
setSelectedTool={setSelectedTool}
|
||||
toolResult={toolResult}
|
||||
error={error}
|
||||
/>
|
||||
<ConsoleTab />
|
||||
</div>
|
||||
</Tabs>
|
||||
) : (
|
||||
<div className="flex items-center justify-center h-full">
|
||||
<p className="text-lg text-gray-500">
|
||||
Connect to an MCP server to start inspecting
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<CommandHistory commandHistory={commandHistory} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user