{"record":{"id":"ba197e949ed61915","repo":"paperclipai/paperclip","slug":"gateway-token-not-found","errorCode":"gateway_token_not_found","errorMessage":"MCP gateway token not found","messagePattern":"MCP gateway token not found","errorType":"http","errorClass":"ToolGatewayHttpError","httpStatus":404,"severity":"error","filePath":"server/src/services/tool-gateway.ts","lineNumber":4964,"sourceCode":"    let agentId = row.gateway.agentId;\n    let runId: string | null = null;\n    let responsibleUserId: string | null = null;\n    let issueId = row.gateway.issueId;\n    let projectId = row.gateway.projectId;\n    if (row.token.subjectType === \"heartbeat_run\") {\n      const tokenRunId = row.token.subjectId;\n      if (!tokenRunId || !uuidPattern.test(tokenRunId)) {\n        return recordNamedGatewayAuthFailure({\n          gatewayId: input.gatewayId,\n          gatewayPublicId: input.gatewayPublicId,\n          bearerToken,\n          reasonCode: \"gateway_token_run_invalid\",\n          clientMetadata,\n        });\n      }\n      const [run] = await db\n        .select({\n          companyId: heartbeatRuns.companyId,\n          agentId: heartbeatRuns.agentId,\n          status: heartbeatRuns.status,\n          responsibleUserId: heartbeatRuns.responsibleUserId,\n        })\n        .from(heartbeatRuns)\n        .where(eq(heartbeatRuns.id, tokenRunId))\n        .limit(1);\n      if (!run || run.companyId !== row.gateway.companyId) {\n        return recordNamedGatewayAuthFailure({\n          gatewayId: input.gatewayId,\n          gatewayPublicId: input.gatewayPublicId,\n          bearerToken,\n          reasonCode: \"gateway_token_run_invalid\",\n          clientMetadata,\n        });\n      }\n      if (!ACTIVE_GATEWAY_RUN_STATUSES.has(run.status)) {\n        return recordNamedGatewayAuthFailure({","sourceCodeStart":4946,"sourceCodeEnd":4982,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/tool-gateway.ts#L4946-L4982","documentation":"Named gateway token management lookup: revokeNamedGatewayToken (or sibling token APIs) found no gateway token row for the supplied tokenId in this company. The 404 fires on the company-scoped select, covering deleted tokens and ids from other tenants.","triggerScenarios":"Thrown at server/src/services/tool-gateway.ts:4796 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The gateway token no longer exists (rotated or revoked). Re-authenticate to obtain a new token."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}