paperclipai/paperclip · error · ToolGatewayHttpError

gateway_profile_invalid

gateway_profile_invalid

Error message

Gateway profile must belong to the company

What it means

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.

Source

Thrown at server/src/services/tool-gateway.ts:3508

    if (!connection || connection.transport !== "local_stdio") {
      throw new ToolGatewayHttpError(404, `Tool "${tool.name}" not found`, "tool_not_found");
    }
    if (!connection.enabled || connection.status !== "active") {
      throw new ToolGatewayHttpError(403, "Connection is disabled.", "local_stdio_connection_disabled", {
        connectionId: connection.id,
      });
    }
    return { entry, connection };
  }

  function localStdioTemplateId(connection: typeof toolConnections.$inferSelect): string {
    const config = asRecord(connection.config) ?? {};
    const templateId = config.templateId;
    if (typeof templateId !== "string" || templateId.trim().length === 0) {
      throw new ToolGatewayHttpError(422, "Local stdio MCP connection requires an approved templateId", "local_stdio_template_missing", {
        connectionId: connection.id,
      });
    }
    return templateId.trim();
  }

  async function resolveLocalStdioRuntimeTemplate(connection: typeof toolConnections.$inferSelect): Promise<LocalStdioRuntimeTemplate> {
    const templateId = localStdioTemplateId(connection);
    const builtIn = BUILTIN_LOCAL_STDIO_RUNTIME_TEMPLATES[templateId];
    if (builtIn) return { templateId, ...builtIn };
    const [template] = await db
      .select()
      .from(toolStdioCommandTemplates)
      .where(and(
        eq(toolStdioCommandTemplates.companyId, connection.companyId),
        eq(toolStdioCommandTemplates.templateKey, templateId),
      ))
      .limit(1);
    if (!template || template.status !== "active") {
      throw new ToolGatewayHttpError(422, "Local stdio MCP connection requires an active approved template", "local_stdio_template_invalid", {
        connectionId: connection.id,

View on GitHub (pinned to 01ad858492)

Solutions

  1. Select a gateway profile that belongs to the same company as the request.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at server/src/services/tool-gateway.ts:3367 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of paperclipai/paperclip@01ad858492 (2026-08-18). Data as JSON: /api/errors/a9a2caf5fa79c29b. Report an issue: GitHub.