langflow-ai/langflow · error · Error
Invalid JSON format.
Error message
Invalid JSON format.
What it means
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.
Source
Thrown at src/frontend/src/utils/mcpUtils.ts:36
* Extracts all MCP servers from a JSON string or object.
* Supports:
* 1. { mcpServers: { ... } }
* 2. { ... } (object with server keys)
* 3. a single server object
* Returns: Array<MCPServerType> or throws an error.
*/
export function extractMcpServersFromJson(
json: string | object,
): MCPServerType[] {
let parsed: any = json;
if (typeof json === "string") {
try {
parsed = JSON.parse(json);
} catch (_e) {
try {
parsed = JSON.parse(`{${json}}`);
} catch (_e) {
throw new Error("Invalid JSON format.");
}
}
}
let serverEntries: [string, any][] = [];
// Case 1: { mcpServers: { ... } }
if (
parsed &&
typeof parsed === "object" &&
parsed.mcpServers &&
typeof parsed.mcpServers === "object"
) {
serverEntries = Object.entries(parsed.mcpServers);
}
// Case 2: { ... } (object with server keys)
else if (
parsed &&View on GitHub (pinned to 976ec789d2)
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
Example fix
// before (trailing comma + single quotes)
const input = "{'mcpServers': {'fs': {'command': 'npx',}},}";
// after
const input = JSON.stringify({
mcpServers: { fs: { command: "npx" } },
}); Defensive patterns
Strategy: validation
Validate before calling
function tryParseMcpJson(text: string): object | null {
try { return JSON.parse(text); } catch { /* fall through */ }
try { return JSON.parse(`{${text}}`); } catch { return null; }
}
const parsed = tryParseMcpJson(clipboardText);
if (!parsed) warnUserAboutJsonSyntax(); Type guard
const isJsonObject = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
Try / catch
try {
const servers = extractMcpServersFromJson(text);
} catch (e) {
if (e instanceof Error && e.message === "Invalid JSON format.") {
highlightJsonEditorErrors(); // keep user in the editor
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- No valid MCP server found in the input.
- Invalid flow data
- Failed to install MCP
- Deployment name is required
- error: invalid JSON in {source}: {exc}
AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14).
Data as JSON: /api/errors/8d11773ae38bd6b0.
Report an issue: GitHub.