Merge pull request #8 from modelcontextprotocol/ashwin/history
add command history
This commit is contained in:
@@ -19,6 +19,7 @@ import ResourcesTab, { Resource } from "./components/ResourcesTab";
|
|||||||
import NotificationsTab from "./components/NotificationsTab";
|
import NotificationsTab from "./components/NotificationsTab";
|
||||||
import PromptsTab, { Prompt } from "./components/PromptsTab";
|
import PromptsTab, { Prompt } from "./components/PromptsTab";
|
||||||
import ToolsTab, { Tool as ToolType } from "./components/ToolsTab";
|
import ToolsTab, { Tool as ToolType } from "./components/ToolsTab";
|
||||||
|
import History from "./components/CommandHistory";
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const [socket, setSocket] = useState<WebSocket | null>(null);
|
const [socket, setSocket] = useState<WebSocket | null>(null);
|
||||||
@@ -39,6 +40,9 @@ const App = () => {
|
|||||||
"/Users/ashwin/code/example-servers/build/everything/index.js",
|
"/Users/ashwin/code/example-servers/build/everything/index.js",
|
||||||
);
|
);
|
||||||
const [mcpConnected, setMcpConnected] = useState<boolean>(false);
|
const [mcpConnected, setMcpConnected] = useState<boolean>(false);
|
||||||
|
const [requestHistory, setRequestHistory] = useState<
|
||||||
|
Array<{ request: string; response: string | null }>
|
||||||
|
>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const ws = new WebSocket("ws://localhost:3000");
|
const ws = new WebSocket("ws://localhost:3000");
|
||||||
@@ -75,6 +79,8 @@ const App = () => {
|
|||||||
} else if (message.type === "connected") {
|
} else if (message.type === "connected") {
|
||||||
setMcpConnected(true);
|
setMcpConnected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateRequestHistory(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = () => {
|
ws.onerror = () => {
|
||||||
@@ -89,10 +95,29 @@ const App = () => {
|
|||||||
return () => ws.close();
|
return () => ws.close();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const updateRequestHistory = (response: unknown) => {
|
||||||
|
setRequestHistory((prev) => {
|
||||||
|
const lastRequest = prev[prev.length - 1];
|
||||||
|
if (lastRequest && lastRequest.response === null) {
|
||||||
|
const updatedHistory = [...prev];
|
||||||
|
updatedHistory[updatedHistory.length - 1] = {
|
||||||
|
...lastRequest,
|
||||||
|
response: JSON.stringify(response),
|
||||||
|
};
|
||||||
|
return updatedHistory;
|
||||||
|
}
|
||||||
|
return prev;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const sendWebSocketMessage = (message: object) => {
|
const sendWebSocketMessage = (message: object) => {
|
||||||
if (socket) {
|
if (socket) {
|
||||||
console.log("Sending WebSocket message:", message);
|
console.log("Sending WebSocket message:", message);
|
||||||
socket.send(JSON.stringify(message));
|
socket.send(JSON.stringify(message));
|
||||||
|
setRequestHistory((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ request: JSON.stringify(message), response: null },
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -136,97 +161,100 @@ const App = () => {
|
|||||||
<Sidebar connectionStatus={connectionStatus} />
|
<Sidebar connectionStatus={connectionStatus} />
|
||||||
<div className="flex-1 flex flex-col overflow-hidden">
|
<div className="flex-1 flex flex-col overflow-hidden">
|
||||||
<h1 className="text-2xl font-bold p-4">MCP Inspector</h1>
|
<h1 className="text-2xl font-bold p-4">MCP Inspector</h1>
|
||||||
<div className="flex-1 overflow-auto">
|
<div className="flex-1 overflow-auto flex">
|
||||||
<div className="p-4 bg-white shadow-md m-4 rounded-md">
|
<div className="flex-1">
|
||||||
<h2 className="text-lg font-semibold mb-2">Connect MCP Server</h2>
|
<div className="p-4 bg-white shadow-md m-4 rounded-md">
|
||||||
<div className="flex space-x-2 mb-2">
|
<h2 className="text-lg font-semibold mb-2">Connect MCP Server</h2>
|
||||||
<Input
|
<div className="flex space-x-2 mb-2">
|
||||||
placeholder="Command"
|
<Input
|
||||||
value={command}
|
placeholder="Command"
|
||||||
onChange={(e) => setCommand(e.target.value)}
|
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}
|
|
||||||
/>
|
/>
|
||||||
<NotificationsTab />
|
<Input
|
||||||
<PromptsTab
|
placeholder="Arguments (space-separated)"
|
||||||
prompts={prompts}
|
value={args}
|
||||||
listPrompts={listPrompts}
|
onChange={(e) => setArgs(e.target.value)}
|
||||||
getPrompt={getPrompt}
|
|
||||||
selectedPrompt={selectedPrompt}
|
|
||||||
setSelectedPrompt={setSelectedPrompt}
|
|
||||||
promptContent={promptContent}
|
|
||||||
error={error}
|
|
||||||
/>
|
/>
|
||||||
<RequestsTab />
|
<Button onClick={connectMcpServer}>
|
||||||
<ToolsTab
|
<Play className="w-4 h-4 mr-2" />
|
||||||
tools={tools}
|
Connect
|
||||||
listTools={listTools}
|
</Button>
|
||||||
callTool={callTool}
|
|
||||||
selectedTool={selectedTool}
|
|
||||||
setSelectedTool={setSelectedTool}
|
|
||||||
toolResult={toolResult}
|
|
||||||
error={error}
|
|
||||||
/>
|
|
||||||
<ConsoleTab />
|
|
||||||
</div>
|
</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>
|
||||||
)}
|
{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>
|
||||||
</div>
|
</div>
|
||||||
|
<History requestHistory={requestHistory} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
94
client/src/components/History.tsx
Normal file
94
client/src/components/History.tsx
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { Copy } from "lucide-react";
|
||||||
|
|
||||||
|
const History = ({
|
||||||
|
requestHistory,
|
||||||
|
}: {
|
||||||
|
requestHistory: Array<{ request: string; response: string | null }>;
|
||||||
|
}) => {
|
||||||
|
const [expandedRequests, setExpandedRequests] = useState<{
|
||||||
|
[key: number]: boolean;
|
||||||
|
}>({});
|
||||||
|
|
||||||
|
const toggleRequestExpansion = (index: number) => {
|
||||||
|
setExpandedRequests((prev) => ({ ...prev, [index]: !prev[index] }));
|
||||||
|
};
|
||||||
|
|
||||||
|
const copyToClipboard = (text: string) => {
|
||||||
|
navigator.clipboard.writeText(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-64 bg-white shadow-md p-4 overflow-y-auto">
|
||||||
|
<h2 className="text-lg font-semibold mb-4">History</h2>
|
||||||
|
<ul className="space-y-3">
|
||||||
|
{requestHistory
|
||||||
|
.slice()
|
||||||
|
.reverse()
|
||||||
|
.map((request, index) => (
|
||||||
|
<li
|
||||||
|
key={index}
|
||||||
|
className="text-sm text-gray-600 bg-gray-100 p-2 rounded"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="flex justify-between items-center cursor-pointer"
|
||||||
|
onClick={() =>
|
||||||
|
toggleRequestExpansion(requestHistory.length - 1 - index)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span className="font-mono">
|
||||||
|
{requestHistory.length - index}.{" "}
|
||||||
|
{JSON.parse(request.request).type}
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
{expandedRequests[requestHistory.length - 1 - index]
|
||||||
|
? "▼"
|
||||||
|
: "▶"}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{expandedRequests[requestHistory.length - 1 - index] && (
|
||||||
|
<>
|
||||||
|
<div className="mt-2">
|
||||||
|
<div className="flex justify-between items-center mb-1">
|
||||||
|
<span className="font-semibold text-blue-600">
|
||||||
|
Request:
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => copyToClipboard(request.request)}
|
||||||
|
className="text-blue-500 hover:text-blue-700"
|
||||||
|
>
|
||||||
|
<Copy size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<pre className="whitespace-pre-wrap break-words bg-blue-50 p-2 rounded">
|
||||||
|
{JSON.stringify(JSON.parse(request.request), null, 2)}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
{request.response && (
|
||||||
|
<div className="mt-2">
|
||||||
|
<div className="flex justify-between items-center mb-1">
|
||||||
|
<span className="font-semibold text-green-600">
|
||||||
|
Response:
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={() => copyToClipboard(request.response!)}
|
||||||
|
className="text-blue-500 hover:text-blue-700"
|
||||||
|
>
|
||||||
|
<Copy size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<pre className="whitespace-pre-wrap break-words bg-green-50 p-2 rounded">
|
||||||
|
{JSON.stringify(JSON.parse(request.response), null, 2)}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default History;
|
||||||
Reference in New Issue
Block a user