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,7 +161,8 @@ 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="flex-1">
|
||||||
<div className="p-4 bg-white shadow-md m-4 rounded-md">
|
<div className="p-4 bg-white shadow-md m-4 rounded-md">
|
||||||
<h2 className="text-lg font-semibold mb-2">Connect MCP Server</h2>
|
<h2 className="text-lg font-semibold mb-2">Connect MCP Server</h2>
|
||||||
<div className="flex space-x-2 mb-2">
|
<div className="flex space-x-2 mb-2">
|
||||||
@@ -228,6 +254,8 @@ const App = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<History requestHistory={requestHistory} />
|
||||||
|
</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