{"record":{"id":"4b1cc332b1d576a1","repo":"Mintplex-Labs/anything-llm","slug":"mcp-server-args-must-be-an-array","errorCode":null,"errorMessage":"MCP server args must be an array","messagePattern":"MCP server args must be an array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/MCP/hypervisor/index.js","lineNumber":394,"sourceCode":"        throw new Error(\n          `MCP server \"${name}\": missing required \"url\" for ${server.type || \"sse\"} transport`\n        );\n      }\n\n      try {\n        new URL(server.url);\n      } catch {\n        throw new Error(`MCP server \"${name}\": invalid URL \"${server.url}\"`);\n      }\n      return;\n    }\n\n    if (type === \"stdio\") {\n      if (\n        Object.prototype.hasOwnProperty.call(server, \"args\") &&\n        !Array.isArray(server.args)\n      )\n        throw new Error(\"MCP server args must be an array\");\n    }\n    return;\n  }\n\n  /**\n   * Setup the server transport by type and server definition\n   * @param {Object} server - The server definition\n   * @param {MCPServerTypes} type - The server type\n   * @returns {Promise<StdioClientTransport | StreamableHTTPClientTransport | SSEClientTransport>} - The server transport\n   */\n  async #setupServerTransport(server, type) {\n    // if not stdio then it is http or sse\n    if (type !== \"stdio\") return this.createHttpTransport(server);\n\n    return new StdioClientTransport({\n      command: server.command,\n      args: server?.args ?? [],\n      ...(await this.#buildMCPServerENV(server)),","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/MCP/hypervisor/index.js#L376-L412","documentation":"Thrown by #validateServerDefinitionByType when a server is classified as stdio (it has a command) and the optional args field is present but not an array. StdioClientTransport expects args as an array of strings passed to the spawned command, so a non-array value (string, object, number) is a config error. The check uses hasOwnProperty so a missing args is fine (defaults to []), only a present-but-wrong-type args fails.","triggerScenarios":"A stdio MCP server config where args is a single string (e.g. \"--flag\") instead of [\"--flag\"], an object, a number, or any non-array. Determination as stdio happens because the entry has a command field.","commonSituations":"Writing args as a string instead of a one-element array — the single most common form; copy-pasting a CLI invocation as a flat string; JSON config authoring mistake; merging configs where args got coerced to a string.","solutions":["Wrap single arguments in an array: \"args\": [\"--flag\"] instead of \"args\": \"--flag\".","Ensure every element of args is a string (no nested objects/numbers).","If multiple args, list them as separate array elements: [\"--port\", \"8080\", \"--verbose\"].","Remember args is optional — if there are none, omit the key rather than setting it to an empty non-array."],"exampleFix":"// before\n{\n  \"myServer\": {\n    \"command\": \"npx\",\n    \"args\": \"-y @modelcontextprotocol/server-filesystem /tmp\"\n  }\n}\n\n// after\n{\n  \"myServer\": {\n    \"command\": \"npx\",\n    \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \"/tmp\"]\n  }\n}","handlingStrategy":"type-guard","validationCode":"function validateStdioArgs(name, server) {\n  if (Object.prototype.hasOwnProperty.call(server, 'args')) {\n    if (!Array.isArray(server.args) || !server.args.every(a => typeof a === 'string')) {\n      throw new Error(`MCP server '${name}': args must be an array of strings.`);\n    }\n  }\n}","typeGuard":"/** @param {unknown} s */\nfunction hasValidStdioArgs(s) {\n  if (!s || typeof s !== 'object') return false;\n  if (!('args' in s)) return true; // args optional\n  return Array.isArray(s.args) && s.args.every(a => typeof a === 'string');\n}","tryCatchPattern":"try {\n  // start MCP stdio server\n} catch (e) {\n  if (/MCP server args must be an array/.test(e.message)) {\n    throw new Error('Wrap MCP server args in an array of strings, e.g. [\"--flag\", \"value\"].');\n  }\n  throw e;\n}","preventionTips":["Always write args as an array of strings, even for a single argument: [\"--flag\"] not \"--flag\".","If there are no args, omit the key rather than setting a non-array.","Validate the MCP config with a JSON schema before starting the hypervisor.","Ensure every args element is a string — no numbers or objects."],"tags":["mcp","configuration","validation","stdio","config-schema"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}