11import { useEffect , useRef } from "react" ;
2- import { InspectorOAuthClientProvider } from "../lib/auth" ;
32import { SESSION_KEYS } from "../lib/constants" ;
4- import { auth } from "@modelcontextprotocol/sdk/client/auth.js" ;
53import { useToast } from "@/hooks/use-toast.ts" ;
64import {
75 generateOAuthErrorDescription ,
@@ -39,38 +37,20 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
3937 }
4038
4139 const serverUrl = sessionStorage . getItem ( SESSION_KEYS . SERVER_URL ) ;
40+
41+ // ServerURL isn't set, this can happen if we've opened the
42+ // authentication request in a new tab, so we don't have the same
43+ // session storage
4244 if ( ! serverUrl ) {
43- return notifyError ( "Missing Server URL [DEBUG]" ) ;
45+ return ;
4446 }
4547
46- onConnect ( serverUrl ) ;
47-
4848 if ( ! params . code ) {
4949 return notifyError ( "Missing authorization code" ) ;
5050 }
5151
5252 sessionStorage . setItem ( SESSION_KEYS . DEBUG_CODE , params . code ) ;
5353
54- // let result;
55- // try {
56- // // Create an auth provider with the current server URL
57- // const serverAuthProvider = new InspectorOAuthClientProvider(serverUrl);
58-
59- // result = await auth(serverAuthProvider, {
60- // serverUrl,
61- // authorizationCode: params.code,
62- // });
63- // } catch (error) {
64- // console.error("OAuth callback error:", error);
65- // return notifyError(`Unexpected error occurred: ${error}`);
66- // }
67-
68- // if (result !== "AUTHORIZED") {
69- // return notifyError(
70- // `Expected to be authorized after providing auth code, got: ${result}`,
71- // );
72- // }
73-
7454 // Finally, trigger auto-connect
7555 toast ( {
7656 title : "Success" ,
@@ -81,22 +61,30 @@ const OAuthDebugCallback = ({ onConnect }: OAuthCallbackProps) => {
8161 } ;
8262
8363 handleCallback ( ) . finally ( ( ) => {
84- // Only redirect if we have the URL set, otherwise assume it was in a new tab.
64+ // Only redirect if we have the URL set, otherwise assume this was
65+ // in a new tab
8566 if ( sessionStorage . getItem ( SESSION_KEYS . SERVER_URL ) ) {
8667 window . history . replaceState ( { } , document . title , "/" ) ;
8768 }
8869 } ) ;
8970 } , [ toast , onConnect ] ) ;
9071
72+ const callbackParams = parseOAuthCallbackParams ( window . location . search ) ;
73+
9174 return (
9275 < div className = "flex items-center justify-center h-screen" >
9376 < div className = "mt-4 p-4 bg-secondary rounded-md max-w-md" >
9477 < p className = "mb-2 text-sm" >
9578 Please copy this authorization code and return to the Auth Debugger:
9679 </ p >
9780 < code className = "block p-2 bg-muted rounded-sm overflow-x-auto text-xs" >
98- { parseOAuthCallbackParams ( window . location . search ) . code ||
99- "No code found" }
81+ { callbackParams . successful
82+ ? (
83+ callbackParams as {
84+ code : string ;
85+ }
86+ ) . code
87+ : `No code found: ${ callbackParams . error } , ${ callbackParams . error_description } ` }
10088 </ code >
10189 < p className = "mt-4 text-xs text-muted-foreground" >
10290 Close this tab and paste the code in the OAuth flow to complete
0 commit comments