{"record":{"id":"ad7329d65eb1cfc6","repo":"paperclipai/paperclip","slug":"agentid-is-required-because-paperclip-agent-id-is","errorCode":null,"errorMessage":"agentId is required because PAPERCLIP_AGENT_ID is not set","messagePattern":"agentId is required because PAPERCLIP_AGENT_ID is not set","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/mcp-server/src/client.ts","lineNumber":73,"sourceCode":"    return {\n      companyId: this.config.companyId,\n      agentId: this.config.agentId,\n      runId: this.config.runId,\n    };\n  }\n\n  resolveCompanyId(companyId?: string | null): string {\n    const resolved = companyId?.trim() || this.config.companyId;\n    if (!resolved) {\n      throw new Error(\"companyId is required because PAPERCLIP_COMPANY_ID is not set\");\n    }\n    return resolved;\n  }\n\n  resolveAgentId(agentId?: string | null): string {\n    const resolved = agentId?.trim() || this.config.agentId;\n    if (!resolved) {\n      throw new Error(\"agentId is required because PAPERCLIP_AGENT_ID is not set\");\n    }\n    return resolved;\n  }\n\n  async requestJson<T>(method: string, path: string, options: JsonRequestOptions = {}): Promise<T> {\n    if (!path.startsWith(\"/\")) {\n      throw new Error(`API path must start with \"/\": ${path}`);\n    }\n\n    const url = new URL(path.slice(1), `${this.config.apiUrl}/`);\n    const headers: Record<string, string> = {\n      Authorization: `Bearer ${this.config.apiKey}`,\n      Accept: \"application/json\",\n    };\n    if (options.body !== undefined) {\n      headers[\"Content-Type\"] = \"application/json\";\n    }\n    if ((options.includeRunId ?? isWriteMethod(method)) && this.config.runId) {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/mcp-server/src/client.ts#L55-L91","documentation":"resolveAgentId mirrors resolveCompanyId: prefers an explicitly passed agentId, falls back to config.agentId (from PAPERCLIP_AGENT_ID), and throws when neither resolves. Agent identity is required for activity logging and run attribution on every mutating call.","triggerScenarios":"A tool is invoked without an agentId argument while the server was started without PAPERCLIP_AGENT_ID (or it was whitespace).","commonSituations":"Same as 448: .env not loaded, var stripped by a launcher, or a multi-agent deployment that intended to pass agentId per call but did not.","solutions":["Set PAPERCLIP_AGENT_ID in the server's environment.","Pass agentId explicitly in each tool call.","Confirm the env var reaches the process."],"exampleFix":"// before: no PAPERCLIP_AGENT_ID\n// after\nexport PAPERCLIP_AGENT_ID=agent_abc\n# restart","handlingStrategy":"validation","validationCode":"const agentId = process.env.PAPERCLIP_AGENT_ID?.trim();\nif (!agentId) throw new Error('Startup config error: PAPERCLIP_AGENT_ID must be set');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set PAPERCLIP_AGENT_ID in the runtime environment.","For multi-agent setups, pass agentId per call rather than relying solely on env.","Confirm the var is exported by the launcher (systemd/docker/compose)."],"tags":["configuration","paperclip-mcp","env","agent-identity"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}