@@ -21,6 +21,10 @@ import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
2121import { SESSION_KEYS , getServerSpecificKey } from "./lib/constants" ;
2222import { AuthDebuggerState , EMPTY_DEBUGGER_STATE } from "./lib/auth-types" ;
2323import { OAuthStateMachine } from "./lib/oauth-state-machine" ;
24+ import {
25+ createOAuthProviderForServer ,
26+ setOAuthMode ,
27+ } from "./lib/oauth/provider-factory" ;
2428import { cacheToolOutputSchemas } from "./utils/schemaUtils" ;
2529import { cleanParams } from "./utils/paramUtils" ;
2630import type { JsonSchemaType } from "./utils/jsonUtils" ;
@@ -145,6 +149,12 @@ const App = () => {
145149 return localStorage . getItem ( "lastOauthClientSecret" ) || "" ;
146150 } ) ;
147151
152+ const [ oauthMode , setOauthMode ] = useState < "direct" | "proxy" > ( ( ) => {
153+ return (
154+ ( localStorage . getItem ( "lastOauthMode" ) as "direct" | "proxy" ) || "direct"
155+ ) ;
156+ } ) ;
157+
148158 // Custom headers state with migration from legacy auth
149159 const [ customHeaders , setCustomHeaders ] = useState < CustomHeaders > ( ( ) => {
150160 const savedHeaders = localStorage . getItem ( "lastCustomHeaders" ) ;
@@ -399,6 +409,18 @@ const App = () => {
399409 localStorage . setItem ( "lastOauthScope" , oauthScope ) ;
400410 } , [ oauthScope ] ) ;
401411
412+ useEffect ( ( ) => {
413+ localStorage . setItem ( "lastOauthMode" , oauthMode ) ;
414+ } , [ oauthMode ] ) ;
415+
416+ // Sync OAuth mode to sessionStorage when server URL changes
417+ useEffect ( ( ) => {
418+ if ( sseUrl ) {
419+ const key = getServerSpecificKey ( SESSION_KEYS . OAUTH_MODE , sseUrl ) ;
420+ sessionStorage . setItem ( key , oauthMode ) ;
421+ }
422+ } , [ sseUrl , oauthMode ] ) ;
423+
402424 useEffect ( ( ) => {
403425 localStorage . setItem ( "lastOauthClientSecret" , oauthClientSecret ) ;
404426 } , [ oauthClientSecret ] ) ;
@@ -446,9 +468,24 @@ const App = () => {
446468 } ;
447469
448470 try {
449- const stateMachine = new OAuthStateMachine ( sseUrl , ( updates ) => {
450- currentState = { ...currentState , ...updates } ;
451- } ) ;
471+ // Set the OAuth mode in sessionStorage before creating the provider
472+ setOAuthMode ( oauthMode , sseUrl ) ;
473+
474+ const proxyAddress = getMCPProxyAddress ( config ) ;
475+ const proxyAuthObj = getMCPProxyAuthToken ( config ) ;
476+ const oauthProvider = createOAuthProviderForServer (
477+ sseUrl ,
478+ proxyAddress ,
479+ proxyAuthObj . token ,
480+ ) ;
481+
482+ const stateMachine = new OAuthStateMachine (
483+ sseUrl ,
484+ ( updates ) => {
485+ currentState = { ...currentState , ...updates } ;
486+ } ,
487+ oauthProvider ,
488+ ) ;
452489
453490 while (
454491 currentState . oauthStep !== "complete" &&
@@ -486,7 +523,7 @@ const App = () => {
486523 } ) ;
487524 }
488525 } ,
489- [ sseUrl ] ,
526+ [ sseUrl , oauthMode , config ] ,
490527 ) ;
491528
492529 useEffect ( ( ) => {
@@ -854,6 +891,8 @@ const App = () => {
854891 onBack = { ( ) => setIsAuthDebuggerVisible ( false ) }
855892 authState = { authState }
856893 updateAuthState = { updateAuthState }
894+ config = { config }
895+ oauthMode = { oauthMode }
857896 />
858897 </ TabsContent >
859898 ) ;
@@ -913,6 +952,8 @@ const App = () => {
913952 setOauthClientSecret = { setOauthClientSecret }
914953 oauthScope = { oauthScope }
915954 setOauthScope = { setOauthScope }
955+ oauthMode = { oauthMode }
956+ setOauthMode = { setOauthMode }
916957 onConnect = { connectMcpServer }
917958 onDisconnect = { disconnectMcpServer }
918959 logLevel = { logLevel }
0 commit comments