{"record":{"id":"20da2fcd7b853896","repo":"nanocoai/nanoclaw","slug":"parsed-error","errorCode":null,"errorMessage":"${parsed.error}","messagePattern":"\\$\\{parsed\\.error\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"container/agent-runner/src/mcp-tools/self-mod.ts","lineNumber":196,"sourceCode":"        command: { type: 'string', description: 'Command to run the MCP server' },\n        url: {\n          type: 'string',\n          description: 'Streamable HTTP MCP endpoint (HTTPS; plain HTTP only for localhost / host.docker.internal)',\n        },\n        args: { type: 'array', items: { type: 'string' }, description: 'Command arguments' },\n        env: { type: 'object', description: 'Environment variables for the server' },\n      },\n      required: ['name'],\n    },\n  },\n  async handler(args) {\n    const name = typeof args.name === 'string' ? args.name : '';\n    if (!name) return err('name is required');\n    if (!MCP_SERVER_NAME_RE.test(name)) {\n      return err('server name must be 1-64 characters of letters, digits, \"_\" or \"-\"');\n    }\n    const parsed = parseMcpServerInput(args);\n    if ('error' in parsed) return err(parsed.error);\n\n    const requestId = generateId();\n    await writeMessageOut({\n      id: requestId,\n      kind: 'system',\n      content: JSON.stringify({\n        action: 'add_mcp_server',\n        name,\n        ...parsed.config,\n      }),\n    });\n\n    log(`add_mcp_server: ${requestId} → \"${name}\" (${'url' in parsed.config ? 'HTTP' : parsed.config.command})`);\n    return ok(`MCP server request submitted. You will be notified when admin approves or rejects.`);\n  },\n};\n\nregisterTools([installPackages, addMcpServer]);","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/nanocoai/nanoclaw/blob/294ef2aee85218b23ad30eda9dfe10e590b54a8c/container/agent-runner/src/mcp-tools/self-mod.ts#L178-L214","documentation":"The self-mod MCP tool `add_mcp_server` rejects the server configuration before submitting it for approval. `parseMcpServerInput` failed to coerce the args into a valid MCP server config (bad/missing transport fields, bad URL, or malformed JSON), so the error string is surfaced verbatim. This is client-side validation inside the agent container, not a host or approval failure.","triggerScenarios":"Calling the add_mcp_server MCP tool with args.name valid but args describing the server (command/url, env, args) malformed — e.g. missing `command` for stdio servers, a non-URL `url` for HTTP servers, or wrong types for env/args.","commonSituations":"Agent constructs the server config from chat text and drops a required field; passing an SSE-style {url} to a stdio shape; env given as an array instead of an object; older callers using a pre-schema field name after an agent-runner update.","solutions":["Read the returned message — it names the exact missing/invalid field; fix the args object accordingly","Check parseMcpServerInput's accepted shapes (stdio: {command,args,env}; http: {url,headers}) and match one exactly","Validate the config shape in your own code before invoking the tool","If the shape you used worked before, check for an agent-runner update that tightened the parser"],"exampleFix":"// before\nawait add_mcp_server({ name: 'github', server: { cmd: 'npx -y @modelcontextprotocol/server-github' } });\n// after\nawait add_mcp_server({ name: 'github', server: { command: 'npx', args: ['-y', '@modelcontextprotocol/server-github'], env: { GITHUB_TOKEN: '...' } } });","handlingStrategy":"validation","validationCode":"function isValidStdioServer(s) {\n  return !!s && typeof s.command === 'string' && s.command.length > 0 &&\n    Array.isArray(s.args ?? []) && typeof (s.env ?? {}) === 'object';\n}","typeGuard":"function isMcpServerInput(v: unknown): v is { command: string; args?: string[]; env?: Record<string,string> } {\n  if (typeof v !== 'object' || v === null) return false;\n  const o = v as Record<string, unknown>;\n  return typeof o.command === 'string' && o.command.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Build MCP server configs from a typed object, never by string concatenation","Mirror the exact shape parseMcpServerInput accepts (stdio vs http) before calling the tool","Log the raw args next to the error so the malformed field is obvious"],"tags":["mcp","self-mod","validation","agent-container"],"backgroundTag":"invalid-tool-arguments","analyzedSha":"294ef2aee85218b23ad30eda9dfe10e590b54a8c","analyzedAt":"2026-08-28T13:59:10.357Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}