mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-01 20:23:36 +00:00
Merge pull request #286 from mzubair481/feature/mcp-server-support
feat: add MCP server support
This commit is contained in:
@@ -178,6 +178,13 @@ export function ContextView() {
|
||||
// Ensure context directory exists
|
||||
await api.mkdir(contextPath);
|
||||
|
||||
// Ensure metadata file exists (create empty one if not)
|
||||
const metadataPath = `${contextPath}/context-metadata.json`;
|
||||
const metadataExists = await api.exists(metadataPath);
|
||||
if (!metadataExists) {
|
||||
await api.writeFile(metadataPath, JSON.stringify({ files: {} }, null, 2));
|
||||
}
|
||||
|
||||
// Load metadata for descriptions
|
||||
const metadata = await loadMetadata();
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import { AudioSection } from './settings-view/audio/audio-section';
|
||||
import { KeyboardShortcutsSection } from './settings-view/keyboard-shortcuts/keyboard-shortcuts-section';
|
||||
import { FeatureDefaultsSection } from './settings-view/feature-defaults/feature-defaults-section';
|
||||
import { DangerZoneSection } from './settings-view/danger-zone/danger-zone-section';
|
||||
import { MCPServersSection } from './settings-view/mcp-servers';
|
||||
import type { Project as SettingsProject, Theme } from './settings-view/shared/types';
|
||||
import type { Project as ElectronProject } from '@/lib/electron';
|
||||
|
||||
@@ -116,6 +117,8 @@ export function SettingsView() {
|
||||
{showUsageTracking && <ClaudeUsageSection />}
|
||||
</div>
|
||||
);
|
||||
case 'mcp-servers':
|
||||
return <MCPServersSection />;
|
||||
case 'ai-enhancement':
|
||||
return <AIEnhancementSection />;
|
||||
case 'appearance':
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
FlaskConical,
|
||||
Trash2,
|
||||
Sparkles,
|
||||
Plug,
|
||||
} from 'lucide-react';
|
||||
import type { SettingsViewId } from '../hooks/use-settings-view';
|
||||
|
||||
@@ -22,6 +23,7 @@ export interface NavigationItem {
|
||||
export const NAV_ITEMS: NavigationItem[] = [
|
||||
{ id: 'api-keys', label: 'API Keys', icon: Key },
|
||||
{ id: 'claude', label: 'Claude', icon: Terminal },
|
||||
{ id: 'mcp-servers', label: 'MCP Servers', icon: Plug },
|
||||
{ id: 'ai-enhancement', label: 'AI Enhancement', icon: Sparkles },
|
||||
{ id: 'appearance', label: 'Appearance', icon: Palette },
|
||||
{ id: 'terminal', label: 'Terminal', icon: SquareTerminal },
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useState, useCallback } from 'react';
|
||||
export type SettingsViewId =
|
||||
| 'api-keys'
|
||||
| 'claude'
|
||||
| 'mcp-servers'
|
||||
| 'ai-enhancement'
|
||||
| 'appearance'
|
||||
| 'terminal'
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export { MCPServerHeader } from './mcp-server-header';
|
||||
export { MCPPermissionSettings } from './mcp-permission-settings';
|
||||
export { MCPToolsWarning } from './mcp-tools-warning';
|
||||
export { MCPServerCard } from './mcp-server-card';
|
||||
@@ -0,0 +1,96 @@
|
||||
import { ShieldAlert } from 'lucide-react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { syncSettingsToServer } from '@/hooks/use-settings-migration';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface MCPPermissionSettingsProps {
|
||||
mcpAutoApproveTools: boolean;
|
||||
mcpUnrestrictedTools: boolean;
|
||||
onAutoApproveChange: (checked: boolean) => void;
|
||||
onUnrestrictedChange: (checked: boolean) => void;
|
||||
}
|
||||
|
||||
export function MCPPermissionSettings({
|
||||
mcpAutoApproveTools,
|
||||
mcpUnrestrictedTools,
|
||||
onAutoApproveChange,
|
||||
onUnrestrictedChange,
|
||||
}: MCPPermissionSettingsProps) {
|
||||
const hasAnyEnabled = mcpAutoApproveTools || mcpUnrestrictedTools;
|
||||
|
||||
return (
|
||||
<div className="px-6 py-4 border-b border-border/50 bg-muted/20">
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<Switch
|
||||
id="mcp-auto-approve"
|
||||
checked={mcpAutoApproveTools}
|
||||
onCheckedChange={async (checked) => {
|
||||
onAutoApproveChange(checked);
|
||||
await syncSettingsToServer();
|
||||
}}
|
||||
data-testid="mcp-auto-approve-toggle"
|
||||
className="mt-0.5"
|
||||
/>
|
||||
<div className="space-y-1 flex-1">
|
||||
<Label htmlFor="mcp-auto-approve" className="text-sm font-medium cursor-pointer">
|
||||
Auto-approve MCP tool calls
|
||||
</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
When enabled, the AI agent can use MCP tools without permission prompts.
|
||||
</p>
|
||||
{mcpAutoApproveTools && (
|
||||
<p className="text-xs text-amber-600 flex items-center gap-1 mt-1">
|
||||
<ShieldAlert className="h-3 w-3" />
|
||||
Bypasses normal permission checks
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-3">
|
||||
<Switch
|
||||
id="mcp-unrestricted"
|
||||
checked={mcpUnrestrictedTools}
|
||||
onCheckedChange={async (checked) => {
|
||||
onUnrestrictedChange(checked);
|
||||
await syncSettingsToServer();
|
||||
}}
|
||||
data-testid="mcp-unrestricted-toggle"
|
||||
className="mt-0.5"
|
||||
/>
|
||||
<div className="space-y-1 flex-1">
|
||||
<Label htmlFor="mcp-unrestricted" className="text-sm font-medium cursor-pointer">
|
||||
Unrestricted tool access
|
||||
</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
When enabled, the AI agent can use any tool, not just the default set.
|
||||
</p>
|
||||
{mcpUnrestrictedTools && (
|
||||
<p className="text-xs text-amber-600 flex items-center gap-1 mt-1">
|
||||
<ShieldAlert className="h-3 w-3" />
|
||||
Agent has full tool access including file writes and bash
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{hasAnyEnabled && (
|
||||
<div
|
||||
className={cn(
|
||||
'rounded-md border border-amber-500/30 bg-amber-500/10 p-3 mt-2',
|
||||
'text-xs text-amber-700 dark:text-amber-400'
|
||||
)}
|
||||
>
|
||||
<p className="font-medium mb-1">Security Note</p>
|
||||
<p>
|
||||
These settings reduce security restrictions for MCP tool usage. Only enable if you
|
||||
trust all configured MCP servers.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import { ChevronDown, ChevronRight, Code, Pencil, Trash2, PlayCircle, Loader2 } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
||||
import { cn } from '@/lib/utils';
|
||||
import type { MCPServerConfig } from '@automaker/types';
|
||||
import type { ServerTestState } from '../types';
|
||||
import { getServerIcon, getTestStatusIcon, maskSensitiveUrl } from '../utils';
|
||||
import { MCPToolsList } from '../mcp-tools-list';
|
||||
|
||||
interface MCPServerCardProps {
|
||||
server: MCPServerConfig;
|
||||
testState?: ServerTestState;
|
||||
isExpanded: boolean;
|
||||
onToggleExpanded: () => void;
|
||||
onTest: () => void;
|
||||
onToggleEnabled: () => void;
|
||||
onEditJson: () => void;
|
||||
onEdit: () => void;
|
||||
onDelete: () => void;
|
||||
}
|
||||
|
||||
export function MCPServerCard({
|
||||
server,
|
||||
testState,
|
||||
isExpanded,
|
||||
onToggleExpanded,
|
||||
onTest,
|
||||
onToggleEnabled,
|
||||
onEditJson,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: MCPServerCardProps) {
|
||||
const Icon = getServerIcon(server.type);
|
||||
const hasTools = testState?.tools && testState.tools.length > 0;
|
||||
|
||||
return (
|
||||
<Collapsible open={isExpanded} onOpenChange={onToggleExpanded}>
|
||||
<div
|
||||
className={cn(
|
||||
'rounded-xl border',
|
||||
server.enabled !== false
|
||||
? 'border-border/50 bg-accent/20'
|
||||
: 'border-border/30 bg-muted/30 opacity-60'
|
||||
)}
|
||||
data-testid={`mcp-server-${server.id}`}
|
||||
>
|
||||
<div className="flex items-center justify-between p-4 gap-2">
|
||||
<div className="flex items-center gap-3 min-w-0 flex-1 overflow-hidden">
|
||||
<CollapsibleTrigger asChild>
|
||||
<button
|
||||
className={cn(
|
||||
'flex items-center gap-3 text-left min-w-0 flex-1',
|
||||
hasTools && 'cursor-pointer hover:opacity-80'
|
||||
)}
|
||||
disabled={!hasTools}
|
||||
>
|
||||
{hasTools ? (
|
||||
isExpanded ? (
|
||||
<ChevronDown className="w-4 h-4 text-muted-foreground shrink-0" />
|
||||
) : (
|
||||
<ChevronRight className="w-4 h-4 text-muted-foreground shrink-0" />
|
||||
)
|
||||
) : (
|
||||
<div className="w-4 shrink-0" />
|
||||
)}
|
||||
<div
|
||||
className={cn(
|
||||
'w-8 h-8 rounded-lg flex items-center justify-center shrink-0',
|
||||
server.enabled !== false ? 'bg-brand-500/20' : 'bg-muted'
|
||||
)}
|
||||
>
|
||||
<Icon className="w-4 h-4 text-brand-500" />
|
||||
</div>
|
||||
<div className="min-w-0 flex-1 overflow-hidden">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="font-medium text-sm truncate">{server.name}</span>
|
||||
{testState && getTestStatusIcon(testState.status)}
|
||||
{testState?.status === 'success' && testState.tools && (
|
||||
<span className="text-xs text-muted-foreground bg-muted px-1.5 py-0.5 rounded whitespace-nowrap">
|
||||
{testState.tools.length} tool{testState.tools.length !== 1 ? 's' : ''}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{server.description && (
|
||||
<div className="text-xs text-muted-foreground truncate">
|
||||
{server.description}
|
||||
</div>
|
||||
)}
|
||||
<div className="text-xs text-muted-foreground/60 mt-0.5 truncate">
|
||||
{server.type === 'stdio'
|
||||
? `${server.command}${server.args?.length ? ' ' + server.args.join(' ') : ''}`
|
||||
: maskSensitiveUrl(server.url || '')}
|
||||
</div>
|
||||
{testState?.status === 'error' && testState.error && (
|
||||
<div className="text-xs text-destructive mt-1 line-clamp-2 break-words">
|
||||
{testState.error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 shrink-0 ml-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={onTest}
|
||||
disabled={testState?.status === 'testing' || server.enabled === false}
|
||||
data-testid={`mcp-server-test-${server.id}`}
|
||||
className="h-8 px-2"
|
||||
>
|
||||
{testState?.status === 'testing' ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
) : (
|
||||
<PlayCircle className="w-4 h-4" />
|
||||
)}
|
||||
<span className="ml-1.5 text-xs">Test</span>
|
||||
</Button>
|
||||
<Switch
|
||||
checked={server.enabled !== false}
|
||||
onCheckedChange={onToggleEnabled}
|
||||
data-testid={`mcp-server-toggle-${server.id}`}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onEditJson}
|
||||
title="Edit JSON"
|
||||
data-testid={`mcp-server-json-${server.id}`}
|
||||
>
|
||||
<Code className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onEdit}
|
||||
data-testid={`mcp-server-edit-${server.id}`}
|
||||
>
|
||||
<Pencil className="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-destructive hover:text-destructive"
|
||||
onClick={onDelete}
|
||||
data-testid={`mcp-server-delete-${server.id}`}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{hasTools && (
|
||||
<CollapsibleContent>
|
||||
<div className="px-4 pb-4 pt-0 ml-7 overflow-hidden">
|
||||
<div className="text-xs font-medium text-muted-foreground mb-2">Available Tools</div>
|
||||
<MCPToolsList
|
||||
tools={testState.tools!}
|
||||
isLoading={testState.status === 'testing'}
|
||||
error={testState.error}
|
||||
className="max-w-full"
|
||||
/>
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
)}
|
||||
</div>
|
||||
</Collapsible>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Plug, RefreshCw, Download, Code, FileJson, Plus } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface MCPServerHeaderProps {
|
||||
isRefreshing: boolean;
|
||||
hasServers: boolean;
|
||||
onRefresh: () => void;
|
||||
onExport: () => void;
|
||||
onEditAllJson: () => void;
|
||||
onImport: () => void;
|
||||
onAdd: () => void;
|
||||
}
|
||||
|
||||
export function MCPServerHeader({
|
||||
isRefreshing,
|
||||
hasServers,
|
||||
onRefresh,
|
||||
onExport,
|
||||
onEditAllJson,
|
||||
onImport,
|
||||
onAdd,
|
||||
}: MCPServerHeaderProps) {
|
||||
return (
|
||||
<div className="p-6 border-b border-border/50 bg-linear-to-r from-transparent via-accent/5 to-transparent">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<div className="flex items-center gap-3 mb-2">
|
||||
<div className="w-9 h-9 rounded-xl bg-linear-to-br from-brand-500/20 to-brand-600/10 flex items-center justify-center border border-brand-500/20">
|
||||
<Plug className="w-5 h-5 text-brand-500" />
|
||||
</div>
|
||||
<h2 className="text-lg font-semibold text-foreground tracking-tight">MCP Servers</h2>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground/80 ml-12">
|
||||
Configure Model Context Protocol servers to extend agent capabilities.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={onRefresh}
|
||||
disabled={isRefreshing}
|
||||
data-testid="refresh-mcp-servers-button"
|
||||
>
|
||||
<RefreshCw className={cn('w-4 h-4', isRefreshing && 'animate-spin')} />
|
||||
</Button>
|
||||
{hasServers && (
|
||||
<>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={onExport}
|
||||
data-testid="export-mcp-servers-button"
|
||||
>
|
||||
<Download className="w-4 h-4 mr-2" />
|
||||
Export
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={onEditAllJson}
|
||||
data-testid="edit-all-json-button"
|
||||
>
|
||||
<Code className="w-4 h-4 mr-2" />
|
||||
Edit JSON
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={onImport}
|
||||
data-testid="import-mcp-servers-button"
|
||||
>
|
||||
<FileJson className="w-4 h-4 mr-2" />
|
||||
Import JSON
|
||||
</Button>
|
||||
<Button size="sm" onClick={onAdd} data-testid="add-mcp-server-button">
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
Add Server
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { AlertTriangle } from 'lucide-react';
|
||||
import { MAX_RECOMMENDED_TOOLS } from '../constants';
|
||||
|
||||
interface MCPToolsWarningProps {
|
||||
totalTools: number;
|
||||
}
|
||||
|
||||
export function MCPToolsWarning({ totalTools }: MCPToolsWarningProps) {
|
||||
return (
|
||||
<div className="mx-6 mt-4 p-3 rounded-lg border border-yellow-500/50 bg-yellow-500/10">
|
||||
<div className="flex items-start gap-3">
|
||||
<AlertTriangle className="w-5 h-5 text-yellow-500 shrink-0 mt-0.5" />
|
||||
<div className="text-sm">
|
||||
<p className="font-medium text-yellow-600 dark:text-yellow-400">
|
||||
High tool count detected ({totalTools} tools)
|
||||
</p>
|
||||
<p className="text-muted-foreground mt-1">
|
||||
Having more than {MAX_RECOMMENDED_TOOLS} MCP tools may degrade AI model performance.
|
||||
Consider disabling unused servers or removing unnecessary tools.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Patterns that indicate sensitive values in URLs or config
|
||||
export const SENSITIVE_PARAM_PATTERNS = [
|
||||
/api[-_]?key/i,
|
||||
/api[-_]?token/i,
|
||||
/auth/i,
|
||||
/token/i,
|
||||
/secret/i,
|
||||
/password/i,
|
||||
/credential/i,
|
||||
/bearer/i,
|
||||
];
|
||||
|
||||
// Maximum recommended MCP tools before performance degradation
|
||||
export const MAX_RECOMMENDED_TOOLS = 80;
|
||||
@@ -0,0 +1,161 @@
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import type { MCPServerConfig } from '@automaker/types';
|
||||
import type { ServerFormData, ServerType } from '../types';
|
||||
|
||||
interface AddEditServerDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
editingServer: MCPServerConfig | null;
|
||||
formData: ServerFormData;
|
||||
onFormDataChange: (data: ServerFormData) => void;
|
||||
onSave: () => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function AddEditServerDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
editingServer,
|
||||
formData,
|
||||
onFormDataChange,
|
||||
onSave,
|
||||
onCancel,
|
||||
}: AddEditServerDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent data-testid="mcp-server-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editingServer ? 'Edit MCP Server' : 'Add MCP Server'}</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure an MCP server to extend agent capabilities with custom tools.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="server-name">Name</Label>
|
||||
<Input
|
||||
id="server-name"
|
||||
value={formData.name}
|
||||
onChange={(e) => onFormDataChange({ ...formData, name: e.target.value })}
|
||||
placeholder="my-mcp-server"
|
||||
data-testid="mcp-server-name-input"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="server-description">Description (optional)</Label>
|
||||
<Input
|
||||
id="server-description"
|
||||
value={formData.description}
|
||||
onChange={(e) => onFormDataChange({ ...formData, description: e.target.value })}
|
||||
placeholder="What this server provides..."
|
||||
data-testid="mcp-server-description-input"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="server-type">Transport Type</Label>
|
||||
<Select
|
||||
value={formData.type}
|
||||
onValueChange={(value: ServerType) => onFormDataChange({ ...formData, type: value })}
|
||||
>
|
||||
<SelectTrigger id="server-type" data-testid="mcp-server-type-select">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="stdio">Stdio (subprocess)</SelectItem>
|
||||
<SelectItem value="sse">SSE (Server-Sent Events)</SelectItem>
|
||||
<SelectItem value="http">HTTP</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{formData.type === 'stdio' ? (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="server-command">Command</Label>
|
||||
<Input
|
||||
id="server-command"
|
||||
value={formData.command}
|
||||
onChange={(e) => onFormDataChange({ ...formData, command: e.target.value })}
|
||||
placeholder="npx, node, python, etc."
|
||||
data-testid="mcp-server-command-input"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="server-args">Arguments (space-separated)</Label>
|
||||
<Input
|
||||
id="server-args"
|
||||
value={formData.args}
|
||||
onChange={(e) => onFormDataChange({ ...formData, args: e.target.value })}
|
||||
placeholder="-y @modelcontextprotocol/server-filesystem"
|
||||
data-testid="mcp-server-args-input"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="server-env">Environment Variables (JSON, optional)</Label>
|
||||
<Textarea
|
||||
id="server-env"
|
||||
value={formData.env}
|
||||
onChange={(e) => onFormDataChange({ ...formData, env: e.target.value })}
|
||||
placeholder={'{\n "API_KEY": "your-key"\n}'}
|
||||
className="font-mono text-sm h-24"
|
||||
data-testid="mcp-server-env-input"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="server-url">URL</Label>
|
||||
<Input
|
||||
id="server-url"
|
||||
value={formData.url}
|
||||
onChange={(e) => onFormDataChange({ ...formData, url: e.target.value })}
|
||||
placeholder="https://example.com/mcp"
|
||||
data-testid="mcp-server-url-input"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="server-headers">Headers (JSON, optional)</Label>
|
||||
<Textarea
|
||||
id="server-headers"
|
||||
value={formData.headers}
|
||||
onChange={(e) => onFormDataChange({ ...formData, headers: e.target.value })}
|
||||
placeholder={
|
||||
'{\n "x-api-key": "your-api-key",\n "Authorization": "Bearer token"\n}'
|
||||
}
|
||||
className="font-mono text-sm h-24"
|
||||
data-testid="mcp-server-headers-input"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={onSave} data-testid="mcp-server-save-button">
|
||||
{editingServer ? 'Save Changes' : 'Add Server'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
interface DeleteServerDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onConfirm: () => void;
|
||||
}
|
||||
|
||||
export function DeleteServerDialog({ open, onOpenChange, onConfirm }: DeleteServerDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent data-testid="mcp-server-delete-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Delete MCP Server</DialogTitle>
|
||||
<DialogDescription>
|
||||
Are you sure you want to delete this MCP server? This action cannot be undone.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={onConfirm}
|
||||
data-testid="mcp-server-confirm-delete-button"
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { Code } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
interface GlobalJsonEditDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
jsonValue: string;
|
||||
onJsonValueChange: (value: string) => void;
|
||||
onSave: () => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function GlobalJsonEditDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
jsonValue,
|
||||
onJsonValueChange,
|
||||
onSave,
|
||||
onCancel,
|
||||
}: GlobalJsonEditDialogProps) {
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
onCancel();
|
||||
} else {
|
||||
onOpenChange(open);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent className="max-w-3xl max-h-[90vh]" data-testid="mcp-global-json-edit-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit All MCP Servers</DialogTitle>
|
||||
<DialogDescription>
|
||||
Edit the full MCP servers configuration. Add, modify, or remove servers directly in
|
||||
JSON. Servers removed from JSON will be deleted.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4">
|
||||
<Textarea
|
||||
value={jsonValue}
|
||||
onChange={(e) => onJsonValueChange(e.target.value)}
|
||||
placeholder={`{
|
||||
"mcpServers": {
|
||||
"server-name": {
|
||||
"type": "stdio",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-name"]
|
||||
}
|
||||
}
|
||||
}`}
|
||||
className="font-mono text-sm h-[50vh] min-h-[300px]"
|
||||
data-testid="mcp-global-json-edit-textarea"
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onSave}
|
||||
disabled={!jsonValue.trim()}
|
||||
data-testid="mcp-global-json-edit-save-button"
|
||||
>
|
||||
<Code className="w-4 h-4 mr-2" />
|
||||
Save All
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { FileJson } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
interface ImportJsonDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
importJson: string;
|
||||
onImportJsonChange: (value: string) => void;
|
||||
onImport: () => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function ImportJsonDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
importJson,
|
||||
onImportJsonChange,
|
||||
onImport,
|
||||
onCancel,
|
||||
}: ImportJsonDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-2xl" data-testid="mcp-import-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Import MCP Servers</DialogTitle>
|
||||
<DialogDescription>
|
||||
Paste JSON configuration in Claude Code format. Servers with duplicate names will be
|
||||
skipped.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4">
|
||||
<Textarea
|
||||
value={importJson}
|
||||
onChange={(e) => onImportJsonChange(e.target.value)}
|
||||
placeholder={`{
|
||||
"mcpServers": {
|
||||
"server-name": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-name"],
|
||||
"type": "stdio"
|
||||
}
|
||||
}
|
||||
}`}
|
||||
className="font-mono text-sm h-64"
|
||||
data-testid="mcp-import-textarea"
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={onImport} disabled={!importJson.trim()} data-testid="mcp-import-button">
|
||||
<FileJson className="w-4 h-4 mr-2" />
|
||||
Import
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export { AddEditServerDialog } from './add-edit-server-dialog';
|
||||
export { DeleteServerDialog } from './delete-server-dialog';
|
||||
export { ImportJsonDialog } from './import-json-dialog';
|
||||
export { JsonEditDialog } from './json-edit-dialog';
|
||||
export { GlobalJsonEditDialog } from './global-json-edit-dialog';
|
||||
export { SecurityWarningDialog } from './security-warning-dialog';
|
||||
@@ -0,0 +1,77 @@
|
||||
import { Code } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import type { MCPServerConfig } from '@automaker/types';
|
||||
|
||||
interface JsonEditDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
server: MCPServerConfig | null;
|
||||
jsonValue: string;
|
||||
onJsonValueChange: (value: string) => void;
|
||||
onSave: () => void;
|
||||
onCancel: () => void;
|
||||
}
|
||||
|
||||
export function JsonEditDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
server,
|
||||
jsonValue,
|
||||
onJsonValueChange,
|
||||
onSave,
|
||||
onCancel,
|
||||
}: JsonEditDialogProps) {
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
onCancel();
|
||||
} else {
|
||||
onOpenChange(open);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent className="max-w-2xl" data-testid="mcp-json-edit-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit Server Configuration</DialogTitle>
|
||||
<DialogDescription>
|
||||
Edit the raw JSON configuration for "{server?.name}". Changes will be validated before
|
||||
saving.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4">
|
||||
<Textarea
|
||||
value={jsonValue}
|
||||
onChange={(e) => onJsonValueChange(e.target.value)}
|
||||
placeholder="Server configuration JSON..."
|
||||
className="font-mono text-sm h-80"
|
||||
data-testid="mcp-json-edit-textarea"
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={onCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={onSave}
|
||||
disabled={!jsonValue.trim()}
|
||||
data-testid="mcp-json-edit-save-button"
|
||||
>
|
||||
<Code className="w-4 h-4 mr-2" />
|
||||
Save JSON
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import { ShieldAlert, Terminal, Globe } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
interface SecurityWarningDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onConfirm: () => void;
|
||||
serverType: 'stdio' | 'sse' | 'http';
|
||||
serverName: string;
|
||||
command?: string;
|
||||
args?: string[];
|
||||
url?: string;
|
||||
/** Number of servers being imported (for import dialog) */
|
||||
importCount?: number;
|
||||
}
|
||||
|
||||
export function SecurityWarningDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
onConfirm,
|
||||
serverType,
|
||||
serverName,
|
||||
command,
|
||||
args,
|
||||
url,
|
||||
importCount,
|
||||
}: SecurityWarningDialogProps) {
|
||||
const isImport = importCount !== undefined && importCount > 0;
|
||||
const isStdio = serverType === 'stdio';
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-lg" data-testid="mcp-security-warning-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<ShieldAlert className="h-5 w-5 text-amber-500" />
|
||||
Security Warning
|
||||
</DialogTitle>
|
||||
<DialogDescription asChild>
|
||||
<div className="space-y-3 pt-2">
|
||||
<p className="font-medium text-foreground">
|
||||
{isImport
|
||||
? `You are about to import ${importCount} MCP server${importCount > 1 ? 's' : ''}.`
|
||||
: 'MCP servers can execute code on your machine.'}
|
||||
</p>
|
||||
|
||||
{!isImport && isStdio && command && (
|
||||
<div className="rounded-md border border-destructive/30 bg-destructive/10 p-3">
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
||||
<Terminal className="h-4 w-4 text-destructive" />
|
||||
This server will run:
|
||||
</div>
|
||||
<code className="mt-1 block break-all text-sm text-muted-foreground">
|
||||
{command} {args?.join(' ')}
|
||||
</code>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isImport && !isStdio && url && (
|
||||
<div className="rounded-md border border-amber-500/30 bg-amber-500/10 p-3">
|
||||
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
||||
<Globe className="h-4 w-4 text-amber-500" />
|
||||
This server will connect to:
|
||||
</div>
|
||||
<code className="mt-1 block break-all text-sm text-muted-foreground">{url}</code>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isImport && (
|
||||
<div className="rounded-md border border-amber-500/30 bg-amber-500/10 p-3">
|
||||
<p className="text-sm text-foreground">
|
||||
Each imported server can execute arbitrary commands or connect to external
|
||||
services. Review the JSON carefully before importing.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ul className="list-inside list-disc space-y-1 text-sm text-muted-foreground">
|
||||
<li>Only add servers from sources you trust</li>
|
||||
{isStdio && <li>Stdio servers run with your user privileges</li>}
|
||||
{!isStdio && <li>HTTP/SSE servers can access network resources</li>}
|
||||
<li>Review the {isStdio ? 'command' : 'URL'} before confirming</li>
|
||||
</ul>
|
||||
</div>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={onConfirm} data-testid="mcp-security-confirm-button">
|
||||
I understand, {isImport ? 'import' : 'add'} server
|
||||
{isImport && importCount! > 1 ? 's' : ''}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { useMCPServers } from './use-mcp-servers';
|
||||
@@ -0,0 +1,759 @@
|
||||
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
||||
import { useAppStore } from '@/store/app-store';
|
||||
import { toast } from 'sonner';
|
||||
import type { MCPServerConfig } from '@automaker/types';
|
||||
import { syncSettingsToServer, loadMCPServersFromServer } from '@/hooks/use-settings-migration';
|
||||
import { getHttpApiClient } from '@/lib/http-api-client';
|
||||
import type { ServerFormData, ServerTestState } from '../types';
|
||||
import { defaultFormData } from '../types';
|
||||
import { MAX_RECOMMENDED_TOOLS } from '../constants';
|
||||
import type { ServerType } from '../types';
|
||||
|
||||
/** Pending server data waiting for security confirmation */
|
||||
interface PendingServerData {
|
||||
type: 'add' | 'import';
|
||||
serverData?: Omit<MCPServerConfig, 'id'>;
|
||||
importServers?: Array<Omit<MCPServerConfig, 'id'>>;
|
||||
serverType: ServerType;
|
||||
command?: string;
|
||||
args?: string[];
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export function useMCPServers() {
|
||||
const {
|
||||
mcpServers,
|
||||
addMCPServer,
|
||||
updateMCPServer,
|
||||
removeMCPServer,
|
||||
mcpAutoApproveTools,
|
||||
mcpUnrestrictedTools,
|
||||
setMcpAutoApproveTools,
|
||||
setMcpUnrestrictedTools,
|
||||
} = useAppStore();
|
||||
|
||||
// State
|
||||
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false);
|
||||
const [editingServer, setEditingServer] = useState<MCPServerConfig | null>(null);
|
||||
const [formData, setFormData] = useState<ServerFormData>(defaultFormData);
|
||||
const [deleteConfirmId, setDeleteConfirmId] = useState<string | null>(null);
|
||||
const [isImportDialogOpen, setIsImportDialogOpen] = useState(false);
|
||||
const [importJson, setImportJson] = useState('');
|
||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||
const [serverTestStates, setServerTestStates] = useState<Record<string, ServerTestState>>({});
|
||||
const [expandedServers, setExpandedServers] = useState<Set<string>>(new Set());
|
||||
const [jsonEditServer, setJsonEditServer] = useState<MCPServerConfig | null>(null);
|
||||
const [jsonEditValue, setJsonEditValue] = useState('');
|
||||
const [isGlobalJsonEditOpen, setIsGlobalJsonEditOpen] = useState(false);
|
||||
const [globalJsonValue, setGlobalJsonValue] = useState('');
|
||||
const autoTestedServersRef = useRef<Set<string>>(new Set());
|
||||
|
||||
// Security warning dialog state
|
||||
const [isSecurityWarningOpen, setIsSecurityWarningOpen] = useState(false);
|
||||
const [pendingServerData, setPendingServerData] = useState<PendingServerData | null>(null);
|
||||
|
||||
// Computed values
|
||||
const totalToolsCount = useMemo(() => {
|
||||
let count = 0;
|
||||
for (const server of mcpServers) {
|
||||
if (server.enabled !== false) {
|
||||
const testState = serverTestStates[server.id];
|
||||
if (testState?.status === 'success' && testState.tools) {
|
||||
count += testState.tools.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}, [mcpServers, serverTestStates]);
|
||||
|
||||
const showToolsWarning = totalToolsCount > MAX_RECOMMENDED_TOOLS;
|
||||
|
||||
// Auto-load MCP servers from settings file on mount
|
||||
useEffect(() => {
|
||||
loadMCPServersFromServer().catch((error) => {
|
||||
console.error('Failed to load MCP servers on mount:', error);
|
||||
});
|
||||
}, []);
|
||||
|
||||
// Test a single server (extracted for reuse)
|
||||
const testServer = useCallback(async (server: MCPServerConfig, silent = false) => {
|
||||
setServerTestStates((prev) => ({
|
||||
...prev,
|
||||
[server.id]: { status: 'testing' },
|
||||
}));
|
||||
|
||||
try {
|
||||
const api = getHttpApiClient();
|
||||
const result = await api.mcp.testServer(server.id);
|
||||
|
||||
if (result.success) {
|
||||
setServerTestStates((prev) => ({
|
||||
...prev,
|
||||
[server.id]: {
|
||||
status: 'success',
|
||||
tools: result.tools,
|
||||
connectionTime: result.connectionTime,
|
||||
},
|
||||
}));
|
||||
// Only auto-expand on manual test, not on auto-test (silent)
|
||||
if (!silent) {
|
||||
setExpandedServers((prev) => new Set([...prev, server.id]));
|
||||
toast.success(
|
||||
`Connected to ${server.name} (${result.tools?.length || 0} tools, ${result.connectionTime}ms)`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
setServerTestStates((prev) => ({
|
||||
...prev,
|
||||
[server.id]: {
|
||||
status: 'error',
|
||||
error: result.error,
|
||||
connectionTime: result.connectionTime,
|
||||
},
|
||||
}));
|
||||
if (!silent) {
|
||||
toast.error(`Failed to connect: ${result.error}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
setServerTestStates((prev) => ({
|
||||
...prev,
|
||||
[server.id]: {
|
||||
status: 'error',
|
||||
error: errorMessage,
|
||||
},
|
||||
}));
|
||||
if (!silent) {
|
||||
toast.error(`Test failed: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Auto-test all enabled servers on mount
|
||||
useEffect(() => {
|
||||
const enabledServers = mcpServers.filter((s) => s.enabled !== false);
|
||||
const serversToTest = enabledServers.filter((s) => !autoTestedServersRef.current.has(s.id));
|
||||
|
||||
if (serversToTest.length > 0) {
|
||||
// Mark all as being tested
|
||||
serversToTest.forEach((s) => autoTestedServersRef.current.add(s.id));
|
||||
|
||||
// Test all servers in parallel (silently - no toast spam)
|
||||
serversToTest.forEach((server) => {
|
||||
testServer(server, true);
|
||||
});
|
||||
}
|
||||
}, [mcpServers, testServer]);
|
||||
|
||||
const handleRefresh = async () => {
|
||||
setIsRefreshing(true);
|
||||
try {
|
||||
const success = await loadMCPServersFromServer();
|
||||
if (success) {
|
||||
toast.success('MCP servers refreshed from settings');
|
||||
} else {
|
||||
toast.error('Failed to refresh MCP servers');
|
||||
}
|
||||
} catch {
|
||||
toast.error('Error refreshing MCP servers');
|
||||
} finally {
|
||||
setIsRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleTestServer = (server: MCPServerConfig) => {
|
||||
testServer(server, false); // false = show toast notifications
|
||||
};
|
||||
|
||||
const toggleServerExpanded = (serverId: string) => {
|
||||
setExpandedServers((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(serverId)) {
|
||||
next.delete(serverId);
|
||||
} else {
|
||||
next.add(serverId);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
const handleOpenAddDialog = () => {
|
||||
setFormData(defaultFormData);
|
||||
setEditingServer(null);
|
||||
setIsAddDialogOpen(true);
|
||||
};
|
||||
|
||||
const handleOpenEditDialog = (server: MCPServerConfig) => {
|
||||
setFormData({
|
||||
name: server.name,
|
||||
description: server.description || '',
|
||||
type: server.type || 'stdio',
|
||||
command: server.command || '',
|
||||
args: server.args?.join(' ') || '',
|
||||
url: server.url || '',
|
||||
headers: server.headers ? JSON.stringify(server.headers, null, 2) : '',
|
||||
env: server.env ? JSON.stringify(server.env, null, 2) : '',
|
||||
});
|
||||
setEditingServer(server);
|
||||
setIsAddDialogOpen(true);
|
||||
};
|
||||
|
||||
const handleCloseDialog = () => {
|
||||
setIsAddDialogOpen(false);
|
||||
setEditingServer(null);
|
||||
setFormData(defaultFormData);
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!formData.name.trim()) {
|
||||
toast.error('Server name is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (formData.type === 'stdio' && !formData.command.trim()) {
|
||||
toast.error('Command is required for stdio servers');
|
||||
return;
|
||||
}
|
||||
|
||||
if ((formData.type === 'sse' || formData.type === 'http') && !formData.url.trim()) {
|
||||
toast.error('URL is required for SSE/HTTP servers');
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse headers if provided
|
||||
let parsedHeaders: Record<string, string> | undefined;
|
||||
if (formData.headers.trim()) {
|
||||
try {
|
||||
parsedHeaders = JSON.parse(formData.headers.trim());
|
||||
if (typeof parsedHeaders !== 'object' || Array.isArray(parsedHeaders)) {
|
||||
toast.error('Headers must be a JSON object');
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
toast.error('Invalid JSON for headers');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse env if provided
|
||||
let parsedEnv: Record<string, string> | undefined;
|
||||
if (formData.env.trim()) {
|
||||
try {
|
||||
parsedEnv = JSON.parse(formData.env.trim());
|
||||
if (typeof parsedEnv !== 'object' || Array.isArray(parsedEnv)) {
|
||||
toast.error('Environment variables must be a JSON object');
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
toast.error('Invalid JSON for environment variables');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const serverData: Omit<MCPServerConfig, 'id'> = {
|
||||
name: formData.name.trim(),
|
||||
description: formData.description.trim() || undefined,
|
||||
type: formData.type,
|
||||
enabled: editingServer?.enabled ?? true,
|
||||
};
|
||||
|
||||
if (formData.type === 'stdio') {
|
||||
serverData.command = formData.command.trim();
|
||||
if (formData.args.trim()) {
|
||||
serverData.args = formData.args.trim().split(/\s+/);
|
||||
}
|
||||
if (parsedEnv) {
|
||||
serverData.env = parsedEnv;
|
||||
}
|
||||
} else {
|
||||
serverData.url = formData.url.trim();
|
||||
if (parsedHeaders) {
|
||||
serverData.headers = parsedHeaders;
|
||||
}
|
||||
}
|
||||
|
||||
// If editing an existing server, save directly (user already approved it)
|
||||
if (editingServer) {
|
||||
updateMCPServer(editingServer.id, serverData);
|
||||
toast.success('MCP server updated');
|
||||
await syncSettingsToServer();
|
||||
handleCloseDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
// For new servers, show security warning first
|
||||
setPendingServerData({
|
||||
type: 'add',
|
||||
serverData,
|
||||
serverType: formData.type,
|
||||
command: formData.type === 'stdio' ? formData.command.trim() : undefined,
|
||||
args:
|
||||
formData.type === 'stdio' && formData.args.trim()
|
||||
? formData.args.trim().split(/\s+/)
|
||||
: undefined,
|
||||
url: formData.type !== 'stdio' ? formData.url.trim() : undefined,
|
||||
});
|
||||
setIsSecurityWarningOpen(true);
|
||||
};
|
||||
|
||||
/** Called when user confirms the security warning for adding a server */
|
||||
const handleSecurityWarningConfirm = async () => {
|
||||
if (!pendingServerData) return;
|
||||
|
||||
if (pendingServerData.type === 'add' && pendingServerData.serverData) {
|
||||
addMCPServer(pendingServerData.serverData);
|
||||
toast.success('MCP server added');
|
||||
await syncSettingsToServer();
|
||||
handleCloseDialog();
|
||||
} else if (pendingServerData.type === 'import' && pendingServerData.importServers) {
|
||||
for (const serverData of pendingServerData.importServers) {
|
||||
addMCPServer(serverData);
|
||||
}
|
||||
await syncSettingsToServer();
|
||||
const count = pendingServerData.importServers.length;
|
||||
toast.success(`Imported ${count} MCP server${count > 1 ? 's' : ''}`);
|
||||
setIsImportDialogOpen(false);
|
||||
setImportJson('');
|
||||
}
|
||||
|
||||
setIsSecurityWarningOpen(false);
|
||||
setPendingServerData(null);
|
||||
};
|
||||
|
||||
const handleToggleEnabled = async (server: MCPServerConfig) => {
|
||||
updateMCPServer(server.id, { enabled: !server.enabled });
|
||||
await syncSettingsToServer();
|
||||
toast.success(server.enabled ? 'Server disabled' : 'Server enabled');
|
||||
};
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
removeMCPServer(id);
|
||||
await syncSettingsToServer();
|
||||
setDeleteConfirmId(null);
|
||||
toast.success('MCP server removed');
|
||||
};
|
||||
|
||||
const handleImportJson = async () => {
|
||||
try {
|
||||
const parsed = JSON.parse(importJson);
|
||||
|
||||
// Support both formats:
|
||||
// 1. Claude Code format: { "mcpServers": { "name": { command, args, ... } } }
|
||||
// 2. Direct format: { "name": { command, args, ... } }
|
||||
const servers = parsed.mcpServers || parsed;
|
||||
|
||||
if (typeof servers !== 'object' || Array.isArray(servers)) {
|
||||
toast.error('Invalid format: expected object with server configurations');
|
||||
return;
|
||||
}
|
||||
|
||||
const serversToImport: Array<Omit<MCPServerConfig, 'id'>> = [];
|
||||
let skippedCount = 0;
|
||||
|
||||
for (const [name, config] of Object.entries(servers)) {
|
||||
if (typeof config !== 'object' || config === null) continue;
|
||||
|
||||
const serverConfig = config as Record<string, unknown>;
|
||||
|
||||
// Check if server with this name already exists
|
||||
if (mcpServers.some((s) => s.name === name)) {
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const serverData: Omit<MCPServerConfig, 'id'> = {
|
||||
name,
|
||||
type: (serverConfig.type as ServerType) || 'stdio',
|
||||
enabled: true,
|
||||
};
|
||||
|
||||
if (serverData.type === 'stdio') {
|
||||
if (!serverConfig.command) {
|
||||
console.warn(`Skipping ${name}: no command specified`);
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const rawCommand = serverConfig.command as string;
|
||||
|
||||
// Support both formats:
|
||||
// 1. Separate command/args: { "command": "npx", "args": ["-y", "package"] }
|
||||
// 2. Inline args (Claude Desktop format): { "command": "npx -y package" }
|
||||
if (Array.isArray(serverConfig.args) && serverConfig.args.length > 0) {
|
||||
// Args provided separately
|
||||
serverData.command = rawCommand;
|
||||
serverData.args = serverConfig.args as string[];
|
||||
} else if (rawCommand.includes(' ')) {
|
||||
// Parse inline command string - split on spaces but preserve quoted strings
|
||||
const parts = rawCommand.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || [rawCommand];
|
||||
serverData.command = parts[0];
|
||||
if (parts.length > 1) {
|
||||
// Remove quotes from args
|
||||
serverData.args = parts.slice(1).map((arg) => arg.replace(/^["']|["']$/g, ''));
|
||||
}
|
||||
} else {
|
||||
serverData.command = rawCommand;
|
||||
}
|
||||
|
||||
if (typeof serverConfig.env === 'object' && serverConfig.env !== null) {
|
||||
serverData.env = serverConfig.env as Record<string, string>;
|
||||
}
|
||||
} else {
|
||||
if (!serverConfig.url) {
|
||||
console.warn(`Skipping ${name}: no url specified`);
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
serverData.url = serverConfig.url as string;
|
||||
if (typeof serverConfig.headers === 'object' && serverConfig.headers !== null) {
|
||||
serverData.headers = serverConfig.headers as Record<string, string>;
|
||||
}
|
||||
}
|
||||
|
||||
serversToImport.push(serverData);
|
||||
}
|
||||
|
||||
if (skippedCount > 0) {
|
||||
toast.info(
|
||||
`Skipped ${skippedCount} server${skippedCount > 1 ? 's' : ''} (already exist or invalid)`
|
||||
);
|
||||
}
|
||||
|
||||
if (serversToImport.length === 0) {
|
||||
toast.warning('No new servers to import');
|
||||
return;
|
||||
}
|
||||
|
||||
// Show security warning before importing
|
||||
// Use the first server's type for the warning (most imports are stdio)
|
||||
const firstServer = serversToImport[0];
|
||||
setPendingServerData({
|
||||
type: 'import',
|
||||
importServers: serversToImport,
|
||||
serverType: firstServer.type || 'stdio',
|
||||
command: firstServer.type === 'stdio' ? firstServer.command : undefined,
|
||||
args: firstServer.type === 'stdio' ? firstServer.args : undefined,
|
||||
url: firstServer.type !== 'stdio' ? firstServer.url : undefined,
|
||||
});
|
||||
setIsSecurityWarningOpen(true);
|
||||
} catch (error) {
|
||||
toast.error('Invalid JSON: ' + (error instanceof Error ? error.message : 'Parse error'));
|
||||
}
|
||||
};
|
||||
|
||||
const handleExportJson = () => {
|
||||
const exportData: Record<string, Record<string, unknown>> = {};
|
||||
|
||||
for (const server of mcpServers) {
|
||||
const serverConfig: Record<string, unknown> = {
|
||||
type: server.type || 'stdio',
|
||||
};
|
||||
|
||||
if (server.type === 'stdio' || !server.type) {
|
||||
serverConfig.command = server.command;
|
||||
if (server.args?.length) serverConfig.args = server.args;
|
||||
if (server.env && Object.keys(server.env).length > 0) serverConfig.env = server.env;
|
||||
} else {
|
||||
serverConfig.url = server.url;
|
||||
if (server.headers && Object.keys(server.headers).length > 0)
|
||||
serverConfig.headers = server.headers;
|
||||
}
|
||||
|
||||
exportData[server.name] = serverConfig;
|
||||
}
|
||||
|
||||
const json = JSON.stringify({ mcpServers: exportData }, null, 2);
|
||||
navigator.clipboard.writeText(json);
|
||||
toast.success('Copied to clipboard');
|
||||
};
|
||||
|
||||
const handleOpenJsonEdit = (server: MCPServerConfig) => {
|
||||
// Build a clean config object for editing (excluding internal fields like id)
|
||||
const editableConfig: Record<string, unknown> = {
|
||||
name: server.name,
|
||||
type: server.type || 'stdio',
|
||||
};
|
||||
|
||||
if (server.description) {
|
||||
editableConfig.description = server.description;
|
||||
}
|
||||
|
||||
if (server.type === 'stdio' || !server.type) {
|
||||
if (server.command) editableConfig.command = server.command;
|
||||
if (server.args?.length) editableConfig.args = server.args;
|
||||
if (server.env && Object.keys(server.env).length > 0) editableConfig.env = server.env;
|
||||
} else {
|
||||
if (server.url) editableConfig.url = server.url;
|
||||
if (server.headers && Object.keys(server.headers).length > 0) {
|
||||
editableConfig.headers = server.headers;
|
||||
}
|
||||
}
|
||||
|
||||
if (server.enabled === false) {
|
||||
editableConfig.enabled = false;
|
||||
}
|
||||
|
||||
setJsonEditValue(JSON.stringify(editableConfig, null, 2));
|
||||
setJsonEditServer(server);
|
||||
};
|
||||
|
||||
const handleSaveJsonEdit = async () => {
|
||||
if (!jsonEditServer) return;
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(jsonEditValue);
|
||||
|
||||
if (typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
toast.error('Config must be a JSON object');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate required fields based on type
|
||||
const serverType = parsed.type || 'stdio';
|
||||
|
||||
if (!parsed.name || typeof parsed.name !== 'string') {
|
||||
toast.error('Name is required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (serverType === 'stdio') {
|
||||
if (!parsed.command || typeof parsed.command !== 'string') {
|
||||
toast.error('Command is required for stdio servers');
|
||||
return;
|
||||
}
|
||||
} else if (serverType === 'sse' || serverType === 'http') {
|
||||
if (!parsed.url || typeof parsed.url !== 'string') {
|
||||
toast.error('URL is required for SSE/HTTP servers');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Build update object
|
||||
const updateData: Partial<MCPServerConfig> = {
|
||||
name: parsed.name,
|
||||
type: serverType,
|
||||
description: parsed.description || undefined,
|
||||
enabled: parsed.enabled !== false,
|
||||
};
|
||||
|
||||
if (serverType === 'stdio') {
|
||||
updateData.command = parsed.command;
|
||||
updateData.args = Array.isArray(parsed.args) ? parsed.args : undefined;
|
||||
updateData.env =
|
||||
typeof parsed.env === 'object' && !Array.isArray(parsed.env) ? parsed.env : undefined;
|
||||
// Clear HTTP fields
|
||||
updateData.url = undefined;
|
||||
updateData.headers = undefined;
|
||||
} else {
|
||||
updateData.url = parsed.url;
|
||||
updateData.headers =
|
||||
typeof parsed.headers === 'object' && !Array.isArray(parsed.headers)
|
||||
? parsed.headers
|
||||
: undefined;
|
||||
// Clear stdio fields
|
||||
updateData.command = undefined;
|
||||
updateData.args = undefined;
|
||||
updateData.env = undefined;
|
||||
}
|
||||
|
||||
updateMCPServer(jsonEditServer.id, updateData);
|
||||
await syncSettingsToServer();
|
||||
|
||||
toast.success('Server configuration updated');
|
||||
setJsonEditServer(null);
|
||||
setJsonEditValue('');
|
||||
} catch (error) {
|
||||
toast.error('Invalid JSON: ' + (error instanceof Error ? error.message : 'Parse error'));
|
||||
}
|
||||
};
|
||||
|
||||
const handleOpenGlobalJsonEdit = () => {
|
||||
// Build the full mcpServers config object
|
||||
const exportData: Record<string, Record<string, unknown>> = {};
|
||||
|
||||
for (const server of mcpServers) {
|
||||
const serverConfig: Record<string, unknown> = {
|
||||
type: server.type || 'stdio',
|
||||
};
|
||||
|
||||
if (server.description) {
|
||||
serverConfig.description = server.description;
|
||||
}
|
||||
|
||||
if (server.enabled === false) {
|
||||
serverConfig.enabled = false;
|
||||
}
|
||||
|
||||
if (server.type === 'stdio' || !server.type) {
|
||||
serverConfig.command = server.command;
|
||||
if (server.args?.length) serverConfig.args = server.args;
|
||||
if (server.env && Object.keys(server.env).length > 0) serverConfig.env = server.env;
|
||||
} else {
|
||||
serverConfig.url = server.url;
|
||||
if (server.headers && Object.keys(server.headers).length > 0) {
|
||||
serverConfig.headers = server.headers;
|
||||
}
|
||||
}
|
||||
|
||||
exportData[server.name] = serverConfig;
|
||||
}
|
||||
|
||||
setGlobalJsonValue(JSON.stringify({ mcpServers: exportData }, null, 2));
|
||||
setIsGlobalJsonEditOpen(true);
|
||||
};
|
||||
|
||||
const handleSaveGlobalJsonEdit = async () => {
|
||||
try {
|
||||
const parsed = JSON.parse(globalJsonValue);
|
||||
|
||||
// Support both formats
|
||||
const servers = parsed.mcpServers || parsed;
|
||||
|
||||
if (typeof servers !== 'object' || Array.isArray(servers)) {
|
||||
toast.error('Invalid format: expected object with server configurations');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate all servers first
|
||||
for (const [name, config] of Object.entries(servers)) {
|
||||
if (typeof config !== 'object' || config === null) {
|
||||
toast.error(`Invalid config for "${name}"`);
|
||||
return;
|
||||
}
|
||||
|
||||
const serverConfig = config as Record<string, unknown>;
|
||||
const serverType = (serverConfig.type as string) || 'stdio';
|
||||
|
||||
if (serverType === 'stdio') {
|
||||
if (!serverConfig.command || typeof serverConfig.command !== 'string') {
|
||||
toast.error(`Command is required for "${name}" (stdio)`);
|
||||
return;
|
||||
}
|
||||
} else if (serverType === 'sse' || serverType === 'http') {
|
||||
if (!serverConfig.url || typeof serverConfig.url !== 'string') {
|
||||
toast.error(`URL is required for "${name}" (${serverType})`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a map of existing servers by name for updating
|
||||
const existingByName = new Map(mcpServers.map((s) => [s.name, s]));
|
||||
const processedNames = new Set<string>();
|
||||
|
||||
// Update or add servers
|
||||
for (const [name, config] of Object.entries(servers)) {
|
||||
const serverConfig = config as Record<string, unknown>;
|
||||
const serverType = (serverConfig.type as ServerType) || 'stdio';
|
||||
|
||||
const serverData: Omit<MCPServerConfig, 'id'> = {
|
||||
name,
|
||||
type: serverType,
|
||||
description: (serverConfig.description as string) || undefined,
|
||||
enabled: serverConfig.enabled !== false,
|
||||
};
|
||||
|
||||
if (serverType === 'stdio') {
|
||||
serverData.command = serverConfig.command as string;
|
||||
if (Array.isArray(serverConfig.args)) {
|
||||
serverData.args = serverConfig.args as string[];
|
||||
}
|
||||
if (typeof serverConfig.env === 'object' && serverConfig.env !== null) {
|
||||
serverData.env = serverConfig.env as Record<string, string>;
|
||||
}
|
||||
} else {
|
||||
serverData.url = serverConfig.url as string;
|
||||
if (typeof serverConfig.headers === 'object' && serverConfig.headers !== null) {
|
||||
serverData.headers = serverConfig.headers as Record<string, string>;
|
||||
}
|
||||
}
|
||||
|
||||
const existing = existingByName.get(name);
|
||||
if (existing) {
|
||||
updateMCPServer(existing.id, serverData);
|
||||
} else {
|
||||
addMCPServer(serverData);
|
||||
}
|
||||
processedNames.add(name);
|
||||
}
|
||||
|
||||
// Remove servers that are no longer in the JSON
|
||||
for (const server of mcpServers) {
|
||||
if (!processedNames.has(server.name)) {
|
||||
removeMCPServer(server.id);
|
||||
}
|
||||
}
|
||||
|
||||
await syncSettingsToServer();
|
||||
|
||||
toast.success('MCP servers configuration updated');
|
||||
setIsGlobalJsonEditOpen(false);
|
||||
setGlobalJsonValue('');
|
||||
} catch (error) {
|
||||
toast.error('Invalid JSON: ' + (error instanceof Error ? error.message : 'Parse error'));
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
// Store state
|
||||
mcpServers,
|
||||
mcpAutoApproveTools,
|
||||
mcpUnrestrictedTools,
|
||||
setMcpAutoApproveTools,
|
||||
setMcpUnrestrictedTools,
|
||||
|
||||
// Dialog state
|
||||
isAddDialogOpen,
|
||||
setIsAddDialogOpen,
|
||||
editingServer,
|
||||
formData,
|
||||
setFormData,
|
||||
deleteConfirmId,
|
||||
setDeleteConfirmId,
|
||||
isImportDialogOpen,
|
||||
setIsImportDialogOpen,
|
||||
importJson,
|
||||
setImportJson,
|
||||
jsonEditServer,
|
||||
setJsonEditServer,
|
||||
jsonEditValue,
|
||||
setJsonEditValue,
|
||||
isGlobalJsonEditOpen,
|
||||
setIsGlobalJsonEditOpen,
|
||||
globalJsonValue,
|
||||
setGlobalJsonValue,
|
||||
|
||||
// Security warning dialog state
|
||||
isSecurityWarningOpen,
|
||||
setIsSecurityWarningOpen,
|
||||
pendingServerData,
|
||||
|
||||
// UI state
|
||||
isRefreshing,
|
||||
serverTestStates,
|
||||
expandedServers,
|
||||
|
||||
// Computed
|
||||
totalToolsCount,
|
||||
showToolsWarning,
|
||||
|
||||
// Handlers
|
||||
handleRefresh,
|
||||
handleTestServer,
|
||||
toggleServerExpanded,
|
||||
handleOpenAddDialog,
|
||||
handleOpenEditDialog,
|
||||
handleCloseDialog,
|
||||
handleSave,
|
||||
handleToggleEnabled,
|
||||
handleDelete,
|
||||
handleImportJson,
|
||||
handleExportJson,
|
||||
handleOpenJsonEdit,
|
||||
handleSaveJsonEdit,
|
||||
handleOpenGlobalJsonEdit,
|
||||
handleSaveGlobalJsonEdit,
|
||||
handleSecurityWarningConfirm,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export { MCPServersSection } from './mcp-servers-section';
|
||||
export { MCPToolsList, type MCPToolDisplay } from './mcp-tools-list';
|
||||
@@ -0,0 +1,213 @@
|
||||
import { Plug } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useMCPServers } from './hooks';
|
||||
import {
|
||||
MCPServerHeader,
|
||||
MCPPermissionSettings,
|
||||
MCPToolsWarning,
|
||||
MCPServerCard,
|
||||
} from './components';
|
||||
import {
|
||||
AddEditServerDialog,
|
||||
DeleteServerDialog,
|
||||
ImportJsonDialog,
|
||||
JsonEditDialog,
|
||||
GlobalJsonEditDialog,
|
||||
SecurityWarningDialog,
|
||||
} from './dialogs';
|
||||
|
||||
export function MCPServersSection() {
|
||||
const {
|
||||
// Store state
|
||||
mcpServers,
|
||||
mcpAutoApproveTools,
|
||||
mcpUnrestrictedTools,
|
||||
setMcpAutoApproveTools,
|
||||
setMcpUnrestrictedTools,
|
||||
|
||||
// Dialog state
|
||||
isAddDialogOpen,
|
||||
setIsAddDialogOpen,
|
||||
editingServer,
|
||||
formData,
|
||||
setFormData,
|
||||
deleteConfirmId,
|
||||
setDeleteConfirmId,
|
||||
isImportDialogOpen,
|
||||
setIsImportDialogOpen,
|
||||
importJson,
|
||||
setImportJson,
|
||||
jsonEditServer,
|
||||
setJsonEditServer,
|
||||
jsonEditValue,
|
||||
setJsonEditValue,
|
||||
isGlobalJsonEditOpen,
|
||||
setIsGlobalJsonEditOpen,
|
||||
globalJsonValue,
|
||||
setGlobalJsonValue,
|
||||
|
||||
// Security warning dialog state
|
||||
isSecurityWarningOpen,
|
||||
setIsSecurityWarningOpen,
|
||||
pendingServerData,
|
||||
|
||||
// UI state
|
||||
isRefreshing,
|
||||
serverTestStates,
|
||||
expandedServers,
|
||||
|
||||
// Computed
|
||||
totalToolsCount,
|
||||
showToolsWarning,
|
||||
|
||||
// Handlers
|
||||
handleRefresh,
|
||||
handleTestServer,
|
||||
toggleServerExpanded,
|
||||
handleOpenAddDialog,
|
||||
handleOpenEditDialog,
|
||||
handleCloseDialog,
|
||||
handleSave,
|
||||
handleToggleEnabled,
|
||||
handleDelete,
|
||||
handleImportJson,
|
||||
handleExportJson,
|
||||
handleOpenJsonEdit,
|
||||
handleSaveJsonEdit,
|
||||
handleOpenGlobalJsonEdit,
|
||||
handleSaveGlobalJsonEdit,
|
||||
handleSecurityWarningConfirm,
|
||||
} = useMCPServers();
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'rounded-2xl overflow-hidden',
|
||||
'border border-border/50',
|
||||
'bg-linear-to-br from-card/90 via-card/70 to-card/80 backdrop-blur-xl',
|
||||
'shadow-sm shadow-black/5'
|
||||
)}
|
||||
>
|
||||
<MCPServerHeader
|
||||
isRefreshing={isRefreshing}
|
||||
hasServers={mcpServers.length > 0}
|
||||
onRefresh={handleRefresh}
|
||||
onExport={handleExportJson}
|
||||
onEditAllJson={handleOpenGlobalJsonEdit}
|
||||
onImport={() => setIsImportDialogOpen(true)}
|
||||
onAdd={handleOpenAddDialog}
|
||||
/>
|
||||
|
||||
{mcpServers.length > 0 && (
|
||||
<MCPPermissionSettings
|
||||
mcpAutoApproveTools={mcpAutoApproveTools}
|
||||
mcpUnrestrictedTools={mcpUnrestrictedTools}
|
||||
onAutoApproveChange={setMcpAutoApproveTools}
|
||||
onUnrestrictedChange={setMcpUnrestrictedTools}
|
||||
/>
|
||||
)}
|
||||
|
||||
{showToolsWarning && <MCPToolsWarning totalTools={totalToolsCount} />}
|
||||
|
||||
<div className="p-6">
|
||||
{mcpServers.length === 0 ? (
|
||||
<div className="text-center py-8 text-muted-foreground">
|
||||
<Plug className="w-12 h-12 mx-auto mb-3 opacity-50" />
|
||||
<p className="text-sm">No MCP servers configured</p>
|
||||
<p className="text-xs mt-1">Add a server to extend agent capabilities</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{mcpServers.map((server) => (
|
||||
<MCPServerCard
|
||||
key={server.id}
|
||||
server={server}
|
||||
testState={serverTestStates[server.id]}
|
||||
isExpanded={expandedServers.has(server.id)}
|
||||
onToggleExpanded={() => toggleServerExpanded(server.id)}
|
||||
onTest={() => handleTestServer(server)}
|
||||
onToggleEnabled={() => handleToggleEnabled(server)}
|
||||
onEditJson={() => handleOpenJsonEdit(server)}
|
||||
onEdit={() => handleOpenEditDialog(server)}
|
||||
onDelete={() => setDeleteConfirmId(server.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Dialogs */}
|
||||
<AddEditServerDialog
|
||||
open={isAddDialogOpen}
|
||||
onOpenChange={setIsAddDialogOpen}
|
||||
editingServer={editingServer}
|
||||
formData={formData}
|
||||
onFormDataChange={setFormData}
|
||||
onSave={handleSave}
|
||||
onCancel={handleCloseDialog}
|
||||
/>
|
||||
|
||||
<DeleteServerDialog
|
||||
open={!!deleteConfirmId}
|
||||
onOpenChange={(open) => setDeleteConfirmId(open ? deleteConfirmId : null)}
|
||||
onConfirm={() => deleteConfirmId && handleDelete(deleteConfirmId)}
|
||||
/>
|
||||
|
||||
<ImportJsonDialog
|
||||
open={isImportDialogOpen}
|
||||
onOpenChange={setIsImportDialogOpen}
|
||||
importJson={importJson}
|
||||
onImportJsonChange={setImportJson}
|
||||
onImport={handleImportJson}
|
||||
onCancel={() => {
|
||||
setIsImportDialogOpen(false);
|
||||
setImportJson('');
|
||||
}}
|
||||
/>
|
||||
|
||||
<JsonEditDialog
|
||||
open={!!jsonEditServer}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
setJsonEditServer(null);
|
||||
setJsonEditValue('');
|
||||
}
|
||||
}}
|
||||
server={jsonEditServer}
|
||||
jsonValue={jsonEditValue}
|
||||
onJsonValueChange={setJsonEditValue}
|
||||
onSave={handleSaveJsonEdit}
|
||||
onCancel={() => {
|
||||
setJsonEditServer(null);
|
||||
setJsonEditValue('');
|
||||
}}
|
||||
/>
|
||||
|
||||
<GlobalJsonEditDialog
|
||||
open={isGlobalJsonEditOpen}
|
||||
onOpenChange={setIsGlobalJsonEditOpen}
|
||||
jsonValue={globalJsonValue}
|
||||
onJsonValueChange={setGlobalJsonValue}
|
||||
onSave={handleSaveGlobalJsonEdit}
|
||||
onCancel={() => {
|
||||
setIsGlobalJsonEditOpen(false);
|
||||
setGlobalJsonValue('');
|
||||
}}
|
||||
/>
|
||||
|
||||
<SecurityWarningDialog
|
||||
open={isSecurityWarningOpen}
|
||||
onOpenChange={setIsSecurityWarningOpen}
|
||||
onConfirm={handleSecurityWarningConfirm}
|
||||
serverType={pendingServerData?.serverType || 'stdio'}
|
||||
serverName={pendingServerData?.serverData?.name || ''}
|
||||
command={pendingServerData?.command}
|
||||
args={pendingServerData?.args}
|
||||
url={pendingServerData?.url}
|
||||
importCount={
|
||||
pendingServerData?.type === 'import' ? pendingServerData.importServers?.length : undefined
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import { useState } from 'react';
|
||||
import { ChevronDown, ChevronRight, Wrench } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
|
||||
|
||||
export interface MCPToolDisplay {
|
||||
name: string;
|
||||
description?: string;
|
||||
inputSchema?: Record<string, unknown>;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
interface MCPToolsListProps {
|
||||
tools: MCPToolDisplay[];
|
||||
isLoading?: boolean;
|
||||
error?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function MCPToolsList({ tools, isLoading, error, className }: MCPToolsListProps) {
|
||||
const [expandedTools, setExpandedTools] = useState<Set<string>>(new Set());
|
||||
|
||||
const toggleTool = (toolName: string) => {
|
||||
setExpandedTools((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(toolName)) {
|
||||
next.delete(toolName);
|
||||
} else {
|
||||
next.add(toolName);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className={cn('text-sm text-muted-foreground animate-pulse', className)}>
|
||||
Loading tools...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div className={cn('text-sm text-destructive wrap-break-word', className)}>{error}</div>;
|
||||
}
|
||||
|
||||
if (!tools || tools.length === 0) {
|
||||
return (
|
||||
<div className={cn('text-sm text-muted-foreground italic', className)}>
|
||||
No tools available
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn('space-y-1 overflow-hidden', className)}>
|
||||
{tools.map((tool) => {
|
||||
const isExpanded = expandedTools.has(tool.name);
|
||||
const hasSchema = tool.inputSchema && Object.keys(tool.inputSchema).length > 0;
|
||||
|
||||
return (
|
||||
<Collapsible key={tool.name} open={isExpanded} onOpenChange={() => toggleTool(tool.name)}>
|
||||
<div
|
||||
className={cn(
|
||||
'rounded-lg border border-border/30 bg-background/50 overflow-hidden',
|
||||
'hover:border-border/50 transition-colors'
|
||||
)}
|
||||
>
|
||||
<CollapsibleTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="w-full justify-start h-auto py-2 px-3 font-normal"
|
||||
>
|
||||
<div className="flex items-start gap-2 w-full min-w-0 overflow-hidden">
|
||||
<div className="flex items-center gap-1.5 shrink-0 mt-0.5">
|
||||
{hasSchema ? (
|
||||
isExpanded ? (
|
||||
<ChevronDown className="w-3.5 h-3.5 text-muted-foreground" />
|
||||
) : (
|
||||
<ChevronRight className="w-3.5 h-3.5 text-muted-foreground" />
|
||||
)
|
||||
) : (
|
||||
<div className="w-3.5" />
|
||||
)}
|
||||
<Wrench className="w-3.5 h-3.5 text-brand-500" />
|
||||
</div>
|
||||
<div className="flex flex-col items-start text-left min-w-0 overflow-hidden flex-1">
|
||||
<span className="font-medium text-xs truncate max-w-full">{tool.name}</span>
|
||||
{tool.description && (
|
||||
<span className="text-xs text-muted-foreground line-clamp-2 wrap-break-word w-full">
|
||||
{tool.description}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
{hasSchema && (
|
||||
<CollapsibleContent>
|
||||
<div className="px-3 pb-2 pt-0 overflow-hidden">
|
||||
<div className="bg-muted/50 rounded p-2 text-xs font-mono overflow-x-auto max-h-48">
|
||||
<pre className="whitespace-pre-wrap break-all text-[10px] leading-relaxed">
|
||||
{JSON.stringify(tool.inputSchema, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
)}
|
||||
</div>
|
||||
</Collapsible>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { MCPToolDisplay } from './mcp-tools-list';
|
||||
|
||||
export type ServerType = 'stdio' | 'sse' | 'http';
|
||||
|
||||
export interface ServerFormData {
|
||||
name: string;
|
||||
description: string;
|
||||
type: ServerType;
|
||||
command: string;
|
||||
args: string;
|
||||
url: string;
|
||||
headers: string; // JSON string for headers
|
||||
env: string; // JSON string for env vars
|
||||
}
|
||||
|
||||
export const defaultFormData: ServerFormData = {
|
||||
name: '',
|
||||
description: '',
|
||||
type: 'stdio',
|
||||
command: '',
|
||||
args: '',
|
||||
url: '',
|
||||
headers: '',
|
||||
env: '',
|
||||
};
|
||||
|
||||
export interface ServerTestState {
|
||||
status: 'idle' | 'testing' | 'success' | 'error';
|
||||
tools?: MCPToolDisplay[];
|
||||
error?: string;
|
||||
connectionTime?: number;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Terminal, Globe, Loader2, CheckCircle2, XCircle } from 'lucide-react';
|
||||
import type { ServerType, ServerTestState } from './types';
|
||||
import { SENSITIVE_PARAM_PATTERNS } from './constants';
|
||||
|
||||
/**
|
||||
* Mask sensitive values in URLs (query params with key-like names)
|
||||
*/
|
||||
export function maskSensitiveUrl(url: string): string {
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
const params = new URLSearchParams(urlObj.search);
|
||||
let hasSensitive = false;
|
||||
|
||||
for (const [key] of params.entries()) {
|
||||
if (SENSITIVE_PARAM_PATTERNS.some((pattern) => pattern.test(key))) {
|
||||
params.set(key, '***');
|
||||
hasSensitive = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSensitive) {
|
||||
urlObj.search = params.toString();
|
||||
return urlObj.toString();
|
||||
}
|
||||
return url;
|
||||
} catch {
|
||||
// If URL parsing fails, try simple regex replacement for common patterns
|
||||
return url.replace(
|
||||
/([?&])(api[-_]?key|auth|token|secret|password|credential)=([^&]*)/gi,
|
||||
'$1$2=***'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function getServerIcon(type: ServerType = 'stdio') {
|
||||
if (type === 'stdio') return Terminal;
|
||||
return Globe;
|
||||
}
|
||||
|
||||
export function getTestStatusIcon(status: ServerTestState['status']) {
|
||||
switch (status) {
|
||||
case 'testing':
|
||||
return <Loader2 className="w-4 h-4 animate-spin text-brand-500" />;
|
||||
case 'success':
|
||||
return <CheckCircle2 className="w-4 h-4 text-green-500" />;
|
||||
case 'error':
|
||||
return <XCircle className="w-4 h-4 text-destructive" />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import { useEffect, useState, useRef } from 'react';
|
||||
import { getHttpApiClient } from '@/lib/http-api-client';
|
||||
import { isElectron } from '@/lib/electron';
|
||||
import { getItem, removeItem } from '@/lib/storage';
|
||||
import { useAppStore } from '@/store/app-store';
|
||||
|
||||
/**
|
||||
* State returned by useSettingsMigration hook
|
||||
@@ -227,6 +228,9 @@ export async function syncSettingsToServer(): Promise<boolean> {
|
||||
enableSandboxMode: state.enableSandboxMode,
|
||||
keyboardShortcuts: state.keyboardShortcuts,
|
||||
aiProfiles: state.aiProfiles,
|
||||
mcpServers: state.mcpServers,
|
||||
mcpAutoApproveTools: state.mcpAutoApproveTools,
|
||||
mcpUnrestrictedTools: state.mcpUnrestrictedTools,
|
||||
projects: state.projects,
|
||||
trashedProjects: state.trashedProjects,
|
||||
projectHistory: state.projectHistory,
|
||||
@@ -316,3 +320,42 @@ export async function syncProjectSettingsToServer(
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load MCP servers from server settings file into the store
|
||||
*
|
||||
* Fetches the global settings from the server and updates the store's
|
||||
* mcpServers state. Useful when settings were modified externally
|
||||
* (e.g., by editing the settings.json file directly).
|
||||
*
|
||||
* Only functions in Electron mode. Returns false if not in Electron or on error.
|
||||
*
|
||||
* @returns Promise resolving to true if load succeeded, false otherwise
|
||||
*/
|
||||
export async function loadMCPServersFromServer(): Promise<boolean> {
|
||||
if (!isElectron()) return false;
|
||||
|
||||
try {
|
||||
const api = getHttpApiClient();
|
||||
const result = await api.settings.getGlobal();
|
||||
|
||||
if (!result.success || !result.settings) {
|
||||
console.error('[Settings Load] Failed to load settings:', result.error);
|
||||
return false;
|
||||
}
|
||||
|
||||
const mcpServers = result.settings.mcpServers || [];
|
||||
const mcpAutoApproveTools = result.settings.mcpAutoApproveTools ?? true;
|
||||
const mcpUnrestrictedTools = result.settings.mcpUnrestrictedTools ?? true;
|
||||
|
||||
// Clear existing and add all from server
|
||||
// We need to update the store directly since we can't use hooks here
|
||||
useAppStore.setState({ mcpServers, mcpAutoApproveTools, mcpUnrestrictedTools });
|
||||
|
||||
console.log(`[Settings Load] Loaded ${mcpServers.length} MCP servers from server`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('[Settings Load] Failed to load MCP servers:', error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -928,6 +928,20 @@ export class HttpApiClient implements ElectronAPI {
|
||||
recentFolders: string[];
|
||||
worktreePanelCollapsed: boolean;
|
||||
lastSelectedSessionByProject: Record<string, string>;
|
||||
mcpServers?: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
type?: 'stdio' | 'sse' | 'http';
|
||||
command?: string;
|
||||
args?: string[];
|
||||
env?: Record<string, string>;
|
||||
url?: string;
|
||||
headers?: Record<string, string>;
|
||||
enabled?: boolean;
|
||||
}>;
|
||||
mcpAutoApproveTools?: boolean;
|
||||
mcpUnrestrictedTools?: boolean;
|
||||
};
|
||||
error?: string;
|
||||
}> => this.get('/api/settings/global'),
|
||||
@@ -1128,6 +1142,42 @@ export class HttpApiClient implements ElectronAPI {
|
||||
},
|
||||
};
|
||||
|
||||
// MCP API - Test MCP server connections and list tools
|
||||
// SECURITY: Only accepts serverId, not arbitrary serverConfig, to prevent
|
||||
// drive-by command execution attacks. Servers must be saved first.
|
||||
mcp = {
|
||||
testServer: (
|
||||
serverId: string
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
tools?: Array<{
|
||||
name: string;
|
||||
description?: string;
|
||||
inputSchema?: Record<string, unknown>;
|
||||
enabled: boolean;
|
||||
}>;
|
||||
error?: string;
|
||||
connectionTime?: number;
|
||||
serverInfo?: {
|
||||
name?: string;
|
||||
version?: string;
|
||||
};
|
||||
}> => this.post('/api/mcp/test', { serverId }),
|
||||
|
||||
listTools: (
|
||||
serverId: string
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
tools?: Array<{
|
||||
name: string;
|
||||
description?: string;
|
||||
inputSchema?: Record<string, unknown>;
|
||||
enabled: boolean;
|
||||
}>;
|
||||
error?: string;
|
||||
}> => this.post('/api/mcp/tools', { serverId }),
|
||||
};
|
||||
|
||||
// Pipeline API - custom workflow pipeline steps
|
||||
pipeline = {
|
||||
getConfig: (
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
AgentModel,
|
||||
PlanningMode,
|
||||
AIProfile,
|
||||
MCPServerConfig,
|
||||
FeatureStatusWithPipeline,
|
||||
PipelineConfig,
|
||||
PipelineStep,
|
||||
@@ -486,6 +487,11 @@ export interface AppState {
|
||||
autoLoadClaudeMd: boolean; // Auto-load CLAUDE.md files using SDK's settingSources option
|
||||
enableSandboxMode: boolean; // Enable sandbox mode for bash commands (may cause issues on some systems)
|
||||
|
||||
// MCP Servers
|
||||
mcpServers: MCPServerConfig[]; // List of configured MCP servers for agent use
|
||||
mcpAutoApproveTools: boolean; // Auto-approve MCP tool calls without permission prompts
|
||||
mcpUnrestrictedTools: boolean; // Allow unrestricted tools when MCP servers are enabled
|
||||
|
||||
// Project Analysis
|
||||
projectAnalysis: ProjectAnalysis | null;
|
||||
isAnalyzing: boolean;
|
||||
@@ -765,6 +771,8 @@ export interface AppActions {
|
||||
// Claude Agent SDK Settings actions
|
||||
setAutoLoadClaudeMd: (enabled: boolean) => Promise<void>;
|
||||
setEnableSandboxMode: (enabled: boolean) => Promise<void>;
|
||||
setMcpAutoApproveTools: (enabled: boolean) => Promise<void>;
|
||||
setMcpUnrestrictedTools: (enabled: boolean) => Promise<void>;
|
||||
|
||||
// AI Profile actions
|
||||
addAIProfile: (profile: Omit<AIProfile, 'id'>) => void;
|
||||
@@ -773,6 +781,12 @@ export interface AppActions {
|
||||
reorderAIProfiles: (oldIndex: number, newIndex: number) => void;
|
||||
resetAIProfiles: () => void;
|
||||
|
||||
// MCP Server actions
|
||||
addMCPServer: (server: Omit<MCPServerConfig, 'id'>) => void;
|
||||
updateMCPServer: (id: string, updates: Partial<MCPServerConfig>) => void;
|
||||
removeMCPServer: (id: string) => void;
|
||||
reorderMCPServers: (oldIndex: number, newIndex: number) => void;
|
||||
|
||||
// Project Analysis actions
|
||||
setProjectAnalysis: (analysis: ProjectAnalysis | null) => void;
|
||||
setIsAnalyzing: (analyzing: boolean) => void;
|
||||
@@ -955,6 +969,9 @@ const initialState: AppState = {
|
||||
validationModel: 'opus', // Default to opus for GitHub issue validation
|
||||
autoLoadClaudeMd: false, // Default to disabled (user must opt-in)
|
||||
enableSandboxMode: true, // Default to enabled for security (can be disabled if issues occur)
|
||||
mcpServers: [], // No MCP servers configured by default
|
||||
mcpAutoApproveTools: true, // Default to enabled - bypass permission prompts for MCP tools
|
||||
mcpUnrestrictedTools: true, // Default to enabled - don't filter allowedTools when MCP enabled
|
||||
aiProfiles: DEFAULT_AI_PROFILES,
|
||||
projectAnalysis: null,
|
||||
isAnalyzing: false,
|
||||
@@ -1598,6 +1615,18 @@ export const useAppStore = create<AppState & AppActions>()(
|
||||
const { syncSettingsToServer } = await import('@/hooks/use-settings-migration');
|
||||
await syncSettingsToServer();
|
||||
},
|
||||
setMcpAutoApproveTools: async (enabled) => {
|
||||
set({ mcpAutoApproveTools: enabled });
|
||||
// Sync to server settings file
|
||||
const { syncSettingsToServer } = await import('@/hooks/use-settings-migration');
|
||||
await syncSettingsToServer();
|
||||
},
|
||||
setMcpUnrestrictedTools: async (enabled) => {
|
||||
set({ mcpUnrestrictedTools: enabled });
|
||||
// Sync to server settings file
|
||||
const { syncSettingsToServer } = await import('@/hooks/use-settings-migration');
|
||||
await syncSettingsToServer();
|
||||
},
|
||||
|
||||
// AI Profile actions
|
||||
addAIProfile: (profile) => {
|
||||
@@ -1639,6 +1668,29 @@ export const useAppStore = create<AppState & AppActions>()(
|
||||
set({ aiProfiles: [...DEFAULT_AI_PROFILES, ...userProfiles] });
|
||||
},
|
||||
|
||||
// MCP Server actions
|
||||
addMCPServer: (server) => {
|
||||
const id = `mcp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
||||
set({ mcpServers: [...get().mcpServers, { ...server, id, enabled: true }] });
|
||||
},
|
||||
|
||||
updateMCPServer: (id, updates) => {
|
||||
set({
|
||||
mcpServers: get().mcpServers.map((s) => (s.id === id ? { ...s, ...updates } : s)),
|
||||
});
|
||||
},
|
||||
|
||||
removeMCPServer: (id) => {
|
||||
set({ mcpServers: get().mcpServers.filter((s) => s.id !== id) });
|
||||
},
|
||||
|
||||
reorderMCPServers: (oldIndex, newIndex) => {
|
||||
const servers = [...get().mcpServers];
|
||||
const [movedServer] = servers.splice(oldIndex, 1);
|
||||
servers.splice(newIndex, 0, movedServer);
|
||||
set({ mcpServers: servers });
|
||||
},
|
||||
|
||||
// Project Analysis actions
|
||||
setProjectAnalysis: (analysis) => set({ projectAnalysis: analysis }),
|
||||
setIsAnalyzing: (analyzing) => set({ isAnalyzing: analyzing }),
|
||||
@@ -2853,6 +2905,10 @@ export const useAppStore = create<AppState & AppActions>()(
|
||||
validationModel: state.validationModel,
|
||||
autoLoadClaudeMd: state.autoLoadClaudeMd,
|
||||
enableSandboxMode: state.enableSandboxMode,
|
||||
// MCP settings
|
||||
mcpServers: state.mcpServers,
|
||||
mcpAutoApproveTools: state.mcpAutoApproveTools,
|
||||
mcpUnrestrictedTools: state.mcpUnrestrictedTools,
|
||||
// Profiles and sessions
|
||||
aiProfiles: state.aiProfiles,
|
||||
chatSessions: state.chatSessions,
|
||||
|
||||
Reference in New Issue
Block a user