MCPcopy Create free account
hub / github.com/CopilotKit/open-mcp-client / MCPConfigForm

Function MCPConfigForm

app/components/MCPConfigForm.tsx:48–632  ·  view source on GitHub ↗
({ showSpreadsheet, setShowSpreadsheet }: { showSpreadsheet: boolean, setShowSpreadsheet: (value: boolean) => void })

Source from the content-addressed store, hash-verified

46);
47
48export function MCPConfigForm({ showSpreadsheet, setShowSpreadsheet }: { showSpreadsheet: boolean, setShowSpreadsheet: (value: boolean) => void }) {
49 // Use our localStorage hook for persistent storage
50 const [savedConfigs, setSavedConfigs] = useLocalStorage<
51 Record<string, ServerConfig>
52 >(STORAGE_KEY, {});
53
54 // Initialize agent state with the data from localStorage
55 const { state: agentState, setState: setAgentState } = useCoAgent<AgentState>(
56 {
57 name: "sample_agent",
58 initialState: {
59 mcp_config: savedConfigs,
60 },
61 }
62 );
63
64 // Simple getter for configs
65 const configs = agentState?.mcp_config || {};
66
67 // Simple setter wrapper for configs
68 const setConfigs = (newConfigs: Record<string, ServerConfig>) => {
69 setAgentState({ ...agentState, mcp_config: newConfigs });
70 setSavedConfigs(newConfigs);
71 };
72
73 const [serverName, setServerName] = useState("");
74 const [connectionType, setConnectionType] = useState<ConnectionType>("stdio");
75 const [command, setCommand] = useState("");
76 const [args, setArgs] = useState("");
77 const [url, setUrl] = useState("");
78 const [isLoading, setIsLoading] = useState(true);
79 const [showAddServerForm, setShowAddServerForm] = useState(false);
80 const [showExampleConfigs, setShowExampleConfigs] = useState(false);
81
82 // Calculate server statistics
83 const totalServers = Object.keys(configs).length;
84 const stdioServers = Object.values(configs).filter(
85 (config) => config.transport === "stdio"
86 ).length;
87 const sseServers = Object.values(configs).filter(
88 (config) => config.transport === "sse"
89 ).length;
90
91 // Set loading to false when state is loaded
92 useEffect(() => {
93 if (agentState) {
94 setIsLoading(false);
95 }
96 }, [agentState]);
97
98 const handleExampleConfig = (exampleConfig: Record<string, ServerConfig>) => {
99 // Merge the example with existing configs or replace them based on user preference
100 if (Object.keys(configs).length > 0) {
101 const shouldReplace = window.confirm(
102 "Do you want to replace your current configuration with this example? Click 'OK' to replace, or 'Cancel' to merge."
103 );
104
105 if (shouldReplace) {

Callers

nothing calls this directly

Calls 2

useLocalStorageFunction · 0.90
removeConfigFunction · 0.85

Tested by

no test coverage detected