@@ -53,33 +53,14 @@ const PROXY_PORT = params.get("proxyPort") ?? "3000";
5353const PROXY_SERVER_URL = `http://${ window . location . hostname } :${ PROXY_PORT } ` ;
5454
5555const App = ( ) => {
56- if ( window . location . pathname === "/oauth/callback" ) {
57- return < OAuthCallbackRoute /> ;
58- }
59-
60- return < MainApp /> ;
61- } ;
62-
63- const OAuthCallbackRoute = ( ) => {
64- const OAuthCallback = React . lazy ( ( ) => import ( "./components/OAuthCallback" ) ) ;
65- return (
66- < Suspense fallback = { < div > Loading...</ div > } >
67- < OAuthCallback />
68- </ Suspense >
69- ) ;
70- } ;
71-
72- const MainApp = ( ) => {
56+ // Handle OAuth callback route
7357 const [ resources , setResources ] = useState < Resource [ ] > ( [ ] ) ;
74- const [ resourceTemplates , setResourceTemplates ] = useState <
75- ResourceTemplate [ ]
76- > ( [ ] ) ;
58+ const [ resourceTemplates , setResourceTemplates ] = useState < ResourceTemplate [ ] > ( [ ] ) ;
7759 const [ resourceContent , setResourceContent ] = useState < string > ( "" ) ;
7860 const [ prompts , setPrompts ] = useState < Prompt [ ] > ( [ ] ) ;
7961 const [ promptContent , setPromptContent ] = useState < string > ( "" ) ;
8062 const [ tools , setTools ] = useState < Tool [ ] > ( [ ] ) ;
81- const [ toolResult , setToolResult ] =
82- useState < CompatibilityCallToolResult | null > ( null ) ;
63+ const [ toolResult , setToolResult ] = useState < CompatibilityCallToolResult | null > ( null ) ;
8364 const [ errors , setErrors ] = useState < Record < string , string | null > > ( {
8465 resources : null ,
8566 prompts : null ,
@@ -102,9 +83,7 @@ const MainApp = () => {
10283 } ) ;
10384 const [ logLevel , setLogLevel ] = useState < LoggingLevel > ( "debug" ) ;
10485 const [ notifications , setNotifications ] = useState < ServerNotification [ ] > ( [ ] ) ;
105- const [ stdErrNotifications , setStdErrNotifications ] = useState <
106- StdErrNotification [ ]
107- > ( [ ] ) ;
86+ const [ stdErrNotifications , setStdErrNotifications ] = useState < StdErrNotification [ ] > ( [ ] ) ;
10887 const [ roots , setRoots ] = useState < Root [ ] > ( [ ] ) ;
10988 const [ env , setEnv ] = useState < Record < string , string > > ( { } ) ;
11089 const [ bearerToken , setBearerToken ] = useState < string > ( ( ) => {
@@ -125,24 +104,14 @@ const MainApp = () => {
125104 const nextRequestId = useRef ( 0 ) ;
126105 const rootsRef = useRef < Root [ ] > ( [ ] ) ;
127106
128- const [ selectedResource , setSelectedResource ] = useState < Resource | null > (
129- null ,
130- ) ;
131- const [ resourceSubscriptions , setResourceSubscriptions ] = useState <
132- Set < string >
133- > ( new Set < string > ( ) ) ;
107+ const [ selectedResource , setSelectedResource ] = useState < Resource | null > ( null ) ;
108+ const [ resourceSubscriptions , setResourceSubscriptions ] = useState < Set < string > > ( new Set < string > ( ) ) ;
134109
135110 const [ selectedPrompt , setSelectedPrompt ] = useState < Prompt | null > ( null ) ;
136111 const [ selectedTool , setSelectedTool ] = useState < Tool | null > ( null ) ;
137- const [ nextResourceCursor , setNextResourceCursor ] = useState <
138- string | undefined
139- > ( ) ;
140- const [ nextResourceTemplateCursor , setNextResourceTemplateCursor ] = useState <
141- string | undefined
142- > ( ) ;
143- const [ nextPromptCursor , setNextPromptCursor ] = useState <
144- string | undefined
145- > ( ) ;
112+ const [ nextResourceCursor , setNextResourceCursor ] = useState < string | undefined > ( ) ;
113+ const [ nextResourceTemplateCursor , setNextResourceTemplateCursor ] = useState < string | undefined > ( ) ;
114+ const [ nextPromptCursor , setNextPromptCursor ] = useState < string | undefined > ( ) ;
146115 const [ nextToolCursor , setNextToolCursor ] = useState < string | undefined > ( ) ;
147116 const progressTokenRef = useRef ( 0 ) ;
148117
@@ -228,7 +197,7 @@ const MainApp = () => {
228197 toast . success ( "Successfully authenticated with OAuth" ) ;
229198 connectMcpServer ( ) ;
230199 }
231- } , [ ] ) ;
200+ } , [ connectMcpServer ] ) ;
232201
233202 useEffect ( ( ) => {
234203 fetch ( `${ PROXY_SERVER_URL } /config` )
@@ -255,8 +224,10 @@ const MainApp = () => {
255224
256225 useEffect ( ( ) => {
257226 console . log ( `[App] Connection status changed to: ${ connectionStatus } ` ) ;
258- console . log ( `[App] Connection details - status: ${ connectionStatus } , serverCapabilities: ${ ! ! serverCapabilities } , mcpClient: ${ ! ! mcpClient } ` ) ;
259-
227+ console . log (
228+ `[App] Connection details - status: ${ connectionStatus } , serverCapabilities: ${ ! ! serverCapabilities } , mcpClient: ${ ! ! mcpClient } `
229+ ) ;
230+
260231 if ( connectionStatus === "connected" && mcpClient && ! serverCapabilities ) {
261232 console . log ( "[App] Connection is established, but missing capabilities" ) ;
262233 try {
@@ -280,11 +251,29 @@ const MainApp = () => {
280251 setErrors ( ( prev ) => ( { ...prev , [ tabKey ] : null } ) ) ;
281252 } ;
282253
254+ // Add sampling handlers
255+ const handleApproveSampling = ( id : number , result : CreateMessageResult ) => {
256+ const pendingRequest = pendingSampleRequests . find ( ( req ) => req . id === id ) ;
257+ if ( pendingRequest ) {
258+ pendingRequest . resolve ( result ) ;
259+ setPendingSampleRequests ( ( prev ) => prev . filter ( ( req ) => req . id !== id ) ) ;
260+ }
261+ } ;
262+
263+ const handleRejectSampling = ( id : number ) => {
264+ const pendingRequest = pendingSampleRequests . find ( ( req ) => req . id === id ) ;
265+ if ( pendingRequest ) {
266+ pendingRequest . reject ( new Error ( "Request rejected by user" ) ) ;
267+ setPendingSampleRequests ( ( prev ) => prev . filter ( ( req ) => req . id !== id ) ) ;
268+ }
269+ } ;
270+
271+ // Add wrapper function for makeConnectionRequest to handle tab error management
283272 const makeRequest = async < T extends z . ZodType > (
284273 request : ClientRequest ,
285274 schema : T ,
286275 tabKey ?: keyof typeof errors ,
287- ) => {
276+ ) : Promise < z . output < T > > => {
288277 try {
289278 const response = await makeConnectionRequest ( request , schema ) ;
290279 if ( tabKey !== undefined ) {
@@ -310,7 +299,7 @@ const MainApp = () => {
310299 params : nextResourceCursor ? { cursor : nextResourceCursor } : { } ,
311300 } ,
312301 ListResourcesResultSchema ,
313- "resources" ,
302+ "resources"
314303 ) ;
315304 setResources ( resources . concat ( response . resources ?? [ ] ) ) ;
316305 setNextResourceCursor ( response . nextCursor ) ;
@@ -320,16 +309,12 @@ const MainApp = () => {
320309 const response = await makeRequest (
321310 {
322311 method : "resources/templates/list" as const ,
323- params : nextResourceTemplateCursor
324- ? { cursor : nextResourceTemplateCursor }
325- : { } ,
312+ params : nextResourceTemplateCursor ? { cursor : nextResourceTemplateCursor } : { } ,
326313 } ,
327314 ListResourceTemplatesResultSchema ,
328- "resources" ,
329- ) ;
330- setResourceTemplates (
331- resourceTemplates . concat ( response . resourceTemplates ?? [ ] ) ,
315+ "resources"
332316 ) ;
317+ setResourceTemplates ( resourceTemplates . concat ( response . resourceTemplates ?? [ ] ) ) ;
333318 setNextResourceTemplateCursor ( response . nextCursor ) ;
334319 } ;
335320
@@ -340,7 +325,7 @@ const MainApp = () => {
340325 params : { uri } ,
341326 } ,
342327 ReadResourceResultSchema ,
343- "resources" ,
328+ "resources"
344329 ) ;
345330 setResourceContent ( JSON . stringify ( response , null , 2 ) ) ;
346331 } ;
@@ -353,7 +338,7 @@ const MainApp = () => {
353338 params : { uri } ,
354339 } ,
355340 z . object ( { } ) ,
356- "resources" ,
341+ "resources"
357342 ) ;
358343 const clone = new Set ( resourceSubscriptions ) ;
359344 clone . add ( uri ) ;
@@ -369,7 +354,7 @@ const MainApp = () => {
369354 params : { uri } ,
370355 } ,
371356 z . object ( { } ) ,
372- "resources" ,
357+ "resources"
373358 ) ;
374359 const clone = new Set ( resourceSubscriptions ) ;
375360 clone . delete ( uri ) ;
@@ -384,7 +369,7 @@ const MainApp = () => {
384369 params : nextPromptCursor ? { cursor : nextPromptCursor } : { } ,
385370 } ,
386371 ListPromptsResultSchema ,
387- "prompts" ,
372+ "prompts"
388373 ) ;
389374 setPrompts ( response . prompts ) ;
390375 setNextPromptCursor ( response . nextCursor ) ;
@@ -397,7 +382,7 @@ const MainApp = () => {
397382 params : { name, arguments : args } ,
398383 } ,
399384 GetPromptResultSchema ,
400- "prompts" ,
385+ "prompts"
401386 ) ;
402387 setPromptContent ( JSON . stringify ( response , null , 2 ) ) ;
403388 } ;
@@ -409,7 +394,7 @@ const MainApp = () => {
409394 params : nextToolCursor ? { cursor : nextToolCursor } : { } ,
410395 } ,
411396 ListToolsResultSchema ,
412- "tools" ,
397+ "tools"
413398 ) ;
414399 setTools ( response . tools ) ;
415400 setNextToolCursor ( response . nextCursor ) ;
@@ -428,7 +413,7 @@ const MainApp = () => {
428413 } ,
429414 } ,
430415 CompatibilityCallToolResultSchema ,
431- "tools" ,
416+ "tools"
432417 ) ;
433418 setToolResult ( response ) ;
434419 } ;
@@ -448,22 +433,14 @@ const MainApp = () => {
448433 setLogLevel ( level ) ;
449434 } ;
450435
451- const handleApproveSampling = ( id : number , result : CreateMessageResult ) => {
452- setPendingSampleRequests ( ( prev ) => {
453- const request = prev . find ( ( r ) => r . id === id ) ;
454- request ?. resolve ( result ) ;
455- return prev . filter ( ( r ) => r . id !== id ) ;
456- } ) ;
457- } ;
458-
459- const handleRejectSampling = ( id : number ) => {
460- setPendingSampleRequests ( ( prev ) => {
461- const request = prev . find ( ( r ) => r . id === id ) ;
462- request ?. reject ( new Error ( "Sampling request rejected" ) ) ;
463- return prev . filter ( ( r ) => r . id !== id ) ;
464- } ) ;
465- } ;
466-
436+ if ( window . location . pathname === "/oauth/callback" ) {
437+ const OAuthCallback = React . lazy ( ( ) => import ( "./components/OAuthCallback" ) ) ;
438+ return (
439+ < Suspense fallback = { < div > Loading...</ div > } >
440+ < OAuthCallback />
441+ </ Suspense >
442+ ) ;
443+ }
467444
468445 return (
469446 < div className = "flex h-screen bg-background" >
@@ -494,9 +471,7 @@ const MainApp = () => {
494471 { connectionStatus === "connected" && serverCapabilities ? (
495472 < Tabs
496473 defaultValue = {
497- Object . keys ( serverCapabilities ) . includes (
498- window . location . hash . slice ( 1 ) ,
499- )
474+ Object . keys ( serverCapabilities ) . includes ( window . location . hash . slice ( 1 ) )
500475 ? window . location . hash . slice ( 1 )
501476 : serverCapabilities ?. resources
502477 ? "resources"
@@ -510,24 +485,15 @@ const MainApp = () => {
510485 onValueChange = { ( value ) => ( window . location . hash = value ) }
511486 >
512487 < TabsList className = "mb-4 p-0" >
513- < TabsTrigger
514- value = "resources"
515- disabled = { ! serverCapabilities ?. resources }
516- >
488+ < TabsTrigger value = "resources" disabled = { ! serverCapabilities ?. resources } >
517489 < Files className = "w-4 h-4 mr-2" />
518490 Resources
519491 </ TabsTrigger >
520- < TabsTrigger
521- value = "prompts"
522- disabled = { ! serverCapabilities ?. prompts }
523- >
492+ < TabsTrigger value = "prompts" disabled = { ! serverCapabilities ?. prompts } >
524493 < MessageSquare className = "w-4 h-4 mr-2" />
525494 Prompts
526495 </ TabsTrigger >
527- < TabsTrigger
528- value = "tools"
529- disabled = { ! serverCapabilities ?. tools }
530- >
496+ < TabsTrigger value = "tools" disabled = { ! serverCapabilities ?. tools } >
531497 < Hammer className = "w-4 h-4 mr-2" />
532498 Tools
533499 </ TabsTrigger >
@@ -593,9 +559,7 @@ const MainApp = () => {
593559 clearError ( "resources" ) ;
594560 setSelectedResource ( resource ) ;
595561 } }
596- resourceSubscriptionsSupported = {
597- serverCapabilities ?. resources ?. subscribe || false
598- }
562+ resourceSubscriptionsSupported = { serverCapabilities ?. resources ?. subscribe || false }
599563 resourceSubscriptions = { resourceSubscriptions }
600564 subscribeToResource = { ( uri ) => {
601565 clearError ( "resources" ) ;
@@ -668,7 +632,7 @@ const MainApp = () => {
668632 {
669633 method : "ping" as const ,
670634 } ,
671- EmptyResultSchema ,
635+ EmptyResultSchema
672636 ) ;
673637 } }
674638 />
0 commit comments