Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions client/src/App.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
Comment on lines -2 to -5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird default CSS that was causing the window to look weird at large sizes

}

.logo {
Expand Down
40 changes: 29 additions & 11 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
Resource,
Tool,
ClientRequest,
ProgressNotificationSchema,
ServerNotification,
} from "mcp-typescript/types.js";
import { useState } from "react";
import { useState, useRef } from "react";
import {
Send,
Bell,
Expand All @@ -36,11 +38,11 @@ import ConsoleTab from "./components/ConsoleTab";
import Sidebar from "./components/Sidebar";
import RequestsTab from "./components/RequestsTabs";
import ResourcesTab from "./components/ResourcesTab";
import NotificationsTab from "./components/NotificationsTab";
import PromptsTab, { Prompt } from "./components/PromptsTab";
import ToolsTab from "./components/ToolsTab";
import History from "./components/History";
import { AnyZodObject } from "zod";
import HistoryAndNotifications from "./components/History";
import "./App.css";

const App = () => {
const [connectionStatus, setConnectionStatus] = useState<
Expand All @@ -57,20 +59,22 @@ const App = () => {
"/Users/ashwin/.nvm/versions/node/v18.20.4/bin/node",
);
const [args, setArgs] = useState<string>(
"/Users/ashwin/code/example-servers/build/everything/stdio.js",
"/Users/ashwin/code/mcp/example-servers/build/everything/stdio.js",
);
const [url, setUrl] = useState<string>("http://localhost:3001/sse");
const [transportType, setTransportType] = useState<"stdio" | "sse">("stdio");
const [requestHistory, setRequestHistory] = useState<
{ request: string; response: string }[]
>([]);
const [mcpClient, setMcpClient] = useState<Client | null>(null);
const [notifications, setNotifications] = useState<ServerNotification[]>([]);

const [selectedResource, setSelectedResource] = useState<Resource | null>(
null,
);
const [selectedPrompt, setSelectedPrompt] = useState<Prompt | null>(null);
const [selectedTool, setSelectedTool] = useState<Tool | null>(null);
const progressTokenRef = useRef(0);

const pushHistory = (request: object, response: object) => {
setRequestHistory((prev) => [
Expand Down Expand Up @@ -155,7 +159,13 @@ const App = () => {
const response = await makeRequest(
{
method: "tools/call" as const,
params: { name, arguments: params },
params: {
name,
arguments: params,
_meta: {
progressToken: progressTokenRef.current++,
},
},
},
CallToolResultSchema,
);
Expand All @@ -182,6 +192,16 @@ const App = () => {
const clientTransport = new SSEClientTransport(backendUrl);
await client.connect(clientTransport);

client.setNotificationHandler(
ProgressNotificationSchema,
(notification) => {
setNotifications((prevNotifications) => [
...prevNotifications,
notification,
]);
},
);

setMcpClient(client);
setConnectionStatus("connected");
} catch (e) {
Expand Down Expand Up @@ -255,10 +275,6 @@ const App = () => {
<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">
<Hammer className="w-4 h-4 mr-2" />
Tools
Expand All @@ -279,7 +295,6 @@ const App = () => {
resourceContent={resourceContent}
error={error}
/>
<NotificationsTab />
<PromptsTab
prompts={prompts}
listPrompts={listPrompts}
Expand Down Expand Up @@ -315,7 +330,10 @@ const App = () => {
</div>
</div>
</div>
<History requestHistory={requestHistory} />
<HistoryAndNotifications
requestHistory={requestHistory}
serverNotifications={notifications}
/>
</div>
);
};
Expand Down
183 changes: 126 additions & 57 deletions client/src/components/History.tsx
Original file line number Diff line number Diff line change
@@ -1,94 +1,163 @@
import { useState } from "react";
import { Copy } from "lucide-react";
import { ServerNotification } from "mcp-typescript/types.js";

const History = ({
const HistoryAndNotifications = ({
requestHistory,
serverNotifications,
}: {
requestHistory: Array<{ request: string; response: string | null }>;
serverNotifications: ServerNotification[];
}) => {
const [expandedRequests, setExpandedRequests] = useState<{
[key: number]: boolean;
}>({});
const [expandedNotifications, setExpandedNotifications] = useState<{
[key: number]: boolean;
}>({});

const toggleRequestExpansion = (index: number) => {
setExpandedRequests((prev) => ({ ...prev, [index]: !prev[index] }));
};

const toggleNotificationExpansion = (index: number) => {
setExpandedNotifications((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).method}
</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 className="w-64 bg-white shadow-md p-4 overflow-hidden flex flex-col h-full">
<div className="flex-1 overflow-y-auto mb-4 border-b pb-4">
<h2 className="text-lg font-semibold mb-4">History</h2>
{requestHistory.length === 0 ? (
<p className="text-sm text-gray-500 italic">No history yet</p>
) : (
<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).method}
</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>
Comment on lines +32 to +109
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The joy of Tailwind 🤮 Nothing has changed here, just some light touch-ups to make the History list only take up the top half of the right sidebar.

<div className="flex-1 overflow-y-auto">
<h2 className="text-lg font-semibold mb-4">Server Notifications</h2>
{serverNotifications.length === 0 ? (
<p className="text-sm text-gray-500 italic">No notifications yet</p>
) : (
<ul className="space-y-3">
{serverNotifications
.slice()
.reverse()
.map((notification, 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={() => toggleNotificationExpansion(index)}
>
<span className="font-mono">
{serverNotifications.length - index}.{" "}
{notification.method}
</span>
<span>{expandedNotifications[index] ? "▼" : "▶"}</span>
</div>
{request.response && (
{expandedNotifications[index] && (
<div className="mt-2">
<div className="flex justify-between items-center mb-1">
<span className="font-semibold text-green-600">
Response:
<span className="font-semibold text-purple-600">
Details:
</span>
<button
onClick={() => copyToClipboard(request.response!)}
onClick={() =>
copyToClipboard(JSON.stringify(notification))
}
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 className="whitespace-pre-wrap break-words bg-purple-50 p-2 rounded">
{JSON.stringify(notification, null, 2)}
</pre>
</div>
)}
</>
)}
</li>
))}
</ul>
</li>
))}
</ul>
)}
</div>
</div>
);
};

export default History;
export default HistoryAndNotifications;
33 changes: 0 additions & 33 deletions client/src/components/NotificationsTab.tsx

This file was deleted.

4 changes: 3 additions & 1 deletion client/src/components/ToolsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const ToolsTab = ({
renderItem={(tool) => (
<>
<span className="flex-1">{tool.name}</span>
<span className="text-sm text-gray-500">{tool.description}</span>
<span className="text-sm text-gray-500 text-right">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right-aligning the description text because it looks better

{tool.description}
</span>
</>
)}
title="Tools"
Expand Down
1 change: 0 additions & 1 deletion client/tsconfig.node.tsbuildinfo

This file was deleted.

Loading