Skip to content

Commit 3bae267

Browse files
committed
Use toasts for errors unassociated with a tab
1 parent 9d0c643 commit 3bae267

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

client/src/App.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
Terminal,
5353
} from "lucide-react";
5454

55+
import { toast } from "react-toastify";
5556
import { ZodType } from "zod";
5657
import "./App.css";
5758
import ConsoleTab from "./components/ConsoleTab";
@@ -178,7 +179,7 @@ const App = () => {
178179
const makeRequest = async <T extends ZodType<object>>(
179180
request: ClientRequest,
180181
schema: T,
181-
tabKey: keyof typeof errors
182+
tabKey?: keyof typeof errors,
182183
) => {
183184
if (!mcpClient) {
184185
throw new Error("MCP client not connected");
@@ -187,10 +188,19 @@ const App = () => {
187188
try {
188189
const response = await mcpClient.request(request, schema);
189190
pushHistory(request, response);
190-
setErrors(prev => ({ ...prev, [tabKey]: null }));
191+
192+
if (tabKey !== undefined) {
193+
setErrors((prev) => ({ ...prev, [tabKey]: null }));
194+
}
195+
191196
return response;
192197
} catch (e: unknown) {
193-
setErrors(prev => ({ ...prev, [tabKey]: (e as Error).message }));
198+
if (tabKey === undefined) {
199+
toast.error((e as Error).message);
200+
} else {
201+
setErrors((prev) => ({ ...prev, [tabKey]: (e as Error).message }));
202+
}
203+
194204
throw e;
195205
}
196206
};
@@ -204,7 +214,7 @@ const App = () => {
204214
await mcpClient.notification(notification);
205215
pushHistory(notification);
206216
} catch (e: unknown) {
207-
setError((e as Error).message);
217+
toast.error((e as Error).message);
208218
throw e;
209219
}
210220
};
@@ -216,7 +226,7 @@ const App = () => {
216226
params: nextResourceCursor ? { cursor: nextResourceCursor } : {},
217227
},
218228
ListResourcesResultSchema,
219-
'resources'
229+
"resources",
220230
);
221231
setResources(resources.concat(response.resources ?? []));
222232
setNextResourceCursor(response.nextCursor);
@@ -231,7 +241,7 @@ const App = () => {
231241
: {},
232242
},
233243
ListResourceTemplatesResultSchema,
234-
'resources'
244+
"resources",
235245
);
236246
setResourceTemplates(
237247
resourceTemplates.concat(response.resourceTemplates ?? []),
@@ -246,7 +256,7 @@ const App = () => {
246256
params: { uri },
247257
},
248258
ReadResourceResultSchema,
249-
'resources'
259+
"resources",
250260
);
251261
setResourceContent(JSON.stringify(response, null, 2));
252262
};
@@ -258,7 +268,7 @@ const App = () => {
258268
params: nextPromptCursor ? { cursor: nextPromptCursor } : {},
259269
},
260270
ListPromptsResultSchema,
261-
'prompts'
271+
"prompts",
262272
);
263273
setPrompts(response.prompts);
264274
setNextPromptCursor(response.nextCursor);
@@ -271,7 +281,7 @@ const App = () => {
271281
params: { name, arguments: args },
272282
},
273283
GetPromptResultSchema,
274-
'prompts'
284+
"prompts",
275285
);
276286
setPromptContent(JSON.stringify(response, null, 2));
277287
};
@@ -283,7 +293,7 @@ const App = () => {
283293
params: nextToolCursor ? { cursor: nextToolCursor } : {},
284294
},
285295
ListToolsResultSchema,
286-
'tools'
296+
"tools",
287297
);
288298
setTools(response.tools);
289299
setNextToolCursor(response.nextCursor);
@@ -302,7 +312,7 @@ const App = () => {
302312
},
303313
},
304314
CompatibilityCallToolResultSchema,
305-
'tools'
315+
"tools",
306316
);
307317
setToolResult(response);
308318
};

client/src/main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
3+
import { ToastContainer } from 'react-toastify';
4+
import 'react-toastify/dist/ReactToastify.css';
35
import App from "./App.tsx";
46
import "./index.css";
57

68
createRoot(document.getElementById("root")!).render(
79
<StrictMode>
810
<App />
11+
<ToastContainer />
912
</StrictMode>,
1013
);

0 commit comments

Comments
 (0)