MCPcopy Index your code
hub / github.com/winfunc/opcode / MCPAddServer

Function MCPAddServer

src/components/MCPAddServer.tsx:33–465  ·  view source on GitHub ↗
({
  onServerAdded,
  onError,
})

Source from the content-addressed store, hash-verified

31 * Supports both stdio and SSE transport types
32 */
33export const MCPAddServer: React.FC<MCPAddServerProps> = ({
34 onServerAdded,
35 onError,
36}) => {
37 const [transport, setTransport] = useState<"stdio" | "sse">("stdio");
38 const [saving, setSaving] = useState(false);
39
40 // Analytics tracking
41 const trackEvent = useTrackEvent();
42
43 // Stdio server state
44 const [stdioName, setStdioName] = useState("");
45 const [stdioCommand, setStdioCommand] = useState("");
46 const [stdioArgs, setStdioArgs] = useState("");
47 const [stdioScope, setStdioScope] = useState("local");
48 const [stdioEnvVars, setStdioEnvVars] = useState<EnvironmentVariable[]>([]);
49
50 // SSE server state
51 const [sseName, setSseName] = useState("");
52 const [sseUrl, setSseUrl] = useState("");
53 const [sseScope, setSseScope] = useState("local");
54 const [sseEnvVars, setSseEnvVars] = useState<EnvironmentVariable[]>([]);
55
56 /**
57 * Adds a new environment variable
58 */
59 const addEnvVar = (type: "stdio" | "sse") => {
60 const newVar: EnvironmentVariable = {
61 id: `env-${Date.now()}`,
62 key: "",
63 value: "",
64 };
65
66 if (type === "stdio") {
67 setStdioEnvVars(prev => [...prev, newVar]);
68 } else {
69 setSseEnvVars(prev => [...prev, newVar]);
70 }
71 };
72
73 /**
74 * Updates an environment variable
75 */
76 const updateEnvVar = (type: "stdio" | "sse", id: string, field: "key" | "value", value: string) => {
77 if (type === "stdio") {
78 setStdioEnvVars(prev => prev.map(v =>
79 v.id === id ? { ...v, [field]: value } : v
80 ));
81 } else {
82 setSseEnvVars(prev => prev.map(v =>
83 v.id === id ? { ...v, [field]: value } : v
84 ));
85 }
86 };
87
88 /**
89 * Removes an environment variable
90 */

Callers

nothing calls this directly

Calls 2

useTrackEventFunction · 0.90
renderEnvVarsFunction · 0.85

Tested by

no test coverage detected