feat: MCP OAuth flow improvements (#123)

Rewrite OAuth flow handle authentication entirely in web app with secure proxy
- Add MCP OAuth proxy with origin validation and callback handling
- Remove auto OAuth method from authentication flow
- Fix TypeScript build errors
- Add directory support for MCP OAuth flows and improve config manager UI
- Reload session caches after MCP connection changes
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-13 00:10:56 -05:00
1 parent 7824d52fb8
commit 3f9c398b31
31 files changed
+1054 -483

No files matched your search

@@ -179,14 +179,14 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
return (
<Dialog open={open} onOpenChange={handleClose}>
<DialogContent className="max-w-3xl max-h-[90vh] sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6 z-[200]" overlayClassName="z-[200]">
<DialogContent className="max-w-3xl max-h-[90vh] sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6">
<DialogHeader className="p-4 sm:p-6 border-b flex flex-row items-center justify-between space-y-0">
<DialogTitle>Add MCP Server</DialogTitle>
</DialogHeader>
<div className="flex-1 overflow-y-auto p-2 sm:p-4">
<div className="space-y-4">
<div>
<div className="space-y-1.5">
<Label htmlFor="serverId">Server ID</Label>
<Input
id="serverId"
@@ -200,7 +200,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
</p>
</div>
<div>
<div className="space-y-1.5">
<Label htmlFor="serverType">Server Type</Label>
<Select value={serverType} onValueChange={(value: 'local' | 'remote') => setServerType(value)}>
<SelectTrigger className="bg-background border-border">
@@ -214,7 +214,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
</div>
{serverType === 'local' ? (
<div>
<div className="space-y-1.5">
<Label htmlFor="command">Command</Label>
<Input
id="command"
@@ -228,7 +228,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
</p>
</div>
) : (
<div>
<div className="space-y-1.5">
<Label htmlFor="url">Server URL</Label>
<Input
id="url"
@@ -258,7 +258,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
<p className="text-xs text-muted-foreground">
Leave fields blank to use the server's default OAuth discovery
</p>
<div>
<div className="space-y-1.5">
<Label htmlFor="oauthClientId">Client ID</Label>
<Input
id="oauthClientId"
@@ -268,7 +268,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
className="bg-background border-border font-mono"
/>
</div>
<div>
<div className="space-y-1.5">
<Label htmlFor="oauthClientSecret">Client Secret</Label>
<Input
id="oauthClientSecret"
@@ -279,7 +279,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
className="bg-background border-border font-mono"
/>
</div>
<div>
<div className="space-y-1.5">
<Label htmlFor="oauthScope">Scope</Label>
<Input
id="oauthScope"
@@ -295,7 +295,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
)}
{serverType === 'local' && (
<div>
<div className="space-y-1.5">
<div className="flex items-center justify-between">
<Label>Environment Variables</Label>
<Button
@@ -340,7 +340,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
</div>
)}
<div>
<div className="space-y-1.5">
<Label htmlFor="timeout">Timeout (ms)</Label>
<Input
id="timeout"
@@ -176,7 +176,7 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent className="max-w-2xl max-h-[90vh] sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6 z-[200]" overlayClassName="z-[200]">
<DialogContent className="max-w-2xl max-h-[90vh] sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6">
<DialogHeader className="p-4 sm:p-6 border-b flex flex-row items-center justify-between space-y-0">
<DialogTitle>{editingAgent ? 'Edit Agent' : 'Create Agent'}</DialogTitle>
</DialogHeader>
@@ -99,7 +99,7 @@ export function CommandDialog({
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent className="max-w-3xl max-h-[90vh] sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6 z-[200]" overlayClassName="z-[200]">
<DialogContent className="max-w-3xl max-h-[90vh] sm:max-h-[85vh] gap-0 flex flex-col p-0 md:p-6">
<DialogHeader className="p-4 sm:p-6 border-b flex flex-row items-center justify-between space-y-0">
<DialogTitle>
{editingCommand ? "Edit Command" : "Create Command"}
@@ -104,7 +104,7 @@ export function CreateConfigDialog({ isOpen, onOpenChange, onCreate, isUpdating
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
<DialogContent className="max-w-2xl max-h-[90vh] sm:max-h-[85vh] flex flex-col z-[200]" overlayClassName="z-[200]">
<DialogContent className="max-w-2xl max-h-[90vh] sm:max-h-[85vh] flex flex-col">
<DialogHeader className="flex-shrink-0">
<DialogTitle>Create OpenCode Config</DialogTitle>
</DialogHeader>
@@ -132,8 +132,7 @@ export function GitCredentialDialog({ open, onOpenChange, onSave, credential, is
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent mobileFullscreen className="max-w-lg z-[200] h-[90vh] sm:h-auto sm:max-h-[85vh] flex flex-col"
overlayClassName="z-[200]">
<DialogContent mobileFullscreen className="max-w-lg h-[90vh] sm:h-auto sm:max-h-[85vh] flex flex-col">
<DialogHeader className="flex-shrink-0 px-4 sm:px-6 pt-4 sm:pt-6 pb-2 sm:pb-3">
<DialogTitle>{credential ? 'Edit Git Credential' : 'Add Git Credential'}</DialogTitle>
</DialogHeader>
+44 -17
View File
@@ -12,6 +12,7 @@ import { invalidateConfigCaches } from '@/lib/queryInvalidation'
import type { McpServerConfig } from '@/api/mcp'
import { mcpApi } from '@/api/mcp'
import type { McpAuthStartResponse } from '@/api/mcp'
import { showToast } from '@/lib/toast'
interface McpManagerProps {
config: {
@@ -38,16 +39,19 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
refetch: refetchStatus,
connect,
disconnect,
authenticate,
removeAuth,
isRemovingAuth,
isToggling
removeAuthAsync,
isRemovingAuth
} = useMcpServers()
const deleteServerMutation = useMutation({
mutationFn: async (serverId: string) => {
if (!config) return
const currentStatus = mcpStatus?.[serverId]
if (currentStatus?.status === 'connected') {
await disconnect(serverId)
}
const currentMcp = (config.content?.mcp as Record<string, McpServerConfig>) || {}
const { [serverId]: _, ...rest } = currentMcp
void _
@@ -59,15 +63,19 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
await onUpdate(updatedConfig)
},
onSuccess: () => {
onSuccess: async () => {
invalidateConfigCaches(queryClient)
await refetchStatus()
setDeleteConfirmServer(null)
},
onError: () => {
showToast.error('Failed to delete MCP server')
},
})
const mcpServers = config?.content?.mcp as Record<string, McpServerConfig> || {}
const isAnyOperationPending = deleteServerMutation.isPending || togglingServerId !== null || isToggling
const isAnyOperationPending = deleteServerMutation.isPending || togglingServerId !== null
const handleToggleServer = async (serverId: string) => {
const currentStatus = mcpStatus?.[serverId]
@@ -103,16 +111,18 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
setAuthDialogServerId(serverId)
}
const handleOAuthAutoAuth = async () => {
if (!authDialogServerId) return
await authenticate(authDialogServerId)
refetchStatus()
setAuthDialogServerId(null)
}
const handleOAuthStartAuth = async (): Promise<McpAuthStartResponse> => {
if (!authDialogServerId) throw new Error('No server ID')
return await mcpApi.startAuth(authDialogServerId)
const serverConfig = mcpServers[authDialogServerId]
if (!serverConfig?.url) throw new Error('Server URL not found')
const oauthConfig = typeof serverConfig.oauth === 'object' ? serverConfig.oauth : undefined
return await mcpApi.startAuth(
authDialogServerId,
serverConfig.url,
oauthConfig?.scope,
oauthConfig?.clientId,
oauthConfig?.clientSecret,
)
}
const handleOAuthCompleteAuth = async (code: string) => {
@@ -122,14 +132,30 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
setAuthDialogServerId(null)
}
const handleOAuthCheckStatus = async (): Promise<boolean> => {
if (!authDialogServerId) return false
const status = await mcpApi.getStatus()
const serverStatus = status[authDialogServerId]
if (serverStatus?.status === 'connected') {
refetchStatus()
return true
}
return false
}
const handleOAuthSuccess = () => {
refetchStatus()
}
const handleRemoveAuth = (serverId: string) => {
setRemoveAuthConfirmServer(serverId)
}
const handleConfirmRemoveAuth = () => {
const handleConfirmRemoveAuth = async () => {
if (removeAuthConfirmServer) {
removeAuth(removeAuthConfirmServer)
await removeAuthAsync(removeAuthConfirmServer)
setRemoveAuthConfirmServer(null)
refetchStatus()
}
}
@@ -251,9 +277,10 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
open={!!authDialogServerId}
onOpenChange={(open) => !open && setAuthDialogServerId(null)}
serverName={authDialogServerId || ''}
onAutoAuth={handleOAuthAutoAuth}
onStartAuth={handleOAuthStartAuth}
onCompleteAuth={handleOAuthCompleteAuth}
onCheckStatus={handleOAuthCheckStatus}
onSuccess={handleOAuthSuccess}
/>
<DeleteDialog
@@ -1,76 +1,205 @@
import { useState } from 'react'
import { useState, useEffect, useRef, useCallback } from 'react'
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
import { Alert, AlertDescription } from '@/components/ui/alert'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Loader2, ExternalLink, Key, XCircle } from 'lucide-react'
import { Loader2, ExternalLink, Key, XCircle, ChevronDown, ChevronUp, CheckCircle } from 'lucide-react'
import type { McpAuthStartResponse } from '@/api/mcp'
import { mcpApi } from '@/api/mcp'
interface McpOAuthDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
serverName: string
onAutoAuth: () => Promise<void>
onStartAuth: () => Promise<McpAuthStartResponse>
onCompleteAuth: (code: string) => Promise<void>
onCheckStatus?: () => Promise<boolean>
onSuccess?: () => void
directory?: string
}
type Step = 'loading' | 'ready' | 'waiting' | 'popup_closed' | 'success' | 'error'
export function McpOAuthDialog({
open,
onOpenChange,
serverName,
onAutoAuth,
onStartAuth,
onCompleteAuth,
onCheckStatus,
onSuccess,
directory
}: McpOAuthDialogProps) {
const [step, setStep] = useState<'method' | 'auto' | 'manual' | 'enter_code'>('method')
const [step, setStep] = useState<Step>('loading')
const [loading, setLoading] = useState(false)
const [authUrl, setAuthUrl] = useState<string | null>(null)
const [authCode, setAuthCode] = useState('')
const [error, setError] = useState<string | null>(null)
const [showManualEntry, setShowManualEntry] = useState(false)
const flowIdRef = useRef<string | null>(null)
const flowPollingRef = useRef<ReturnType<typeof setInterval> | null>(null)
const statusPollingRef = useRef<ReturnType<typeof setInterval> | null>(null)
const popupPollingRef = useRef<ReturnType<typeof setInterval> | null>(null)
const popupRef = useRef<Window | null>(null)
const doneRef = useRef(false)
const handleAutoAuth = async () => {
setLoading(true)
setError(null)
setStep('auto')
try {
await onAutoAuth()
const scopes = directory ? 'this location' : 'globally'
const stopAllPolling = useCallback(() => {
if (flowPollingRef.current) {
clearInterval(flowPollingRef.current)
flowPollingRef.current = null
}
if (statusPollingRef.current) {
clearInterval(statusPollingRef.current)
statusPollingRef.current = null
}
if (popupPollingRef.current) {
clearInterval(popupPollingRef.current)
popupPollingRef.current = null
}
}, [])
const handleSuccess = useCallback(() => {
if (doneRef.current) return
doneRef.current = true
stopAllPolling()
if (popupRef.current && !popupRef.current.closed) {
popupRef.current.close()
}
setStep('success')
onSuccess?.()
setTimeout(() => {
onOpenChange(false)
resetState()
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to authenticate')
setStep('method')
} finally {
setLoading(false)
}
}
}, 1500)
}, [stopAllPolling, onOpenChange, onSuccess])
const handleStartManualAuth = async () => {
setLoading(true)
const resetState = useCallback(() => {
setStep('loading')
setAuthUrl(null)
setAuthCode('')
setError(null)
try {
const result = await onStartAuth()
setAuthUrl(result.authorizationUrl)
setStep('manual')
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to start authentication')
} finally {
setLoading(false)
setLoading(false)
setShowManualEntry(false)
stopAllPolling()
doneRef.current = false
flowIdRef.current = null
if (popupRef.current && !popupRef.current.closed) {
popupRef.current.close()
}
popupRef.current = null
}, [stopAllPolling])
const startFlowPolling = useCallback(() => {
if (flowPollingRef.current) return
flowPollingRef.current = setInterval(async () => {
if (doneRef.current || !flowIdRef.current) return
try {
const result = await mcpApi.checkFlowStatus(flowIdRef.current)
if (result.status === 'completed') {
handleSuccess()
} else if (result.status === 'failed') {
stopAllPolling()
setError('error' in result ? result.error : 'Authentication failed')
setStep('error')
}
} catch {
// ignore
}
}, 1500)
}, [handleSuccess, stopAllPolling])
const startStatusPolling = useCallback(() => {
if (!onCheckStatus || statusPollingRef.current) return
statusPollingRef.current = setInterval(async () => {
if (doneRef.current) return
try {
const isConnected = await onCheckStatus()
if (isConnected) {
handleSuccess()
}
} catch {
// ignore
}
}, 2000)
}, [onCheckStatus, handleSuccess])
const startPopupPolling = useCallback(() => {
if (popupPollingRef.current) return
popupPollingRef.current = setInterval(() => {
const popup = popupRef.current
if (!popup || doneRef.current) return
if (popup.closed) {
if (popupPollingRef.current) {
clearInterval(popupPollingRef.current)
popupPollingRef.current = null
}
if (!doneRef.current) {
setStep('popup_closed')
startFlowPolling()
startStatusPolling()
}
}
}, 500)
}, [startFlowPolling, startStatusPolling])
useEffect(() => {
if (!open) return
resetState()
const initAuth = async () => {
try {
const result = await onStartAuth()
setAuthUrl(result.authorizationUrl)
flowIdRef.current = result.flowId
setStep('ready')
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to start authentication')
setStep('error')
}
}
initAuth()
}, [open]) // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
return () => {
stopAllPolling()
doneRef.current = false
}
}, [stopAllPolling])
const handleOpenAuthPage = () => {
if (!authUrl) return
const width = 600
const height = 700
const left = window.screenX + (window.outerWidth - width) / 2
const top = window.screenY + (window.outerHeight - height) / 2
popupRef.current = window.open(
authUrl,
'mcp-oauth',
`width=${width},height=${height},left=${left},top=${top},popup=yes`
)
setStep('waiting')
startPopupPolling()
startFlowPolling()
startStatusPolling()
}
const handleCompleteAuth = async () => {
const handleCompleteManualAuth = async () => {
if (!authCode.trim()) return
setLoading(true)
setError(null)
try {
await onCompleteAuth(authCode.trim())
onOpenChange(false)
resetState()
handleSuccess()
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to complete authentication')
} finally {
@@ -78,21 +207,6 @@ export function McpOAuthDialog({
}
}
const handleOpenAuthUrl = () => {
if (authUrl) {
window.open(authUrl, '_blank')
setStep('enter_code')
}
}
const resetState = () => {
setStep('method')
setAuthUrl(null)
setAuthCode('')
setError(null)
setLoading(false)
}
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) {
resetState()
@@ -100,157 +214,175 @@ export function McpOAuthDialog({
onOpenChange(newOpen)
}
const scopes = directory ? 'this location' : 'global'
const handleRetry = async () => {
setError(null)
setStep('loading')
doneRef.current = false
flowIdRef.current = null
try {
const result = await onStartAuth()
setAuthUrl(result.authorizationUrl)
flowIdRef.current = result.flowId
setStep('ready')
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to start authentication')
setStep('error')
}
}
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent className="max-w-md z-[200]" overlayClassName="z-[200]">
<DialogContent className="w-[calc(100vw-2rem)] max-w-md h-auto">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Key className="h-5 w-5" />
Connect {serverName}
<Key className="h-5 w-5 shrink-0" />
<span className="truncate">Connect {serverName}</span>
</DialogTitle>
<DialogDescription>
Authenticate to use this MCP server for {scopes}
Authenticate to use this MCP server {scopes}
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-4 py-2 min-w-0">
{error && (
<Alert variant="destructive">
<XCircle className="h-4 w-4" />
<AlertDescription>{error}</AlertDescription>
<XCircle className="h-4 w-4 shrink-0" />
<AlertDescription className="break-words">{error}</AlertDescription>
</Alert>
)}
{step === 'method' && (
<div className="space-y-3">
<p className="text-sm text-muted-foreground">Choose an authentication method:</p>
<div className="flex flex-col gap-2">
<Button
onClick={handleAutoAuth}
disabled={loading}
variant="outline"
className="justify-start h-auto py-3"
>
{loading ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Starting authentication...
</>
) : (
<>
<Loader2 className="h-4 w-4 mr-2" />
<div className="text-left">
<div className="font-medium">Auto (Recommended)</div>
<div className="text-xs text-muted-foreground">
Opens browser, handles redirect automatically
</div>
</div>
</>
)}
</Button>
<Button
onClick={handleStartManualAuth}
disabled={loading}
variant="outline"
className="justify-start h-auto py-3"
>
{loading ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Starting authentication...
</>
) : (
<>
<Key className="h-4 w-4 mr-2" />
<div className="text-left">
<div className="font-medium">Manual with Code</div>
<div className="text-xs text-muted-foreground">
Open URL, then paste the authorization code
</div>
</div>
</>
)}
</Button>
</div>
{step === 'loading' && (
<div className="flex items-center justify-center py-6">
<Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
<span className="ml-2 text-sm text-muted-foreground">Preparing authentication...</span>
</div>
)}
{step === 'auto' && (
<div className="flex items-center justify-center py-8">
<div className="flex flex-col items-center gap-3">
<Loader2 className="h-8 w-8 animate-spin text-primary" />
<p className="text-sm text-muted-foreground">
Waiting for browser authorization...
</p>
</div>
</div>
)}
{step === 'manual' && authUrl && (
{step === 'ready' && authUrl && (
<div className="space-y-3">
<p className="text-sm text-muted-foreground">
Open the authorization link in your browser to begin the flow. Then paste the code below.
Click below to open the authorization page. After you approve access, this dialog will update automatically.
</p>
<Button
onClick={handleOpenAuthUrl}
onClick={handleOpenAuthPage}
className="w-full"
>
<ExternalLink className="h-4 w-4 mr-2" />
Open Auth Page
Open Authorization Page
</Button>
<div className="text-xs text-muted-foreground break-all bg-muted p-2 rounded">
<a
href={authUrl}
target="_blank"
rel="noopener noreferrer"
className="block text-xs text-muted-foreground hover:text-foreground break-all transition-colors"
onClick={(e) => {
e.preventDefault()
handleOpenAuthPage()
}}
>
{authUrl}
</div>
</a>
</div>
)}
{step === 'enter_code' && (
<div className="space-y-3">
{step === 'waiting' && (
<div className="space-y-4">
<div className="flex items-center justify-center py-4">
<Loader2 className="h-5 w-5 animate-spin text-blue-500" />
<span className="ml-2 text-sm text-muted-foreground">Waiting for authorization...</span>
</div>
<p className="text-xs text-center text-muted-foreground">
Complete the authorization in the popup window. This dialog will update automatically.
</p>
{authUrl && (
<Button
variant="ghost"
size="sm"
className="w-full text-xs text-muted-foreground"
onClick={handleOpenAuthPage}
>
<ExternalLink className="h-3 w-3 mr-1" />
Re-open authorization popup
</Button>
)}
<ManualCodeEntry
showManualEntry={showManualEntry}
setShowManualEntry={setShowManualEntry}
authCode={authCode}
setAuthCode={setAuthCode}
loading={loading}
onSubmit={handleCompleteManualAuth}
/>
</div>
)}
{step === 'popup_closed' && (
<div className="space-y-4">
<div className="flex items-center justify-center py-4">
<Loader2 className="h-5 w-5 animate-spin text-blue-500" />
<span className="ml-2 text-sm text-muted-foreground">Checking authentication status...</span>
</div>
<p className="text-sm text-muted-foreground">
Paste the authorization code from the browser:
If authorization was completed, this will update shortly. Otherwise, paste the <code className="text-xs bg-muted px-1 py-0.5 rounded">code</code> parameter from the redirect URL below.
</p>
<div className="space-y-2">
<Label htmlFor="auth-code">Authorization Code</Label>
<Input
id="auth-code"
value={authCode}
onChange={(e) => setAuthCode(e.target.value)}
placeholder="Paste code here..."
disabled={loading}
/>
<div className="flex gap-2">
<Input
id="auth-code"
value={authCode}
onChange={(e) => setAuthCode(e.target.value)}
placeholder="Paste code here..."
disabled={loading}
className="text-sm"
/>
<Button
onClick={handleCompleteManualAuth}
disabled={loading || !authCode.trim()}
size="sm"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : 'Submit'}
</Button>
</div>
</div>
{authUrl && (
<Button
variant="outline"
size="sm"
className="w-full"
onClick={handleOpenAuthPage}
>
<ExternalLink className="h-4 w-4 mr-2" />
Try Again
</Button>
)}
</div>
)}
{step === 'success' && (
<div className="flex flex-col items-center justify-center py-6 gap-2">
<CheckCircle className="h-8 w-8 text-green-500" />
<p className="text-sm font-medium">Authentication successful</p>
</div>
)}
{step === 'error' && !error && (
<div className="flex flex-col items-center justify-center py-6 gap-2">
<XCircle className="h-8 w-8 text-destructive" />
<p className="text-sm text-muted-foreground">Something went wrong</p>
</div>
)}
</div>
<DialogFooter>
{step === 'enter_code' && (
<>
<Button
variant="outline"
onClick={() => setStep('method')}
disabled={loading}
>
Back
</Button>
<Button
onClick={handleCompleteAuth}
disabled={loading || !authCode.trim()}
>
{loading ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Authenticating...
</>
) : (
'Complete Authentication'
)}
</Button>
</>
<DialogFooter className="gap-2 sm:gap-0">
{step === 'error' && (
<Button variant="outline" onClick={handleRetry}>
Try Again
</Button>
)}
{(step === 'method' || step === 'manual') && (
{step !== 'success' && (
<Button
variant="outline"
onClick={() => handleOpenChange(false)}
@@ -264,3 +396,58 @@ export function McpOAuthDialog({
</Dialog>
)
}
function ManualCodeEntry({
showManualEntry,
setShowManualEntry,
authCode,
setAuthCode,
loading,
onSubmit,
}: {
showManualEntry: boolean
setShowManualEntry: (show: boolean) => void
authCode: string
setAuthCode: (code: string) => void
loading: boolean
onSubmit: () => void
}) {
return (
<div className="border-t border-border pt-3">
<button
type="button"
onClick={() => setShowManualEntry(!showManualEntry)}
className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors w-full"
>
{showManualEntry ? <ChevronUp className="h-3 w-3" /> : <ChevronDown className="h-3 w-3" />}
Paste authorization code manually
</button>
{showManualEntry && (
<div className="space-y-2 mt-3">
<p className="text-xs text-muted-foreground">
After authorizing, copy the <code className="bg-muted px-1 py-0.5 rounded">code</code> parameter from the redirect URL in your browser.
</p>
<Label htmlFor="auth-code" className="text-xs">Authorization Code</Label>
<div className="flex gap-2">
<Input
id="auth-code"
value={authCode}
onChange={(e) => setAuthCode(e.target.value)}
placeholder="Paste code here..."
disabled={loading}
className="text-sm"
/>
<Button
onClick={onSubmit}
disabled={loading || !authCode.trim()}
size="sm"
>
{loading ? <Loader2 className="h-4 w-4 animate-spin" /> : 'Submit'}
</Button>
</div>
</div>
)}
</div>
)
}
@@ -152,20 +152,20 @@ export function McpServerCard({
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{showAuthButton && onAuthenticate && (
<DropdownMenuItem onClick={() => onAuthenticate(serverId)}>
<DropdownMenuItem onSelect={() => setTimeout(() => onAuthenticate(serverId), 0)}>
<Key className="h-4 w-4 mr-2" />
Authenticate
</DropdownMenuItem>
)}
{connectedWithOAuth && onAuthenticate && (
<DropdownMenuItem onClick={() => onAuthenticate(serverId)}>
<DropdownMenuItem onSelect={() => setTimeout(() => onAuthenticate(serverId), 0)}>
<RefreshCw className="h-4 w-4 mr-2" />
Re-authenticate
</DropdownMenuItem>
)}
{connectedWithOAuth && onRemoveAuth && (
<DropdownMenuItem
onClick={() => onRemoveAuth(serverId)}
onSelect={() => setTimeout(() => onRemoveAuth(serverId), 0)}
disabled={isRemovingAuth}
>
<Shield className="h-4 w-4 mr-2" />
@@ -174,7 +174,9 @@ export function McpServerCard({
)}
{(showAuthButton || connectedWithOAuth) && <DropdownMenuSeparator />}
<DropdownMenuItem
onClick={() => onDeleteServer(serverId, displayName)}
onSelect={() => {
setTimeout(() => onDeleteServer(serverId, displayName), 0)
}}
className="text-red-600"
>
<Trash2 className="h-4 w-4 mr-2" />
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { Button } from '@/components/ui/button'
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { ExternalLink, Copy } from 'lucide-react'
import { Copy } from 'lucide-react'
import { oauthApi, type OAuthAuthorizeResponse } from '@/api/oauth'
import { mapOAuthError, OAuthMethod } from '@/lib/oauthErrors'
@@ -45,11 +45,11 @@ export function OAuthAuthorizeDialog({
return (
<Dialog open={open} onOpenChange={handleClose}>
<DialogContent className="bg-card border-border max-w-lg z-[200]" overlayClassName="z-[200]">
<DialogContent className="bg-card border-border max-w-lg">
<DialogHeader>
<DialogTitle>Connect to {providerName}</DialogTitle>
<DialogDescription>
Choose an authentication method to connect your {providerName} account.
Connect your {providerName} account using authorization code.
</DialogDescription>
</DialogHeader>
@@ -60,16 +60,6 @@ export function OAuthAuthorizeDialog({
)}
<div className="space-y-3">
<Button
onClick={() => handleAuthorize(OAuthMethod.AUTO)}
disabled={isLoading}
className="w-full justify-start"
variant="outline"
>
<ExternalLink className="h-4 w-4 mr-2" />
{isLoading ? 'Authorizing...' : 'Open Authorization Page'}
</Button>
<Button
onClick={() => handleAuthorize(OAuthMethod.CODE)}
disabled={isLoading}
@@ -82,7 +72,6 @@ export function OAuthAuthorizeDialog({
</div>
<div className="text-xs text-muted-foreground">
<p>• "Open Authorization Page" will open a browser window for you to sign in</p>
<p>• "Use Authorization Code" will give you a code to manually enter</p>
</div>
</DialogContent>
@@ -29,24 +29,6 @@ export function OAuthCallbackDialog({
const [authCode, setAuthCode] = useState('')
const [error, setError] = useState<string | null>(null)
const handleAutoCallback = async () => {
setIsLoading(true)
setLoadingMessage('Completing authentication...')
setError(null)
try {
setLoadingMessage('Restarting server with new credentials...')
await oauthApi.callback(providerId, { method: OAuthMethod.AUTO })
onSuccess()
} catch (err) {
setError(mapOAuthError(err, 'callback'))
console.error('OAuth callback error:', err)
} finally {
setIsLoading(false)
setLoadingMessage('')
}
}
const handleCodeCallback = async () => {
if (!authCode.trim()) {
setError('Please enter the authorization code')
@@ -82,14 +64,11 @@ export function OAuthCallbackDialog({
return (
<Dialog open={open} onOpenChange={handleClose}>
<DialogContent className="bg-card border-border max-w-lg z-[200]" overlayClassName="z-[200]">
<DialogContent className="bg-card border-border max-w-lg">
<DialogHeader>
<DialogTitle>Complete {providerName} Authentication</DialogTitle>
<DialogDescription>
{authResponse.method === 'auto'
? 'Follow the instructions to complete authentication.'
: 'Enter the authorization code from the provider.'
}
Enter the authorization code from the provider.
</DialogDescription>
</DialogHeader>
@@ -100,86 +79,50 @@ export function OAuthCallbackDialog({
)}
<div className="space-y-4">
{authResponse.method === 'auto' ? (
<div className="space-y-3">
<div className="bg-muted p-3 rounded-md">
<p className="text-sm">{authResponse.instructions}</p>
</div>
<div className="space-y-3">
<div className="bg-muted p-3 rounded-md">
<p className="text-sm mb-2">{authResponse.instructions}</p>
<Button
onClick={handleOpenAuthUrl}
variant="outline"
size="sm"
className="w-full"
disabled={isLoading}
>
<ExternalLink className="h-4 w-4 mr-2" />
Open Authorization Page
</Button>
</div>
<Button
onClick={handleAutoCallback}
variant="outline"
className="w-full"
<div className="space-y-2">
<Label htmlFor="authCode">Authorization Code</Label>
<Input
id="authCode"
value={authCode}
onChange={(e) => setAuthCode(e.target.value)}
placeholder="Enter the authorization code..."
className="bg-background border-border"
disabled={isLoading}
>
{isLoading ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
{loadingMessage || 'Completing...'}
</>
) : (
<>
<CheckCircle className="h-4 w-4 mr-2" />
I Completed Authorization
</>
)}
</Button>
/>
</div>
) : (
<div className="space-y-3">
<div className="bg-muted p-3 rounded-md">
<p className="text-sm mb-2">{authResponse.instructions}</p>
<Button
onClick={handleOpenAuthUrl}
variant="outline"
size="sm"
className="w-full"
>
<ExternalLink className="h-4 w-4 mr-2" />
Open Authorization Page
</Button>
</div>
<div className="space-y-2">
<Label htmlFor="authCode">Authorization Code</Label>
<Input
id="authCode"
value={authCode}
onChange={(e) => setAuthCode(e.target.value)}
placeholder="Enter the authorization code..."
className="bg-background border-border"
disabled={isLoading}
/>
</div>
<Button
onClick={handleCodeCallback}
className="w-full"
disabled={isLoading || !authCode.trim()}
>
{isLoading ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
{loadingMessage || 'Completing...'}
</>
) : (
<>
<CheckCircle className="h-4 w-4 mr-2" />
Complete Authentication
</>
)}
</Button>
</div>
)}
<Button
onClick={handleCodeCallback}
className="w-full"
disabled={isLoading || !authCode.trim()}
>
{isLoading ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
{loadingMessage || 'Completing...'}
</>
) : (
<>
<CheckCircle className="h-4 w-4 mr-2" />
Complete Authentication
</>
)}
</Button>
</div>
</div>
</DialogContent>
</Dialog>
@@ -70,7 +70,7 @@ export function OpenCodeConfigEditor({
return (
<Dialog open={isOpen} onOpenChange={(open) => !open && onClose()}>
<DialogContent mobileFullscreen className="gap-0 flex flex-col p-0 md:p-6 w-full min-w-0 sm:max-w-4xl max-h-[90vh] sm:max-h-[85vh] z-[200]" overlayClassName="z-[200]">
<DialogContent mobileFullscreen className="gap-0 flex flex-col p-0 md:p-6 w-full min-w-0 sm:max-w-4xl max-h-[90vh] sm:max-h-[85vh]">
<DialogHeader className="p-4 sm:p-6 border-b flex flex-row items-center justify-between space-y-0">
<DialogTitle className="text-lg sm:text-xl font-semibold">
{`Edit Config: ${config.name}`}
@@ -1,5 +1,5 @@
import { useState, useEffect, useRef } from 'react'
import { Loader2, Plus, Trash2, Edit, Star, StarOff, Download, RotateCcw, FileText, ArrowUpCircle, History } from 'lucide-react'
import { Loader2, Plus, Trash2, Edit, StarOff, Download, RotateCcw, FileText, ArrowUpCircle, History } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Label } from '@/components/ui/label'
@@ -434,64 +434,66 @@ export function OpenCodeConfigManager() {
</Card>
) : (
<div className="flex flex-col gap-4 md:grid md:grid-cols-2 lg:grid-cols">
{configs.map((config) => (
<Card key={config.id}>
<CardHeader className="pb-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 flex-wrap">
<CardTitle className="text-base">{config.name}</CardTitle>
{config.isDefault && (
<Badge variant="default" className="">
<Star className="h-4 w-4" />
</Badge>
)}
</div>
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="sm"
onClick={() => downloadConfig(config)}
>
<Download className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => startEdit(config)}
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => setDefaultConfig(config)}
disabled={config.isDefault || isUpdating}
>
{config.isDefault ? (
<StarOff className="h-4 w-4" />
) : (
<Star className="h-4 w-4" />
{configs
.sort((a, b) => {
if (a.isDefault) return -1
if (b.isDefault) return 1
return 0
})
.map((config) => (
<Card key={config.id} className={config.isDefault ? 'border-green-500' : ''}>
<CardHeader className="pb-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 flex-wrap">
<CardTitle className="text-base">{config.name}</CardTitle>
{config.isDefault && (
<Badge variant="default" className="text-green-500 bg-green-500/10">
Current
</Badge>
)}
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => setDeleteConfirmConfig(config)}
className="text-red-500 hover:text-red-600"
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="sm"
onClick={() => downloadConfig(config)}
>
<Download className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => startEdit(config)}
>
<Edit className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => setDefaultConfig(config)}
disabled={config.isDefault || isUpdating}
>
<StarOff className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => setDeleteConfirmConfig(config)}
className="text-red-500 hover:text-red-600"
>
<Trash2 className="h-4 w-4" />
</Button>
</div>
</div>
</div>
</CardHeader>
<CardContent>
<div className="text-sm text-muted-foreground break-words">
<p className="truncate">Updated: {new Date(config.updatedAt).toLocaleString()}</p>
<p className="truncate">Created: {new Date(config.createdAt).toLocaleString()}</p>
</div>
</CardContent>
</Card>
))}
</CardHeader>
<CardContent>
<div className="text-sm text-muted-foreground break-words">
<p className="truncate">Updated: {new Date(config.updatedAt).toLocaleString()}</p>
<p className="truncate">Created: {new Date(config.createdAt).toLocaleString()}</p>
</div>
</CardContent>
</Card>
))}
</div>
)}
@@ -69,7 +69,7 @@ export function SettingsDialog() {
<Dialog open={isOpen} modal={false}>
<DialogContent
ref={contentRef}
className="inset-0 w-full h-full max-w-none max-h-none p-0 rounded-none bg-gradient-to-br from-background via-background to-background border-border overflow-hidden !flex !flex-col z-[100]"
className="inset-0 w-full h-full max-w-none max-h-none p-0 rounded-none bg-gradient-to-br from-background via-background to-background border-border overflow-hidden !flex !flex-col"
style={swipeStyles}
fullscreen
>
@@ -80,7 +80,7 @@ export function VersionSelectDialog({ open, onOpenChange }: VersionSelectDialogP
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-md z-[200]" overlayClassName="z-[200]">
<DialogContent className="max-w-md">
<DialogHeader>
<DialogTitle>Select OpenCode Version</DialogTitle>
<DialogDescription>