diff --git a/apps/mcp/src/server/analytics.ts b/apps/mcp/src/server/analytics.ts index c2b30c0b..3c629926 100644 --- a/apps/mcp/src/server/analytics.ts +++ b/apps/mcp/src/server/analytics.ts @@ -1,6 +1,7 @@ import type { McpServer } from "@modelcontextprotocol/server" import { instrument, type MCPAnalyticsOptions } from "@posthog/mcp" import { PostHog } from "posthog-node" +import { OUT_OF_CREDITS_MESSAGE } from "./client" import type { ActorContext, ServerEnv } from "./types" const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com" @@ -68,6 +69,11 @@ const metadataOnlyMcpEvent: NonNullable = ( return null } + const errorMessage = event.properties.$mcp_error_message + const outOfCredits = + typeof errorMessage === "string" && + errorMessage.includes(OUT_OF_CREDITS_MESSAGE) + return { ...event, properties: { @@ -76,6 +82,10 @@ const metadataOnlyMcpEvent: NonNullable = ( (key) => event.properties[key] !== undefined, ).map((key) => [key, event.properties[key]]), ), + // Billing state, not a server bug, so keep it out of the error rate. + ...(outOfCredits + ? { $mcp_is_error: false, $mcp_error_type: "out_of_credits" } + : {}), $process_person_profile: false, }, } diff --git a/apps/mcp/src/server/client/index.ts b/apps/mcp/src/server/client/index.ts index a2ccc8e7..1b575e15 100644 --- a/apps/mcp/src/server/client/index.ts +++ b/apps/mcp/src/server/client/index.ts @@ -21,6 +21,9 @@ const MAX_CHARS = 200000 export const DEFAULT_PROJECT_ID = "sm_project_default" const FETCH_TIMEOUT_MS = 30_000 const MCP_SOURCE = "supermemory-mcp" +// Analytics matches on this text to tag quota errors, keep them in sync. +export const OUT_OF_CREDITS_MESSAGE = + "Out of credits. Top up or upgrade at https://console.supermemory.ai/billing" export type { ContainerTag, @@ -457,7 +460,7 @@ export class SupermemoryClient { case 401: throw new Error("Authentication failed. Please re-authenticate.") case 402: - throw new Error("Memory limit reached. Upgrade at supermemory.ai") + throw new Error(OUT_OF_CREDITS_MESSAGE) case 403: throw new Error( message ||