Skip to content

Commit d91d7e8

Browse files
committed
Add default request timeout
1 parent 6c27f5a commit d91d7e8

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

client/src/App.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import SamplingTab, { PendingRequest } from "./components/SamplingTab";
5353
import Sidebar from "./components/Sidebar";
5454
import ToolsTab from "./components/ToolsTab";
5555

56+
const DEFAULT_REQUEST_TIMEOUT_MSEC = 10000;
57+
5658
const App = () => {
5759
const [connectionStatus, setConnectionStatus] = useState<
5860
"disconnected" | "connected" | "error"
@@ -220,7 +222,19 @@ const App = () => {
220222
}
221223

222224
try {
223-
const response = await mcpClient.request(request, schema);
225+
const abortController = new AbortController();
226+
const timeoutId = setTimeout(() => {
227+
abortController.abort("Request timed out");
228+
}, DEFAULT_REQUEST_TIMEOUT_MSEC);
229+
230+
let response;
231+
try {
232+
response = await mcpClient.request(request, schema, {
233+
signal: abortController.signal,
234+
});
235+
} finally {
236+
clearTimeout(timeoutId);
237+
}
224238
pushHistory(request, response);
225239

226240
if (tabKey !== undefined) {
@@ -229,10 +243,14 @@ const App = () => {
229243

230244
return response;
231245
} catch (e: unknown) {
246+
const errorString = (e as Error).message ?? String(e);
232247
if (tabKey === undefined) {
233-
toast.error((e as Error).message);
248+
toast.error(errorString);
234249
} else {
235-
setErrors((prev) => ({ ...prev, [tabKey]: (e as Error).message }));
250+
setErrors((prev) => ({
251+
...prev,
252+
[tabKey]: errorString,
253+
}));
236254
}
237255

238256
throw e;
@@ -248,7 +266,7 @@ const App = () => {
248266
await mcpClient.notification(notification);
249267
pushHistory(notification);
250268
} catch (e: unknown) {
251-
toast.error((e as Error).message);
269+
toast.error((e as Error).message ?? String(e));
252270
throw e;
253271
}
254272
};

0 commit comments

Comments
 (0)