MCPcopy Create free account
hub / github.com/ShipSecAI/studio / parseClaudeCodeConfig

Function parseClaudeCodeConfig

frontend/src/pages/McpLibraryPage.tsx:1215–1278  ·  view source on GitHub ↗
(
    jsonString: string,
  )

Source from the content-addressed store, hash-verified

1213
1214 // Parse Claude Code style JSON config
1215 const parseClaudeCodeConfig = (
1216 jsonString: string,
1217 ): {
1218 servers: { name: string; config: ServerFormData }[];
1219 error?: string;
1220 } => {
1221 try {
1222 const parsed = JSON.parse(jsonString);
1223
1224 // Validate structure - support both { mcpServers: {...} } and direct server config
1225 let mcpServers: Record<string, unknown>;
1226
1227 if (parsed.mcpServers && typeof parsed.mcpServers === 'object') {
1228 mcpServers = parsed.mcpServers;
1229 } else if (parsed.url || parsed.command) {
1230 // Direct single server config without name
1231 mcpServers = { 'Imported Server': parsed };
1232 } else {
1233 return {
1234 servers: [],
1235 error: 'Invalid config: expected mcpServers object or server config with url/command',
1236 };
1237 }
1238
1239 const servers: { name: string; config: ServerFormData }[] = [];
1240
1241 for (const [name, config] of Object.entries(mcpServers)) {
1242 const serverConfig = config as {
1243 url?: string;
1244 headers?: Record<string, string>;
1245 command?: string;
1246 args?: string[];
1247 };
1248
1249 // Determine transport type based on config
1250 let transportType: TransportType = 'http';
1251 if (serverConfig.command) {
1252 transportType = 'stdio';
1253 }
1254
1255 servers.push({
1256 name,
1257 config: {
1258 name,
1259 description: '',
1260 transportType,
1261 endpoint: serverConfig.url ?? '',
1262 command: serverConfig.command ?? '',
1263 args: serverConfig.args?.join('\n') ?? '',
1264 headers: serverConfig.headers ? JSON.stringify(serverConfig.headers, null, 2) : '',
1265 healthCheckUrl: '', // Will default to endpoint
1266 enabled: true,
1267 },
1268 });
1269 }
1270
1271 return { servers };
1272 } catch (e) {

Callers 3

McpLibraryPageFunction · 0.85
handleJsonSaveFunction · 0.85

Calls 2

parseMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected