import React, { useState } from "react"; import { Download, Upload, FileText, Loader2, Info, Network, Settings2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { SelectComponent } from "@/components/ui/select"; import { api } from "@/lib/api"; interface MCPImportExportProps { /** * Callback when import is completed */ onImportCompleted: (imported: number, failed: number) => void; /** * Callback for error messages */ onError: (message: string) => void; } /** * Component for importing and exporting MCP server configurations */ export const MCPImportExport: React.FC = ({ onImportCompleted, onError, }) => { const [importingDesktop, setImportingDesktop] = useState(false); const [importingJson, setImportingJson] = useState(false); const [importScope, setImportScope] = useState("local"); /** * Imports servers from Claude Desktop */ const handleImportFromDesktop = async () => { try { setImportingDesktop(true); // Always use "user" scope for Claude Desktop imports (was previously "global") const result = await api.mcpAddFromClaudeDesktop("user"); // Show detailed results if available if (result.servers && result.servers.length > 0) { const successfulServers = result.servers.filter(s => s.success); const failedServers = result.servers.filter(s => !s.success); if (successfulServers.length > 0) { const successMessage = `Successfully imported: ${successfulServers.map(s => s.name).join(", ")}`; onImportCompleted(result.imported_count, result.failed_count); // Show success details if (failedServers.length === 0) { onError(successMessage); } } if (failedServers.length > 0) { const failureDetails = failedServers .map(s => `${s.name}: ${s.error || "Unknown error"}`) .join("\n"); onError(`Failed to import some servers:\n${failureDetails}`); } } else { onImportCompleted(result.imported_count, result.failed_count); } } catch (error: any) { console.error("Failed to import from Claude Desktop:", error); onError(error.toString() || "Failed to import from Claude Desktop"); } finally { setImportingDesktop(false); } }; /** * Handles JSON file import */ const handleJsonFileSelect = async (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (!file) return; try { setImportingJson(true); const content = await file.text(); // Parse the JSON to validate it let jsonData; try { jsonData = JSON.parse(content); } catch (e) { onError("Invalid JSON file. Please check the format."); return; } // Check if it's a single server or multiple servers if (jsonData.mcpServers) { // Multiple servers format let imported = 0; let failed = 0; for (const [name, config] of Object.entries(jsonData.mcpServers)) { try { const serverConfig = { type: "stdio", command: (config as any).command, args: (config as any).args || [], env: (config as any).env || {} }; const result = await api.mcpAddJson(name, JSON.stringify(serverConfig), importScope); if (result.success) { imported++; } else { failed++; } } catch (e) { failed++; } } onImportCompleted(imported, failed); } else if (jsonData.type && jsonData.command) { // Single server format const name = prompt("Enter a name for this server:"); if (!name) return; const result = await api.mcpAddJson(name, content, importScope); if (result.success) { onImportCompleted(1, 0); } else { onError(result.message); } } else { onError("Unrecognized JSON format. Expected MCP server configuration."); } } catch (error) { console.error("Failed to import JSON:", error); onError("Failed to import JSON file"); } finally { setImportingJson(false); // Reset the input event.target.value = ""; } }; /** * Handles exporting servers (placeholder) */ const handleExport = () => { // TODO: Implement export functionality onError("Export functionality coming soon!"); }; /** * Starts Claude Code as MCP server */ const handleStartMCPServer = async () => { try { await api.mcpServe(); onError("Claude Code MCP server started. You can now connect to it from other applications."); } catch (error) { console.error("Failed to start MCP server:", error); onError("Failed to start Claude Code as MCP server"); } }; return (

Import & Export

Import MCP servers from other sources or export your configuration

{/* Import Scope Selection */}
setImportScope(value)} options={[ { value: "local", label: "Local (this project only)" }, { value: "project", label: "Project (shared via .mcp.json)" }, { value: "user", label: "User (all projects)" }, ]} />

Choose where to save imported servers from JSON files

{/* Import from Claude Desktop */}

Import from Claude Desktop

Automatically imports all MCP servers from Claude Desktop. Installs to user scope (available across all projects).

{/* Import from JSON */}

Import from JSON

Import server configuration from a JSON file

{/* Export (Coming Soon) */}

Export Configuration

Export your MCP server configuration

{/* Serve as MCP */}

Use Claude Code as MCP Server

Start Claude Code as an MCP server that other applications can connect to

{/* Info Box */}
JSON Format Examples

Single server:

{`{
  "type": "stdio",
  "command": "/path/to/server",
  "args": ["--arg1", "value"],
  "env": { "KEY": "value" }
}`}
              

Multiple servers (.mcp.json format):

{`{
  "mcpServers": {
    "server1": {
      "command": "/path/to/server1",
      "args": [],
      "env": {}
    },
    "server2": {
      "command": "/path/to/server2",
      "args": ["--port", "8080"],
      "env": { "API_KEY": "..." }
    }
  }
}`}
              
); };