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
8 changes: 6 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ const App = () => {
(serverUrl: string) => {
setSseUrl(serverUrl);
setIsAuthDebuggerVisible(false);
void connectMcpServer();
void connectMcpServer(undefined, 0, serverUrl);
},
[connectMcpServer],
);
Expand Down Expand Up @@ -1350,7 +1350,11 @@ const App = () => {
);
return (
<Suspense fallback={<div>Loading...</div>}>
<OAuthCallback onConnect={onOAuthConnect} />
<OAuthCallback
onConnect={onOAuthConnect}
connectionType={connectionType}
config={config}
/>
</Suspense>
);
}
Expand Down
16 changes: 15 additions & 1 deletion client/src/components/OAuthCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ import {
generateOAuthErrorDescription,
parseOAuthCallbackParams,
} from "@/utils/oauthUtils.ts";
import { createProxyFetch } from "@/lib/proxyFetch";
import type { InspectorConfig } from "@/lib/configurationTypes";

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

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

Expand Down Expand Up @@ -46,9 +54,15 @@ const OAuthCallback = ({ onConnect }: OAuthCallbackProps) => {
// Create an auth provider with the current server URL
const serverAuthProvider = new InspectorOAuthClientProvider(serverUrl);

const fetchFn =
connectionType === "proxy" && config
? createProxyFetch(config)
: undefined;

result = await auth(serverAuthProvider, {
serverUrl,
authorizationCode: params.code,
...(fetchFn ? { fetchFn } : {}),
});
} catch (error) {
console.error("OAuth callback error:", error);
Expand Down
12 changes: 8 additions & 4 deletions client/src/lib/hooks/useConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ export function useConnection({
}
};

const connect = async (_e?: unknown, retryCount: number = 0) => {
const connect = async (
_e?: unknown,
retryCount: number = 0,
serverUrlOverride?: string,
) => {
const clientCapabilities = {
capabilities: {
sampling: {},
Expand Down Expand Up @@ -496,7 +500,9 @@ export function useConnection({
const headers: HeadersInit = {};

// Create an auth provider with the current server URL
const serverAuthProvider = new InspectorOAuthClientProvider(sseUrl);
const serverAuthProvider = new InspectorOAuthClientProvider(
serverUrlOverride ?? sseUrl,
);

// Use custom headers (migration is handled in App.tsx)
let finalHeaders: CustomHeaders = customHeaders || [];
Expand Down Expand Up @@ -694,7 +700,6 @@ export function useConnection({
);
}
transportOptions = {
authProvider: serverAuthProvider,
eventSourceInit: {
fetch: (
url: string | URL | globalThis.Request,
Expand All @@ -716,7 +721,6 @@ export function useConnection({
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
mcpProxyServerUrl.searchParams.append("url", sseUrl);
transportOptions = {
authProvider: serverAuthProvider,
eventSourceInit: {
fetch: (
url: string | URL | globalThis.Request,
Expand Down