moeru-ai/airi · error · Error
invalid JSON: ${stringifyError(error)}
Error message
invalid JSON: ${stringifyError(error)} What it means
Thrown by parseElectronMcpConfigText when JSON.parse fails on the supplied text. It wraps the native SyntaxError message via stringifyError so the caller sees the original JSON parse reason (e.g. unexpected token). This is purely a syntax-layer failure distinct from the schema validation in parseElectronMcpConfig which runs afterward on successfully parsed text.
Source
Thrown at apps/stage-tamagotchi/src/shared/mcp-config.ts:120
*
* Use when:
* - Reading `mcp.json` from disk
* - Applying raw JSON drafts in the renderer
*
* Expects:
* - `text` contains JSON text for an MCP config file
*
* Returns:
* - A validated `ElectronMcpStdioConfigFile`
*/
export function parseElectronMcpConfigText(text: string): ElectronMcpStdioConfigFile {
let parsed: unknown
try {
parsed = JSON.parse(text)
}
catch (error) {
throw new Error(`invalid JSON: ${stringifyError(error)}`)
}
return parseElectronMcpConfig(parsed)
}
View on GitHub (pinned to 27111382b4)
Solutions
- Run the text through a JSON linter to find the exact syntax error location cited in the message.
- Remove trailing commas, comments, and single quotes; double-quote all keys and string values.
- If authoring in TS/JS, JSON.stringify the object before writing the file rather than hand-serializing.
Example fix
// before (text)
{ "mcpServers": { "fs": { "command": "npx", } } } // trailing comma -> invalid JSON
// after
{ "mcpServers": { "fs": { "command": "npx" } } } Defensive patterns
Strategy: validation
Validate before calling
function tryParseJson(text) {
try { JSON.parse(text); return null } catch (e) { return e.message }
}
const syntaxErr = tryParseJson(text)
if (syntaxErr) console.error(syntaxErr) Type guard
function isValidJsonText(text) {
try { JSON.parse(text); return true } catch { return false }
} Try / catch
try {
const cfg = parseElectronMcpConfigText(text)
} catch (e) {
if (e.message.startsWith('invalid JSON:'))
// point the user at the syntax location in the message
throw e
} Prevention
- Author mcp.json by JSON.stringify-ing an object, not by hand.
- Run the editor's JSON validator before saving.
- Avoid comments, trailing commas, and single quotes in mcp.json.
When it happens
Trigger: Loading mcp.json text that has a trailing comma, single quotes, an unquoted key, a stray comment, or is truncated; pasting a JS object literal (not JSON) into the config editor; a file with a BOM or mixed encoding.
Common situations: Editing mcp.json by hand and using JavaScript syntax (comments, trailing commas, unquoted keys) instead of strict JSON; copy-pasting a config snippet that lost a closing brace; CRLF/encoding artifacts from a non-UTF-8 editor.
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
- ${issue.path.join('.') || '<root>'}: ${issue.message}
- Invalid JSON for componentProps: ${(error as Error).message}
- Missing value for `${optionName}`.
- Provider definition with id "${definitionId}" not found.
- No active chat provider or model configured
AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12).
Data as JSON: /api/errors/994999f8354cc0ee.
Report an issue: GitHub.