@@ -17,6 +17,9 @@ import {
17
17
Tool ,
18
18
LoggingLevel ,
19
19
} from "@modelcontextprotocol/sdk/types.js" ;
20
+ import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js" ;
21
+ import { SESSION_KEYS , getServerSpecificKey } from "./lib/constants" ;
22
+ import { AuthDebuggerState } from "./lib/auth-types" ;
20
23
import React , {
21
24
Suspense ,
22
25
useCallback ,
@@ -139,6 +142,26 @@ const App = () => {
139
142
>
140
143
> ( [ ] ) ;
141
144
const [ isAuthDebuggerVisible , setIsAuthDebuggerVisible ] = useState ( false ) ;
145
+
146
+ // Auth debugger state (moved from AuthDebugger component)
147
+ const [ authState , setAuthState ] = useState < AuthDebuggerState > ( {
148
+ isInitiatingAuth : false ,
149
+ oauthTokens : null ,
150
+ loading : true ,
151
+ oauthStep : "not_started" ,
152
+ oauthMetadata : null ,
153
+ oauthClientInfo : null ,
154
+ authorizationUrl : null ,
155
+ authorizationCode : "" ,
156
+ latestError : null ,
157
+ statusMessage : null ,
158
+ validationError : null ,
159
+ } ) ;
160
+
161
+ // Helper function to update specific auth state properties
162
+ const updateAuthState = ( updates : Partial < AuthDebuggerState > ) => {
163
+ setAuthState ( ( prev ) => ( { ...prev , ...updates } ) ) ;
164
+ } ;
142
165
const nextRequestId = useRef ( 0 ) ;
143
166
const rootsRef = useRef < Root [ ] > ( [ ] ) ;
144
167
@@ -246,6 +269,47 @@ const App = () => {
246
269
setIsAuthDebuggerVisible ( true ) ;
247
270
} , [ ] ) ;
248
271
272
+ // Load OAuth tokens when sseUrl changes (moved from AuthDebugger)
273
+ useEffect ( ( ) => {
274
+ const loadOAuthTokens = async ( ) => {
275
+ try {
276
+ if ( sseUrl ) {
277
+ const key = getServerSpecificKey ( SESSION_KEYS . TOKENS , sseUrl ) ;
278
+ const tokens = sessionStorage . getItem ( key ) ;
279
+ if ( tokens ) {
280
+ const parsedTokens = await OAuthTokensSchema . parseAsync (
281
+ JSON . parse ( tokens ) ,
282
+ ) ;
283
+ updateAuthState ( {
284
+ oauthTokens : parsedTokens ,
285
+ oauthStep : "complete" ,
286
+ } ) ;
287
+ }
288
+ }
289
+ } catch ( error ) {
290
+ console . error ( "Error loading OAuth tokens:" , error ) ;
291
+ } finally {
292
+ updateAuthState ( { loading : false } ) ;
293
+ }
294
+ } ;
295
+
296
+ loadOAuthTokens ( ) ;
297
+ } , [ sseUrl ] ) ;
298
+
299
+ // Check for debug callback code (moved from AuthDebugger)
300
+ useEffect ( ( ) => {
301
+ const debugCode = sessionStorage . getItem ( SESSION_KEYS . DEBUG_CODE ) ;
302
+ if ( debugCode && sseUrl ) {
303
+ updateAuthState ( {
304
+ authorizationCode : debugCode ,
305
+ oauthStep : "token_request" ,
306
+ } ) ;
307
+
308
+ // Now that we've processed it, clear the debug code
309
+ sessionStorage . removeItem ( SESSION_KEYS . DEBUG_CODE ) ;
310
+ }
311
+ } , [ sseUrl ] ) ;
312
+
249
313
useEffect ( ( ) => {
250
314
fetch ( `${ getMCPProxyAddress ( config ) } /config` )
251
315
. then ( ( response ) => response . json ( ) )
@@ -485,6 +549,8 @@ const App = () => {
485
549
< AuthDebugger
486
550
sseUrl = { sseUrl }
487
551
onBack = { ( ) => setIsAuthDebuggerVisible ( false ) }
552
+ authState = { authState }
553
+ updateAuthState = { updateAuthState }
488
554
/>
489
555
</ Suspense >
490
556
) ;
0 commit comments