{"record":{"id":"acc5153ed44d4e27","repo":"coleam00/Archon","slug":"mcp-config-servername-env-must-be-a-json-object","errorCode":null,"errorMessage":"MCP config ${serverName}.env must be a JSON object of string values (got ${describeJsonType(server.env)})","messagePattern":"MCP config (.+?)\\.env must be a JSON object of string values \\(got (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/providers/src/mcp/config.ts","lineNumber":68,"sourceCode":"function expandEnvVars(\n  config: Record<string, unknown>,\n  envSource: EnvSource\n): {\n  expanded: Record<string, unknown>;\n  missingVars: string[];\n} {\n  const result: Record<string, unknown> = {};\n  const missingVars: string[] = [];\n  for (const [serverName, serverConfig] of Object.entries(config)) {\n    if (typeof serverConfig !== 'object' || serverConfig === null || Array.isArray(serverConfig)) {\n      throw new Error(\n        `MCP server \"${serverName}\" must be a JSON object (got ${describeJsonType(serverConfig)})`\n      );\n    }\n    const server = { ...(serverConfig as Record<string, unknown>) };\n    if (server.env !== undefined) {\n      if (typeof server.env !== 'object' || server.env === null || Array.isArray(server.env)) {\n        throw new Error(\n          `MCP config ${serverName}.env must be a JSON object of string values (got ${describeJsonType(server.env)})`\n        );\n      }\n      server.env = expandEnvVarsInRecord(\n        server.env as Record<string, unknown>,\n        missingVars,\n        envSource,\n        `${serverName}.env`\n      );\n    }\n    if (server.headers !== undefined) {\n      if (\n        typeof server.headers !== 'object' ||\n        server.headers === null ||\n        Array.isArray(server.headers)\n      ) {\n        throw new Error(\n          `MCP config ${serverName}.headers must be a JSON object of string values (got ${describeJsonType(server.headers)})`","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/providers/src/mcp/config.ts#L50-L86","documentation":"If a server entry defines env, it must be a JSON object whose values are strings (each value is env-var interpolated). A non-object env, or an array/null, cannot hold key/value environment variables, so expandEnvVars throws naming the server and the offending type.","triggerScenarios":"loadMcpConfig where a server has \"env\": \"DEBUG=1\" (string), \"env\": [\"A=1\"] (array), or \"env\": null instead of an object of strings.","commonSituations":"Migrating from dotenv-style lines pasted into JSON; YAML-to-JSON conversion producing lists; a script setting env to null when no vars exist; shell export syntax copied verbatim.","solutions":["Convert env to an object of strings: {\"env\": {\"DEBUG\": \"1\"}}.","Delete the env key entirely if there are no variables (undefined is allowed).","Split comma or newline separated env strings into individual object entries."],"exampleFix":"// before\n{\"server\": {\"command\": \"node\", \"env\": \"DEBUG=1\\nLOG=info\"}}\n// after\n{\"server\": {\"command\": \"node\", \"env\": {\"DEBUG\": \"1\", \"LOG\": \"info\"}}}","handlingStrategy":"validation","validationCode":"const s = cfg[serverName];\nif ('env' in s && (typeof s.env !== 'object' || s.env === null || Array.isArray(s.env))) {\n  throw new Error(`${serverName}.env must be an object of strings`);\n}","typeGuard":"const isEnvObject = (v: unknown): v is Record<string, string> =>\n  typeof v === 'object' && v !== null && !Array.isArray(v) &&\n  Object.values(v).every((x) => typeof x === 'string');","tryCatchPattern":null,"preventionTips":["Never paste dotenv 'KEY=VALUE' lines into the env field; convert them to key/value pairs.","Omit env entirely instead of writing null when there are no variables.","Lint the config with a schema requiring env?: {[k: string]: string}."],"tags":["config","validation","mcp","environment-variables"],"backgroundTag":"mcp-config-schema-invalid","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}