Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.
Merged
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: 6 additions & 0 deletions src/auth/browser-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
readonly clientName: string
readonly clientUri: string
readonly callbackUrl: string
private preventAutoAuth?: boolean
readonly onPopupWindow: ((url: string, features: string, window: Window | null) => void) | undefined

constructor(
Expand All @@ -24,6 +25,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
clientName?: string
clientUri?: string
callbackUrl?: string
preventAutoAuth?: boolean
onPopupWindow?: (url: string, features: string, window: Window | null) => void
} = {},
) {
Expand All @@ -36,6 +38,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
options.callbackUrl ||
(typeof window !== 'undefined' ? new URL('/oauth/callback', window.location.origin).toString() : '/oauth/callback'),
)
this.preventAutoAuth = options.preventAutoAuth
this.onPopupWindow = options.onPopupWindow
}

Expand Down Expand Up @@ -164,6 +167,9 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
* @param authorizationUrl The fully constructed authorization URL from the SDK.
*/
async redirectToAuthorization(authorizationUrl: URL): Promise<void> {
// Ideally we should catch things before we get here, but if we don't, let's not show everyone we are dum
if (this.preventAutoAuth) return

// Prepare the authorization URL with state
const sanitizedAuthUrl = await this.prepareAuthorizationUrl(authorizationUrl)

Expand Down
2 changes: 2 additions & 0 deletions src/react/useMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export function useMcp(options: UseMcpOptions): UseMcpResult {
clientName,
clientUri,
callbackUrl,
preventAutoAuth,
onPopupWindow,
})
addLog('debug', 'BrowserOAuthClientProvider initialized in connect.')
Expand Down Expand Up @@ -781,6 +782,7 @@ export function useMcp(options: UseMcpOptions): UseMcpResult {
clientName,
clientUri,
callbackUrl,
preventAutoAuth,
onPopupWindow,
})
addLog('debug', 'BrowserOAuthClientProvider initialized/updated on mount/option change.')
Expand Down
Loading