refactor: improve virtualized text viewer with React Query infinite scroll and simplified buffering (#108)

* Add OAuth authentication support for MCP servers

* Improve mobile text sizing with responsive text classes

* refactor: improve virtualized text viewer with React Query infinite scroll and simplified buffering
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-05 20:18:27 -05:00
1 parent c453235839
commit f570758b74
24 files changed
+930 -471

No files matched your search

@@ -163,11 +163,11 @@ export function AccountSettings() {
<div className="space-y-3 sm:space-y-4">
<div className="space-y-1.5">
<Label className="text-xs sm:text-sm">Name</Label>
<Input value={user.name} disabled className="h-9 sm:h-10 text-sm" />
<Input value={user.name} disabled className="h-9 sm:h-10 md:text-sm" />
</div>
<div className="space-y-1.5">
<Label className="text-xs sm:text-sm">Email</Label>
<Input value={user.email} disabled className="h-9 sm:h-10 text-sm" />
<Input value={user.email} disabled className="h-9 sm:h-10 md:text-sm" />
</div>
<Button variant="outline" onClick={() => setEditingProfile(false)} className="h-9 sm:h-10">
Done
@@ -216,7 +216,7 @@ export function AccountSettings() {
value={currentPassword}
onChange={(e) => setCurrentPassword(e.target.value)}
placeholder="Enter current password"
className="h-9 sm:h-10 text-sm"
className="h-9 sm:h-10 md:text-sm"
/>
</div>
<div className="space-y-1.5">
@@ -227,7 +227,7 @@ export function AccountSettings() {
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
placeholder="At least 8 characters"
className="h-9 sm:h-10 text-sm"
className="h-9 sm:h-10 md:text-sm"
/>
</div>
<div className="flex gap-2">
@@ -271,7 +271,7 @@ export function AccountSettings() {
placeholder="Passkey name (optional)"
value={passkeyName}
onChange={(e) => setPasskeyName(e.target.value)}
className="h-9 sm:h-10 text-sm"
className="h-9 sm:h-10 md:text-sm"
/>
<Button
onClick={handleAddPasskey}
@@ -30,6 +30,10 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
const [environment, setEnvironment] = useState<EnvironmentVariable[]>([])
const [timeout, setTimeout] = useState('')
const [enabled, setEnabled] = useState(true)
const [oauthEnabled, setOauthEnabled] = useState(false)
const [oauthClientId, setOauthClientId] = useState('')
const [oauthClientSecret, setOauthClientSecret] = useState('')
const [oauthScope, setOauthScope] = useState('')
const queryClient = useQueryClient()
const { addServerAsync, isAddingServer } = useMcpServers()
@@ -67,6 +71,14 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
throw new Error('URL is required for remote MCP servers')
}
mcpConfig.url = url.trim()
if (oauthEnabled) {
const oauthConfig: Record<string, string> = {}
if (oauthClientId.trim()) oauthConfig.clientId = oauthClientId.trim()
if (oauthClientSecret.trim()) oauthConfig.clientSecret = oauthClientSecret.trim()
if (oauthScope.trim()) oauthConfig.scope = oauthScope.trim()
mcpConfig.oauth = Object.keys(oauthConfig).length > 0 ? oauthConfig : true
}
}
if (timeout && parseInt(timeout)) {
@@ -84,6 +96,15 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
await settingsApi.updateOpenCodeConfig(config.name, { content: updatedConfig })
if (enabled) {
const buildOauthField = () => {
if (serverType !== 'remote' || !oauthEnabled) return undefined
const cfg: Record<string, string> = {}
if (oauthClientId.trim()) cfg.clientId = oauthClientId.trim()
if (oauthClientSecret.trim()) cfg.clientSecret = oauthClientSecret.trim()
if (oauthScope.trim()) cfg.scope = oauthScope.trim()
return Object.keys(cfg).length > 0 ? cfg : true
}
await addServerAsync({
name: serverId,
config: {
@@ -100,6 +121,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
}, {} as Record<string, string>)
: undefined,
timeout: timeout && parseInt(timeout) ? parseInt(timeout) : undefined,
oauth: buildOauthField(),
}
})
}
@@ -146,6 +168,10 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
setEnvironment([])
setTimeout('')
setEnabled(true)
setOauthEnabled(false)
setOauthClientId('')
setOauthClientSecret('')
setOauthScope('')
onOpenChange(false)
}
@@ -153,149 +179,203 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
return (
<Dialog open={open} onOpenChange={handleClose}>
<DialogContent className="w-full max-w-3xl bg-card border-border">
<DialogHeader>
<DialogContent mobileFullscreen className="sm:inset-auto sm:left-[50%] sm:top-[50%] sm:w-[95vw] sm:max-w-3xl sm:h-auto sm:max-h-[90vh] flex flex-col gap-0 bg-card border-border pb-safe">
<DialogHeader className="px-4 sm:px-6 pt-4 sm:pt-6 pb-2 sm:pb-3 shrink-0">
<DialogTitle>Add MCP Server</DialogTitle>
<DialogDescription>
Configure a new Model Context Protocol server for your OpenCode configuration
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
<div>
<Label htmlFor="serverId">Server ID</Label>
<Input
id="serverId"
value={serverId}
onChange={(e) => setServerId(e.target.value)}
placeholder="e.g., filesystem, git, my-server"
className="bg-background border-border"
/>
<p className="text-xs text-muted-foreground">
Unique identifier for this MCP server (lowercase, no spaces)
</p>
</div>
<div>
<Label htmlFor="serverType">Server Type</Label>
<Select value={serverType} onValueChange={(value: 'local' | 'remote') => setServerType(value)}>
<SelectTrigger className="bg-background border-border">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="local">Local (Command)</SelectItem>
<SelectItem value="remote">Remote (HTTP)</SelectItem>
</SelectContent>
</Select>
</div>
{serverType === 'local' ? (
<div className="flex-1 overflow-y-auto min-h-0 px-4 sm:px-6 py-3 sm:py-4">
<div className="space-y-4">
<div>
<Label htmlFor="command">Command</Label>
<Label htmlFor="serverId">Server ID</Label>
<Input
id="command"
value={command}
onChange={(e) => setCommand(e.target.value)}
placeholder="npx @modelcontextprotocol/server-filesystem /tmp"
className="bg-background border-border font-mono"
id="serverId"
value={serverId}
onChange={(e) => setServerId(e.target.value)}
placeholder="e.g., filesystem, git, my-server"
className="bg-background border-border"
/>
<p className="text-xs text-muted-foreground">
Command and arguments to run the MCP server
Unique identifier for this MCP server (lowercase, no spaces)
</p>
</div>
) : (
<div>
<Label htmlFor="url">Server URL</Label>
<Input
id="url"
value={url}
onChange={(e) => setUrl(e.target.value)}
placeholder="http://localhost:3000/mcp"
className="bg-background border-border font-mono"
/>
<p className="text-xs text-muted-foreground">
URL of the remote MCP server
</p>
</div>
)}
{serverType === 'local' && (
<div>
<div className="flex items-center justify-between">
<Label>Environment Variables</Label>
<Button
type="button"
variant="outline"
size="sm"
className='h-6'
onClick={handleAddEnvironmentVar}
>
+
</Button>
<Label htmlFor="serverType">Server Type</Label>
<Select value={serverType} onValueChange={(value: 'local' | 'remote') => setServerType(value)}>
<SelectTrigger className="bg-background border-border">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="local">Local (Command)</SelectItem>
<SelectItem value="remote">Remote (HTTP)</SelectItem>
</SelectContent>
</Select>
</div>
{serverType === 'local' ? (
<div>
<Label htmlFor="command">Command</Label>
<Input
id="command"
value={command}
onChange={(e) => setCommand(e.target.value)}
placeholder="npx @modelcontextprotocol/server-filesystem /tmp"
className="bg-background border-border font-mono"
/>
<p className="text-xs text-muted-foreground">
Command and arguments to run the MCP server
</p>
</div>
{environment.map((env, index) => (
<div key={index} className="flex gap-2">
<Input
value={env.key}
onChange={(e) => handleUpdateEnvironmentVar(index, 'key', e.target.value)}
placeholder="API_KEY"
className="bg-background border-border font-mono"
) : (
<div>
<Label htmlFor="url">Server URL</Label>
<Input
id="url"
value={url}
onChange={(e) => setUrl(e.target.value)}
placeholder="http://localhost:3000/mcp"
className="bg-background border-border font-mono"
/>
<p className="text-xs text-muted-foreground">
URL of the remote MCP server
</p>
</div>
)}
{serverType === 'remote' && (
<div className="space-y-3">
<div className="flex items-center space-x-2">
<Switch
id="oauth"
checked={oauthEnabled}
onCheckedChange={setOauthEnabled}
/>
<Input
value={env.value}
onChange={(e) => handleUpdateEnvironmentVar(index, 'value', e.target.value)}
placeholder="your-api-key-here"
className="bg-background border-border font-mono"
/>
{environment.length > 1 && (
<Button
type="button"
variant="outline"
size="icon"
onClick={() => handleRemoveEnvironmentVar(index)}
>
x
</Button>
)}
<Label htmlFor="oauth">Enable OAuth</Label>
</div>
))}
{oauthEnabled && (
<div className="space-y-3 pl-4 border-l-2 border-border">
<p className="text-xs text-muted-foreground">
Leave fields blank to use the server's default OAuth discovery
</p>
<div>
<Label htmlFor="oauthClientId">Client ID</Label>
<Input
id="oauthClientId"
value={oauthClientId}
onChange={(e) => setOauthClientId(e.target.value)}
placeholder="Optional"
className="bg-background border-border font-mono"
/>
</div>
<div>
<Label htmlFor="oauthClientSecret">Client Secret</Label>
<Input
id="oauthClientSecret"
type="password"
value={oauthClientSecret}
onChange={(e) => setOauthClientSecret(e.target.value)}
placeholder="Optional"
className="bg-background border-border font-mono"
/>
</div>
<div>
<Label htmlFor="oauthScope">Scope</Label>
<Input
id="oauthScope"
value={oauthScope}
onChange={(e) => setOauthScope(e.target.value)}
placeholder="e.g., read write"
className="bg-background border-border font-mono"
/>
</div>
</div>
)}
</div>
)}
{serverType === 'local' && (
<div>
<div className="flex items-center justify-between">
<Label>Environment Variables</Label>
<Button
type="button"
variant="outline"
size="sm"
className='h-6'
onClick={handleAddEnvironmentVar}
>
+
</Button>
</div>
{environment.map((env, index) => (
<div key={index} className="flex gap-2">
<Input
value={env.key}
onChange={(e) => handleUpdateEnvironmentVar(index, 'key', e.target.value)}
placeholder="API_KEY"
className="bg-background border-border font-mono"
/>
<Input
value={env.value}
onChange={(e) => handleUpdateEnvironmentVar(index, 'value', e.target.value)}
placeholder="your-api-key-here"
className="bg-background border-border font-mono"
/>
{environment.length > 1 && (
<Button
type="button"
variant="outline"
size="icon"
onClick={() => handleRemoveEnvironmentVar(index)}
>
x
</Button>
)}
</div>
))}
<p className="text-xs text-muted-foreground">
Environment variables to set when running the MCP server
</p>
</div>
)}
<div>
<Label htmlFor="timeout">Timeout (ms)</Label>
<Input
id="timeout"
value={timeout}
onChange={(e) => setTimeout(e.target.value)}
placeholder="5000"
className="bg-background border-border"
/>
<p className="text-xs text-muted-foreground">
Environment variables to set when running the MCP server
Timeout in milliseconds for fetching tools (default: 5000)
</p>
</div>
)}
<div>
<Label htmlFor="timeout">Timeout (ms)</Label>
<Input
id="timeout"
value={timeout}
onChange={(e) => setTimeout(e.target.value)}
placeholder="5000"
className="bg-background border-border"
/>
<p className="text-xs text-muted-foreground">
Timeout in milliseconds for fetching tools (default: 5000)
</p>
</div>
<div className="flex items-center space-x-2">
<Switch
id="enabled"
checked={enabled}
onCheckedChange={setEnabled}
/>
<Label htmlFor="enabled">Connect immediately after adding</Label>
<div className="flex items-center space-x-2">
<Switch
id="enabled"
checked={enabled}
onCheckedChange={setEnabled}
/>
<Label htmlFor="enabled">Connect immediately after adding</Label>
</div>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={handleClose}>
<DialogFooter className="flex flex-row gap-2 w-full px-4 sm:px-6 pb-4 sm:pb-6 pt-3 shrink-0 border-t border-border gap-2">
<Button variant="outline" onClick={handleClose} className="flex-1">
Cancel
</Button>
<Button
onClick={handleAdd}
disabled={!serverId || isPending}
className="flex-1"
>
{isPending && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
Add MCP Server
@@ -233,7 +233,7 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
{...field}
placeholder="The system prompt that defines the agent's behavior and role"
rows={6}
className="font-mono text-sm"
className="font-mono md:text-sm"
/>
</FormControl>
<FormMessage />
@@ -122,7 +122,7 @@ export function AgentsMdEditor() {
<Textarea
value={content}
onChange={(e) => handleContentChange(e.target.value)}
className="font-mono text-sm min-h-[300px] resize-y"
className="font-mono md:text-sm min-h-[300px] resize-y"
placeholder="# Agent Instructions&#10;&#10;Add global instructions for AI agents here..."
/>
@@ -160,7 +160,7 @@ export function CommandDialog({
{...field}
placeholder="The prompt template that will be sent to the LLM. Use $ARGUMENTS or $1, $2, etc. for parameters."
rows={8}
className="font-mono text-sm"
className="font-mono md:text-sm"
/>
</FormControl>
<FormDescription>
@@ -138,7 +138,7 @@ export function CreateConfigDialog({ isOpen, onOpenChange, onCreate, isUpdating
onChange={(e) => handleContentChange(e.target.value)}
placeholder='{"$schema": "https://opencode.ai/config.json", "theme": "dark"}'
rows={12}
className="font-mono text-sm"
className="font-mono md:text-sm"
/>
{error && (
<p className="text-sm text-red-500 mt-2">
@@ -176,7 +176,7 @@ export function KeyboardShortcuts() {
<div className="flex items-center gap-2">
<input
type="text"
className="px-3 py-1.5 bg-accent border border-primary rounded text-sm text-foreground font-mono outline-none"
className="px-3 py-1.5 bg-accent border border-primary rounded text-[16px] md:text-sm text-foreground font-mono outline-none"
placeholder="Press keys..."
value={currentKeys || ''}
autoFocus
@@ -218,7 +218,7 @@ export function KeyboardShortcuts() {
<div className="flex items-center gap-2">
<input
type="text"
className="px-3 py-1.5 bg-accent border border-primary rounded text-sm text-foreground font-mono outline-none"
className="px-3 py-1.5 bg-accent border border-primary rounded text-[16px] md:text-sm text-foreground font-mono outline-none"
placeholder="Press keys..."
value={currentKeys || ''}
autoFocus
+85 -18
View File
@@ -1,23 +1,17 @@
import { useState } from 'react'
import { Button } from '@/components/ui/button'
import { Card, CardContent } from '@/components/ui/card'
import { Dialog, DialogTrigger } from '@/components/ui/dialog'
import { Plus, Loader2, RefreshCw } from 'lucide-react'
import { DeleteDialog } from '@/components/ui/delete-dialog'
import { AddMcpServerDialog } from './AddMcpServerDialog'
import { McpServerCard } from './McpServerCard'
import { McpOAuthDialog } from './McpOAuthDialog'
import { useMcpServers } from '@/hooks/useMcpServers'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { invalidateConfigCaches } from '@/lib/queryInvalidation'
interface McpServerConfig {
type: 'local' | 'remote'
enabled?: boolean
command?: string[]
url?: string
environment?: Record<string, string>
timeout?: number
}
import type { McpServerConfig } from '@/api/mcp'
import { mcpApi } from '@/api/mcp'
import type { McpAuthStartResponse } from '@/api/mcp'
interface McpManagerProps {
config: {
@@ -34,6 +28,8 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false)
const [deleteConfirmServer, setDeleteConfirmServer] = useState<{ id: string; name: string } | null>(null)
const [togglingServerId, setTogglingServerId] = useState<string | null>(null)
const [authDialogServerId, setAuthDialogServerId] = useState<string | null>(null)
const [removeAuthConfirmServer, setRemoveAuthConfirmServer] = useState<string | null>(null)
const queryClient = useQueryClient()
const {
@@ -43,6 +39,8 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
connect,
disconnect,
authenticate,
removeAuth,
isRemovingAuth,
isToggling
} = useMcpServers()
@@ -74,15 +72,24 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
const handleToggleServer = async (serverId: string) => {
const currentStatus = mcpStatus?.[serverId]
if (!currentStatus) return
const serverConfig = mcpServers[serverId]
const isRemote = serverConfig?.type === 'remote'
const hasOAuthConfig = isRemote && !!serverConfig?.oauth
const hasOAuthError = currentStatus.status === 'failed' && isRemote && /oauth|auth.*state/i.test(currentStatus.error)
const isOAuthServer = hasOAuthConfig || hasOAuthError || (currentStatus.status === 'needs_auth' && isRemote)
if (currentStatus.status === 'needs_auth' || (currentStatus.status === 'failed' && isOAuthServer)) {
setAuthDialogServerId(serverId)
return
}
setTogglingServerId(serverId)
try {
if (currentStatus.status === 'connected') {
await disconnect(serverId)
} else if (currentStatus.status === 'disabled') {
await connect(serverId)
} else if (currentStatus.status === 'needs_auth') {
await authenticate(serverId)
} else if (currentStatus.status === 'failed') {
await connect(serverId)
}
@@ -92,6 +99,40 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
}
}
const handleAuthenticate = (serverId: string) => {
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 handleOAuthCompleteAuth = async (code: string) => {
if (!authDialogServerId) return
await mcpApi.completeAuth(authDialogServerId, code)
refetchStatus()
setAuthDialogServerId(null)
}
const handleRemoveAuth = (serverId: string) => {
setRemoveAuthConfirmServer(serverId)
}
const handleConfirmRemoveAuth = () => {
if (removeAuthConfirmServer) {
removeAuth(removeAuthConfirmServer)
setRemoveAuthConfirmServer(null)
}
}
const handleDeleteServer = () => {
if (deleteConfirmServer) {
deleteServerMutation.mutate(deleteConfirmServer.id)
@@ -164,13 +205,11 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
</div>
{Object.keys(mcpServers).length === 0 ? (
<Card>
<CardContent className="p-2 sm:p-8 text-center">
<p className="text-muted-foreground">No MCP servers configured. Add your first server to get started.</p>
</CardContent>
</Card>
<div className="rounded-lg border border-border p-6 sm:p-8 text-center">
<p className="text-muted-foreground">No MCP servers configured. Add your first server to get started.</p>
</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<div className="space-y-2">
{Object.entries(mcpServers).map(([serverId, serverConfig]) => {
const status = mcpStatus?.[serverId]
const isConnected = status?.status === 'connected'
@@ -186,7 +225,10 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
errorMessage={errorMessage}
isAnyOperationPending={isAnyOperationPending}
togglingServerId={togglingServerId}
isRemovingAuth={isRemovingAuth}
onToggleServer={handleToggleServer}
onAuthenticate={handleAuthenticate}
onRemoveAuth={handleRemoveAuth}
onDeleteServer={(id, name) => setDeleteConfirmServer({ id, name })}
/>
)
@@ -204,6 +246,31 @@ export function McpManager({ config, onUpdate, onConfigUpdate }: McpManagerProps
itemName={deleteConfirmServer?.name}
isDeleting={deleteServerMutation.isPending}
/>
<McpOAuthDialog
open={!!authDialogServerId}
onOpenChange={(open) => !open && setAuthDialogServerId(null)}
serverName={authDialogServerId || ''}
onAutoAuth={handleOAuthAutoAuth}
onStartAuth={handleOAuthStartAuth}
onCompleteAuth={handleOAuthCompleteAuth}
/>
<DeleteDialog
open={!!removeAuthConfirmServer}
onOpenChange={() => setRemoveAuthConfirmServer(null)}
onConfirm={handleConfirmRemoveAuth}
onCancel={() => setRemoveAuthConfirmServer(null)}
title="Remove Authentication"
description="This will remove the OAuth credentials for this MCP server. You will need to re-authenticate to use this server again."
itemName={mcpServers[removeAuthConfirmServer || ''] ? getDisplayName(removeAuthConfirmServer || '') : ''}
isDeleting={isRemovingAuth}
/>
</div>
)
function getDisplayName(serverId: string): string {
const name = serverId.replace(/[-_]/g, ' ')
return name.charAt(0).toUpperCase() + name.slice(1)
}
}
@@ -0,0 +1,266 @@
import { useState } 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 type { McpAuthStartResponse } from '@/api/mcp'
interface McpOAuthDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
serverName: string
onAutoAuth: () => Promise<void>
onStartAuth: () => Promise<McpAuthStartResponse>
onCompleteAuth: (code: string) => Promise<void>
directory?: string
}
export function McpOAuthDialog({
open,
onOpenChange,
serverName,
onAutoAuth,
onStartAuth,
onCompleteAuth,
directory
}: McpOAuthDialogProps) {
const [step, setStep] = useState<'method' | 'auto' | 'manual' | 'enter_code'>('method')
const [loading, setLoading] = useState(false)
const [authUrl, setAuthUrl] = useState<string | null>(null)
const [authCode, setAuthCode] = useState('')
const [error, setError] = useState<string | null>(null)
const handleAutoAuth = async () => {
setLoading(true)
setError(null)
setStep('auto')
try {
await onAutoAuth()
onOpenChange(false)
resetState()
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to authenticate')
setStep('method')
} finally {
setLoading(false)
}
}
const handleStartManualAuth = async () => {
setLoading(true)
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)
}
}
const handleCompleteAuth = async () => {
if (!authCode.trim()) return
setLoading(true)
setError(null)
try {
await onCompleteAuth(authCode.trim())
onOpenChange(false)
resetState()
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to complete authentication')
} finally {
setLoading(false)
}
}
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()
}
onOpenChange(newOpen)
}
const scopes = directory ? 'this location' : 'global'
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogContent className="max-w-md">
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Key className="h-5 w-5" />
Connect {serverName}
</DialogTitle>
<DialogDescription>
Authenticate to use this MCP server for {scopes}
</DialogDescription>
</DialogHeader>
<div className="space-y-4 py-4">
{error && (
<Alert variant="destructive">
<XCircle className="h-4 w-4" />
<AlertDescription>{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>
</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 && (
<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.
</p>
<Button
onClick={handleOpenAuthUrl}
className="w-full"
>
<ExternalLink className="h-4 w-4 mr-2" />
Open Auth Page
</Button>
<div className="text-xs text-muted-foreground break-all bg-muted p-2 rounded">
{authUrl}
</div>
</div>
)}
{step === 'enter_code' && (
<div className="space-y-3">
<p className="text-sm text-muted-foreground">
Paste the authorization code from the browser:
</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>
</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>
</>
)}
{(step === 'method' || step === 'manual') && (
<Button
variant="outline"
onClick={() => handleOpenChange(false)}
disabled={loading}
>
Cancel
</Button>
)}
</DialogFooter>
</DialogContent>
</Dialog>
)
}
@@ -1,18 +1,10 @@
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Badge } from '@/components/ui/badge'
import { Switch } from '@/components/ui/switch'
import { Button } from '@/components/ui/button'
import { Trash2, XCircle, AlertCircle, Key } from 'lucide-react'
import type { McpStatus } from '@/api/mcp'
interface McpServerConfig {
type: 'local' | 'remote'
enabled?: boolean
command?: string[]
url?: string
environment?: Record<string, string>
timeout?: number
}
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'
import { DropdownMenuSeparator } from '@/components/ui/dropdown-menu'
import { XCircle, AlertCircle, Key, MoreVertical, Shield, Trash2, RefreshCw } from 'lucide-react'
import type { McpStatus, McpServerConfig } from '@/api/mcp'
interface McpServerCardProps {
serverId: string
@@ -22,7 +14,10 @@ interface McpServerCardProps {
errorMessage: string | null
isAnyOperationPending: boolean
togglingServerId: string | null
isRemovingAuth: boolean
onToggleServer: (serverId: string) => void
onAuthenticate?: (serverId: string) => void
onRemoveAuth?: (serverId: string) => void
onDeleteServer: (serverId: string, serverName: string) => void
}
@@ -91,55 +86,103 @@ export function McpServerCard({
errorMessage,
isAnyOperationPending,
togglingServerId,
isRemovingAuth,
onToggleServer,
onAuthenticate,
onRemoveAuth,
onDeleteServer
}: McpServerCardProps) {
const needsAuth = status?.status === 'needs_auth'
const isRemote = serverConfig.type === 'remote'
const hasOAuthConfig = isRemote && !!serverConfig.oauth
const hasOAuthError = status?.status === 'failed' && isRemote && /oauth|auth.*state/i.test(status.error)
const isOAuthServer = hasOAuthConfig || hasOAuthError || (needsAuth && isRemote)
const connectedWithOAuth = isOAuthServer && isConnected
const showAuthButton = needsAuth || (isOAuthServer && status?.status === 'failed')
const displayName = getServerDisplayName(serverId)
return (
<Card key={serverId} className={errorMessage ? 'border-red-500/50' : ''}>
<CardHeader className="pb-3">
<div className="flex flex-col gap-4">
<div className="flex items-center justify-between">
<CardTitle className="text-lg">{getServerDisplayName(serverId)}</CardTitle>
<div className="flex items-center gap-2">
{status ? getStatusBadge(status) : (
<Badge variant="outline" className="text-xs">Loading...</Badge>
)}
</div>
<div className={`flex items-center justify-between gap-3 p-3 rounded-lg border bg-card ${errorMessage ? 'border-red-500/50' : 'border-border'}`}>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 mb-0.5">
<p className="text-sm font-medium truncate">{displayName}</p>
{connectedWithOAuth && (
<span title="OAuth authenticated">
<Shield className="h-3 w-3 text-muted-foreground" />
</span>
)}
{status ? getStatusBadge(status) : (
<Badge variant="outline" className="text-xs">Loading...</Badge>
)}
</div>
<p className="text-xs text-muted-foreground truncate">
{getServerDescription(serverConfig)}
</p>
{errorMessage && (
<div className="flex items-start gap-1.5 mt-1.5 text-xs text-red-500">
<XCircle className="h-3 w-3 flex-shrink-0 mt-0.5" />
<span className="break-words line-clamp-2">{errorMessage}</span>
</div>
<div className="flex items-center gap-2">
<Switch
checked={isConnected}
onCheckedChange={() => onToggleServer(serverId)}
disabled={isAnyOperationPending || togglingServerId === serverId}
/>
<Button
variant="ghost"
size="sm"
onClick={() => onDeleteServer(serverId, getServerDisplayName(serverId))}
className="text-red-500 hover:text-red-600"
>
<Trash2 className="h-4 w-4" />
)}
</div>
<div className="flex items-center gap-2 flex-shrink-0">
{showAuthButton && onAuthenticate ? (
<Button
onClick={() => onAuthenticate(serverId)}
disabled={isAnyOperationPending || togglingServerId === serverId}
variant="default"
size="sm"
>
<Key className="h-3 w-3 mr-1" />
Auth
</Button>
) : (
<Switch
checked={isConnected}
onCheckedChange={() => onToggleServer(serverId)}
disabled={isAnyOperationPending || togglingServerId === serverId}
/>
)}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="sm" className="h-8 w-8 p-0">
<MoreVertical className="h-4 w-4" />
</Button>
</div>
</div>
</CardHeader>
<CardContent className='p-2'>
<div className="text-sm text-muted-foreground space-y-1">
<p>{getServerDescription(serverConfig)}</p>
{serverConfig.timeout && (
<p>Timeout: {serverConfig.timeout}ms</p>
)}
{serverConfig.environment && Object.keys(serverConfig.environment).length > 0 && (
<p>Environment variables: {Object.keys(serverConfig.environment).length} configured</p>
)}
{errorMessage && (
<div className="flex items-start gap-2 mt-2 p-2 bg-red-500/10 rounded text-red-600 text-xs">
<XCircle className="h-4 w-4 flex-shrink-0 mt-0.5" />
<span className="break-words">{errorMessage}</span>
</div>
)}
</div>
</CardContent>
</Card>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{showAuthButton && onAuthenticate && (
<DropdownMenuItem onClick={() => onAuthenticate(serverId)}>
<Key className="h-4 w-4 mr-2" />
Authenticate
</DropdownMenuItem>
)}
{connectedWithOAuth && onAuthenticate && (
<DropdownMenuItem onClick={() => onAuthenticate(serverId)}>
<RefreshCw className="h-4 w-4 mr-2" />
Re-authenticate
</DropdownMenuItem>
)}
{connectedWithOAuth && onRemoveAuth && (
<DropdownMenuItem
onClick={() => onRemoveAuth(serverId)}
disabled={isRemovingAuth}
>
<Shield className="h-4 w-4 mr-2" />
{isRemovingAuth ? 'Removing...' : 'Remove Auth'}
</DropdownMenuItem>
)}
{(showAuthButton || connectedWithOAuth) && <DropdownMenuSeparator />}
<DropdownMenuItem
onClick={() => onDeleteServer(serverId, displayName)}
className="text-red-600"
>
<Trash2 className="h-4 w-4 mr-2" />
Delete Server
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
)
}
@@ -87,7 +87,7 @@ export function OpenCodeConfigEditor({
setEditError('')
setEditErrorLine(null)
}}
className="flex-1 font-mono text-xs sm:text-sm resize-none h-full rounded-none sm:rounded-md"
className="flex-1 font-mono text-[16px] sm:text-xs md:text-sm resize-none h-full rounded-none sm:rounded-md"
/>
{editError && (
<div className="absolute bottom-0 left-0 right-0 bg-background/95 border-t p-2 sm:p-3">
@@ -353,7 +353,7 @@ export function ProviderSettings() {
placeholder="Search providers..."
value={availableSearch}
onChange={(e) => setAvailableSearch(e.target.value)}
className="pl-9 text-sm"
className="pl-9 md:text-sm"
/>
</div>
@@ -262,7 +262,7 @@ export function STTSettings() {
<input
type="text"
placeholder="https://api.openai.com"
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-[16px] md:text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
{...field}
/>
</FormControl>
@@ -285,7 +285,7 @@ export function STTSettings() {
<input
type={showApiKey ? 'text' : 'password'}
placeholder="sk-..."
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 pr-10 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 pr-10 text-[16px] md:text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
{...field}
/>
<button