Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,11 @@ const App = () => {
);
return (
<Suspense fallback={<div>Loading...</div>}>
<OAuthCallback onConnect={onOAuthConnect} />
<OAuthCallback
onConnect={onOAuthConnect}
config={config}
connectionType={connectionType}
/>
</Suspense>
);
}
Expand Down
23 changes: 20 additions & 3 deletions client/src/components/OAuthCallback.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef } from "react";
import { useEffect, useMemo, useRef } from "react";
import { InspectorOAuthClientProvider } from "../lib/auth";
import { SESSION_KEYS } from "../lib/constants";
import { auth } from "@modelcontextprotocol/sdk/client/auth.js";
Expand All @@ -7,15 +7,31 @@ import {
generateOAuthErrorDescription,
parseOAuthCallbackParams,
} from "@/utils/oauthUtils.ts";
import { createProxyFetch } from "@/lib/proxyFetch";
import { InspectorConfig } from "@/lib/configurationTypes";

interface OAuthCallbackProps {
onConnect: (serverUrl: string) => void;
config: InspectorConfig;
connectionType: "direct" | "proxy";
}

const OAuthCallback = ({ onConnect }: OAuthCallbackProps) => {
const OAuthCallback = ({
onConnect,
config,
connectionType,
}: OAuthCallbackProps) => {
const { toast } = useToast();
const hasProcessedRef = useRef(false);

const fetchFn = useMemo(
() =>
connectionType === "proxy" && config
? createProxyFetch(config)
: undefined,
[connectionType, config],
);

useEffect(() => {
const handleCallback = async () => {
// Skip if we've already processed this callback
Expand Down Expand Up @@ -49,6 +65,7 @@ const OAuthCallback = ({ onConnect }: OAuthCallbackProps) => {
result = await auth(serverAuthProvider, {
serverUrl,
authorizationCode: params.code,
...(fetchFn && { fetchFn }),
});
} catch (error) {
console.error("OAuth callback error:", error);
Expand All @@ -73,7 +90,7 @@ const OAuthCallback = ({ onConnect }: OAuthCallbackProps) => {
handleCallback().finally(() => {
window.history.replaceState({}, document.title, "/");
});
}, [toast, onConnect]);
}, [toast, onConnect, fetchFn]);

return (
<div className="flex items-center justify-center h-screen">
Expand Down