{"record":{"id":"a9a2caf5fa79c29b","repo":"paperclipai/paperclip","slug":"gateway-profile-invalid","errorCode":"gateway_profile_invalid","errorMessage":"Gateway profile must belong to the company","messagePattern":"Gateway profile must belong to the company","errorType":"http","errorClass":"ToolGatewayHttpError","httpStatus":422,"severity":"error","filePath":"server/src/services/tool-gateway.ts","lineNumber":3508,"sourceCode":"    if (!connection || connection.transport !== \"local_stdio\") {\n      throw new ToolGatewayHttpError(404, `Tool \"${tool.name}\" not found`, \"tool_not_found\");\n    }\n    if (!connection.enabled || connection.status !== \"active\") {\n      throw new ToolGatewayHttpError(403, \"Connection is disabled.\", \"local_stdio_connection_disabled\", {\n        connectionId: connection.id,\n      });\n    }\n    return { entry, connection };\n  }\n\n  function localStdioTemplateId(connection: typeof toolConnections.$inferSelect): string {\n    const config = asRecord(connection.config) ?? {};\n    const templateId = config.templateId;\n    if (typeof templateId !== \"string\" || templateId.trim().length === 0) {\n      throw new ToolGatewayHttpError(422, \"Local stdio MCP connection requires an approved templateId\", \"local_stdio_template_missing\", {\n        connectionId: connection.id,\n      });\n    }\n    return templateId.trim();\n  }\n\n  async function resolveLocalStdioRuntimeTemplate(connection: typeof toolConnections.$inferSelect): Promise<LocalStdioRuntimeTemplate> {\n    const templateId = localStdioTemplateId(connection);\n    const builtIn = BUILTIN_LOCAL_STDIO_RUNTIME_TEMPLATES[templateId];\n    if (builtIn) return { templateId, ...builtIn };\n    const [template] = await db\n      .select()\n      .from(toolStdioCommandTemplates)\n      .where(and(\n        eq(toolStdioCommandTemplates.companyId, connection.companyId),\n        eq(toolStdioCommandTemplates.templateKey, templateId),\n      ))\n      .limit(1);\n    if (!template || template.status !== \"active\") {\n      throw new ToolGatewayHttpError(422, \"Local stdio MCP connection requires an active approved template\", \"local_stdio_template_invalid\", {\n        connectionId: connection.id,","sourceCodeStart":3490,"sourceCodeEnd":3526,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/tool-gateway.ts#L3490-L3526","documentation":"assertGatewayContext validation: the profileId supplied when creating/updating a gateway does not resolve to a tool profile in the same company. The 422 gateway_profile_invalid fires on the company-scoped select, catching both nonexistent ids and ids leaked from another company.","triggerScenarios":"Thrown at server/src/services/tool-gateway.ts:3367 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Select a gateway profile that belongs to the same company as the request."],"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-14T00:17:10.932Z"}