Skip to content
Open
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
11 changes: 9 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Task,
GetTaskResultSchema,
} from "@modelcontextprotocol/sdk/types.js";
import { TimestampedNotification } from "./lib/notificationTypes";
import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
import type {
AnySchema,
Expand Down Expand Up @@ -154,7 +155,9 @@ const App = () => {
},
);
const [logLevel, setLogLevel] = useState<LoggingLevel>("debug");
const [notifications, setNotifications] = useState<ServerNotification[]>([]);
const [notifications, setNotifications] = useState<TimestampedNotification[]>(
[],
);
const [roots, setRoots] = useState<Root[]>([]);
const [env, setEnv] = useState<Record<string, string>>({});

Expand Down Expand Up @@ -366,7 +369,11 @@ const App = () => {
config,
connectionType,
onNotification: (notification) => {
setNotifications((prev) => [...prev, notification as ServerNotification]);
const timestamped: TimestampedNotification = {
notification: notification as ServerNotification,
receivedAt: new Date().toISOString(),
};
setNotifications((prev) => [...prev, timestamped]);

if (notification.method === "notifications/tasks/list_changed") {
void listTasks();
Expand Down
69 changes: 55 additions & 14 deletions client/src/components/HistoryAndNotifications.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { ServerNotification } from "@modelcontextprotocol/sdk/types.js";
import { useState } from "react";
import JsonView from "./JsonView";
import { Button } from "@/components/ui/button";
import { RequestHistoryEntry } from "@/lib/types/requestHistory";
import { TimestampedNotification } from "@/lib/notificationTypes";
import {
formatDuration,
formatTimestamp,
formatTimestampFull,
} from "@/utils/timeUtils";

const HistoryAndNotifications = ({
requestHistory,
serverNotifications,
onClearHistory,
onClearNotifications,
}: {
requestHistory: Array<{ request: string; response?: string }>;
serverNotifications: ServerNotification[];
requestHistory: RequestHistoryEntry[];
serverNotifications: TimestampedNotification[];
onClearHistory?: () => void;
onClearNotifications?: () => void;
}) => {
Expand Down Expand Up @@ -52,7 +58,7 @@ const HistoryAndNotifications = ({
{requestHistory
.slice()
.reverse()
.map((request, index) => (
.map((entry, index) => (
<li
key={index}
className="text-sm text-foreground bg-secondary py-2 px-3 rounded"
Expand All @@ -63,18 +69,44 @@ const HistoryAndNotifications = ({
toggleRequestExpansion(requestHistory.length - 1 - index)
}
>
<span className="font-mono">
<span className="font-mono flex items-center gap-2">
{requestHistory.length - index}.{" "}
{JSON.parse(request.request).method}
{JSON.parse(entry.request).method}
{entry.durationMs !== undefined && (
<span className="text-xs bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300 px-1.5 py-0.5 rounded-full">
{formatDuration(entry.durationMs)}
</span>
)}
</span>
<span>
<span className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">
{formatTimestamp(entry.requestedAt)}
</span>
{expandedRequests[requestHistory.length - 1 - index]
? "▼"
: "▶"}
</span>
</div>
{expandedRequests[requestHistory.length - 1 - index] && (
<>
<div className="mt-2 pt-2 border-t border-border">
<div className="text-xs text-muted-foreground mb-2 space-y-1">
<div>
Requested: {formatTimestampFull(entry.requestedAt)}
</div>
{entry.respondedAt && (
<div>
Responded:{" "}
{formatTimestampFull(entry.respondedAt)}
{entry.durationMs !== undefined && (
<span className="ml-1">
({formatDuration(entry.durationMs)})
</span>
)}
</div>
)}
</div>
</div>
<div className="mt-2">
<div className="flex justify-between items-center mb-1">
<span className="font-semibold text-blue-600">
Expand All @@ -83,19 +115,19 @@ const HistoryAndNotifications = ({
</div>

<JsonView
data={request.request}
data={entry.request}
className="bg-background"
/>
</div>
{request.response && (
{entry.response && (
<div className="mt-2">
<div className="flex justify-between items-center mb-1">
<span className="font-semibold text-green-600">
Response:
</span>
</div>
<JsonView
data={request.response}
data={entry.response}
className="bg-background"
/>
</div>
Expand Down Expand Up @@ -128,7 +160,7 @@ const HistoryAndNotifications = ({
{serverNotifications
.slice()
.reverse()
.map((notification, index) => (
.map((timestamped, index) => (
<li
key={index}
className="text-sm text-foreground bg-secondary py-2 px-3 rounded"
Expand All @@ -143,9 +175,12 @@ const HistoryAndNotifications = ({
>
<span className="font-mono">
{serverNotifications.length - index}.{" "}
{notification.method}
{timestamped.notification.method}
</span>
<span>
<span className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">
{formatTimestamp(timestamped.receivedAt)}
</span>
{expandedNotifications[
serverNotifications.length - 1 - index
]
Expand All @@ -157,13 +192,19 @@ const HistoryAndNotifications = ({
serverNotifications.length - 1 - index
] && (
<div className="mt-2">
<div className="pt-2 border-t border-border">
<div className="text-xs text-muted-foreground mb-2">
Received:{" "}
{formatTimestampFull(timestamped.receivedAt)}
</div>
</div>
<div className="flex justify-between items-center mb-1">
<span className="font-semibold text-purple-600">
Details:
</span>
</div>
<JsonView
data={JSON.stringify(notification, null, 2)}
data={JSON.stringify(timestamped.notification, null, 2)}
className="bg-background"
/>
</div>
Expand Down
Loading