Skip to content

Commit 79ba164

Browse files
authored
Merge pull request modelcontextprotocol#108 from 8enmann/ben/persist
feat: improve request history and tab persistence
2 parents 0346995 + 2f513df commit 79ba164

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

client/src/App.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ const DEFAULT_REQUEST_TIMEOUT_MSEC = 10000;
5959

6060
const params = new URLSearchParams(window.location.search);
6161
const PROXY_PORT = params.get("proxyPort") ?? "3000";
62-
const REQUEST_TIMEOUT = parseInt(params.get("timeout") ?? "") || DEFAULT_REQUEST_TIMEOUT_MSEC;
62+
const REQUEST_TIMEOUT =
63+
parseInt(params.get("timeout") ?? "") || DEFAULT_REQUEST_TIMEOUT_MSEC;
6364
const PROXY_SERVER_URL = `http://localhost:${PROXY_PORT}`;
6465

6566
const App = () => {
@@ -217,6 +218,12 @@ const App = () => {
217218
rootsRef.current = roots;
218219
}, [roots]);
219220

221+
useEffect(() => {
222+
if (!window.location.hash) {
223+
window.location.hash = "resources";
224+
}
225+
}, []);
226+
220227
const pushHistory = (request: object, response?: object) => {
221228
setRequestHistory((prev) => [
222229
...prev,
@@ -251,10 +258,14 @@ const App = () => {
251258
response = await mcpClient.request(request, schema, {
252259
signal: abortController.signal,
253260
});
261+
pushHistory(request, response);
262+
} catch (error) {
263+
const errorMessage = error instanceof Error ? error.message : String(error);
264+
pushHistory(request, { error: errorMessage });
265+
throw error;
254266
} finally {
255267
clearTimeout(timeoutId);
256268
}
257-
pushHistory(request, response);
258269

259270
if (tabKey !== undefined) {
260271
clearError(tabKey);
@@ -485,7 +496,11 @@ const App = () => {
485496
<div className="flex-1 flex flex-col overflow-hidden">
486497
<div className="flex-1 overflow-auto">
487498
{mcpClient ? (
488-
<Tabs defaultValue="resources" className="w-full p-4">
499+
<Tabs
500+
defaultValue={window.location.hash.slice(1) || "resources"}
501+
className="w-full p-4"
502+
onValueChange={(value) => (window.location.hash = value)}
503+
>
489504
<TabsList className="mb-4 p-0">
490505
<TabsTrigger value="resources">
491506
<Files className="w-4 h-4 mr-2" />

0 commit comments

Comments
 (0)