@@ -53,6 +53,8 @@ import SamplingTab, { PendingRequest } from "./components/SamplingTab";
53
53
import Sidebar from "./components/Sidebar" ;
54
54
import ToolsTab from "./components/ToolsTab" ;
55
55
56
+ const DEFAULT_REQUEST_TIMEOUT_MSEC = 10000 ;
57
+
56
58
const App = ( ) => {
57
59
const [ connectionStatus , setConnectionStatus ] = useState <
58
60
"disconnected" | "connected" | "error"
@@ -220,7 +222,19 @@ const App = () => {
220
222
}
221
223
222
224
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
+ }
224
238
pushHistory ( request , response ) ;
225
239
226
240
if ( tabKey !== undefined ) {
@@ -229,10 +243,14 @@ const App = () => {
229
243
230
244
return response ;
231
245
} catch ( e : unknown ) {
246
+ const errorString = ( e as Error ) . message ?? String ( e ) ;
232
247
if ( tabKey === undefined ) {
233
- toast . error ( ( e as Error ) . message ) ;
248
+ toast . error ( errorString ) ;
234
249
} else {
235
- setErrors ( ( prev ) => ( { ...prev , [ tabKey ] : ( e as Error ) . message } ) ) ;
250
+ setErrors ( ( prev ) => ( {
251
+ ...prev ,
252
+ [ tabKey ] : errorString ,
253
+ } ) ) ;
236
254
}
237
255
238
256
throw e ;
@@ -248,7 +266,7 @@ const App = () => {
248
266
await mcpClient . notification ( notification ) ;
249
267
pushHistory ( notification ) ;
250
268
} catch ( e : unknown ) {
251
- toast . error ( ( e as Error ) . message ) ;
269
+ toast . error ( ( e as Error ) . message ?? String ( e ) ) ;
252
270
throw e ;
253
271
}
254
272
} ;
0 commit comments