{"record":{"id":"8d11773ae38bd6b0","repo":"langflow-ai/langflow","slug":"invalid-json-format","errorCode":null,"errorMessage":"Invalid JSON format.","messagePattern":"Invalid JSON format\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/frontend/src/utils/mcpUtils.ts","lineNumber":36,"sourceCode":" * Extracts all MCP servers from a JSON string or object.\n * Supports:\n * 1. { mcpServers: { ... } }\n * 2. { ... } (object with server keys)\n * 3. a single server object\n * Returns: Array<MCPServerType> or throws an error.\n */\nexport function extractMcpServersFromJson(\n  json: string | object,\n): MCPServerType[] {\n  let parsed: any = json;\n  if (typeof json === \"string\") {\n    try {\n      parsed = JSON.parse(json);\n    } catch (_e) {\n      try {\n        parsed = JSON.parse(`{${json}}`);\n      } catch (_e) {\n        throw new Error(\"Invalid JSON format.\");\n      }\n    }\n  }\n\n  let serverEntries: [string, any][] = [];\n\n  // Case 1: { mcpServers: { ... } }\n  if (\n    parsed &&\n    typeof parsed === \"object\" &&\n    parsed.mcpServers &&\n    typeof parsed.mcpServers === \"object\"\n  ) {\n    serverEntries = Object.entries(parsed.mcpServers);\n  }\n  // Case 2: { ... } (object with server keys)\n  else if (\n    parsed &&","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/frontend/src/utils/mcpUtils.ts#L18-L54","documentation":"Thrown by extractMcpServersFromJson in mcpUtils when the input string cannot be parsed as JSON even after a fallback that wraps it in braces (to support fragment input like '\"mcpServers\": {...}'). Both JSON.parse attempts failed, so the text is not recoverable JSON and MCP server extraction stops.","triggerScenarios":"Pasting MCP config text with trailing commas, single quotes, comments, smart quotes from a chat/docs page, or unquoted keys — e.g. copying a Claude/mcpServers snippet from prose where curly quotes replaced straight quotes.","commonSituations":"Copy-paste from websites or chat apps that 'beautify' quotes; hand-typing JSON; trailing commas which strict JSON.parse rejects; missing closing brace that the brace-wrapper cannot fix.","solutions":["Paste the text into a JSON linter (editor, jsonlint) and fix syntax errors: trailing commas, single→double quotes, smart→straight quotes","Wrap the whole thing in { } once — the helper only tries adding outer braces, not fixing inner structure","Prefer exporting real JSON from the MCP client config file instead of re-typing it","If passing programmatically, pass an object instead of a string — objects skip parsing entirely"],"exampleFix":"// before (trailing comma + single quotes)\nconst input = \"{'mcpServers': {'fs': {'command': 'npx',}},}\";\n\n// after\nconst input = JSON.stringify({\n  mcpServers: { fs: { command: \"npx\" } },\n});","handlingStrategy":"validation","validationCode":"function tryParseMcpJson(text: string): object | null {\n  try { return JSON.parse(text); } catch { /* fall through */ }\n  try { return JSON.parse(`{${text}}`); } catch { return null; }\n}\nconst parsed = tryParseMcpJson(clipboardText);\nif (!parsed) warnUserAboutJsonSyntax();","typeGuard":"const isJsonObject = (v: unknown): v is Record<string, unknown> =>\n  typeof v === \"object\" && v !== null && !Array.isArray(v);","tryCatchPattern":"try {\n  const servers = extractMcpServersFromJson(text);\n} catch (e) {\n  if (e instanceof Error && e.message === \"Invalid JSON format.\") {\n    highlightJsonEditorErrors(); // keep user in the editor\n  } else throw e;\n}","preventionTips":["Run pasted text through JSON.parse in a scratch editor before importing","Watch for smart quotes and trailing commas when copying config from chat/docs","Pass objects (not strings) when calling programmatically"],"tags":["frontend","mcp","json","validation","copy-paste"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}