{"record":{"id":"559543d91d353d3e","repo":"affaan-m/ECC","slug":"mcp-config-must-be-a-json-object","errorCode":null,"errorMessage":"MCP config must be a JSON object","messagePattern":"MCP config must be a JSON object","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/mcp-config.js","lineNumber":14,"sourceCode":"'use strict';\n\nfunction parseDisabledMcpServers(value) {\n  return [...new Set(\n    String(value || '')\n      .split(',')\n      .map((entry) => entry.trim())\n      .filter(Boolean)\n  )];\n}\n\nfunction filterMcpConfig(config, disabledServerNames = []) {\n  if (!config || typeof config !== 'object' || Array.isArray(config)) {\n    throw new Error('MCP config must be a JSON object');\n  }\n\n  const servers = config.mcpServers;\n  if (!servers || typeof servers !== 'object' || Array.isArray(servers)) {\n    throw new Error('MCP config must include an mcpServers object');\n  }\n\n  const disabled = new Set(parseDisabledMcpServers(disabledServerNames));\n  if (disabled.size === 0) {\n    return {\n      config: {\n        ...config,\n        mcpServers: { ...servers },\n      },\n      removed: [],\n    };\n  }\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/mcp-config.js#L1-L32","documentation":"Thrown by filterMcpConfig() when the config argument is null, undefined, not an object type, or an array. The function only operates on plain JSON objects representing an MCP server configuration document.","triggerScenarios":"Passing JSON.parse output that is an array or a string; passing null because a config file was empty or unread; passing a stringified JSON by mistake.","commonSituations":"Reading a .mcp.json that contains a top-level array; a config loader returning null on missing file; double-encoding JSON so the value is a string.","solutions":["Ensure the config is a parsed JSON object (typeof === 'object', not Array.isArray, not null).","If loading from a file, JSON.parse the contents and check the result before passing it in.","Reject or fix config files whose top level is an array or scalar."],"exampleFix":"// before\nfilterMcpConfig(JSON.parse('[...]'));\n// after\nfilterMcpConfig(JSON.parse('{\"mcpServers\": {...}}'));","handlingStrategy":"type-guard","validationCode":"function isJsonObject(value) {\n  return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\nif (!isJsonObject(config)) {\n  throw new Error('MCP config must parse to a JSON object.');\n}","typeGuard":"function isMcpConfigObject(value) {\n  return value !== null && typeof value === 'object' && !Array.isArray(value);\n}","tryCatchPattern":"try {\n  result = filterMcpConfig(config, disabled);\n} catch (e) {\n  if (/MCP config must be a JSON object/.test(e.message)) {\n    if (typeof config === 'string') {\n      try { config = JSON.parse(config); } catch { throw e; }\n      result = filterMcpConfig(config, disabled);\n    } else throw e;\n  } else throw e;\n}","preventionTips":["Validate JSON.parse output shape (object, not array) before passing.","Use a JSON schema validator on config files at load time.","Refuse empty files explicitly so they do not become null downstream."],"tags":["mcp","config","validation","json"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}