Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

feat(mcp): accept rate_limit_retry in the MCP action-log ingest (#5433)

Erik Engervall273412baa50c
diff --git a/apps/api/src/services/mcp/action-logs.test.ts b/apps/api/src/services/mcp/action-logs.test.ts
index d50692051..98749e354 100644
--- a/apps/api/src/services/mcp/action-logs.test.ts
+++ b/apps/api/src/services/mcp/action-logs.test.ts
@@ -239,6 +239,7 @@ describe("MCP action log contract", () => {
llm_model: null,
duration_ms: null,
invalid_arguments: [],
+ rate_limit_retry: null,
});
expect(
input({
@@ -260,6 +261,16 @@ describe("MCP action log contract", () => {
invalid_arguments: ["limit:invalid_type", "*:unrecognized_keys"],
});
expect(input({ duration_ms: 0 }).duration_ms).toBe(0);
+ for (const rate_limit_retry of [
+ "recovered",
+ "failed",
+ "over_cap",
+ "not_retryable",
+ ]) {
+ expect(input({ rate_limit_retry }).rate_limit_retry).toBe(
+ rate_limit_retry,
+ );
+ }
expect(input({ invalid_arguments: ["(root):invalid_type"] })).toMatchObject(
{ invalid_arguments: ["(root):invalid_type"] },
);
@@ -285,6 +296,11 @@ describe("MCP action log contract", () => {
"invalid_arguments must be at most 10 <argument>:<issue> labels",
);
}
+ for (const rate_limit_retry of ["retrying", "RECOVERED", 1]) {
+ expect(() => input({ rate_limit_retry })).toThrow(
+ "rate_limit_retry must be recovered, failed, over_cap or not_retryable",
+ );
+ }
expect(() => input({ llm_model: "m".repeat(129) })).toThrow(
"llm_model must be at most 128 characters",
);
@@ -375,6 +391,7 @@ describe("MCP action log contract", () => {
llm_model: "gpt-6.1-sol",
duration_ms: 55,
invalid_arguments: ["limit:invalid_type"],
+ rate_limit_retry: "recovered",
}),
),
).resolves.toEqual({ disposition: "accepted", id: REQUEST_ID });
@@ -393,6 +410,7 @@ describe("MCP action log contract", () => {
llm_model: "gpt-6.1-sol",
duration_ms: 55,
invalid_arguments: ["limit:invalid_type"],
+ rate_limit_retry: "recovered",
});
expect(row).not.toHaveProperty("user_agent");
diff --git a/apps/api/src/services/mcp/action-logs.ts b/apps/api/src/services/mcp/action-logs.ts
index 6eb415bf5..897885dfa 100644
--- a/apps/api/src/services/mcp/action-logs.ts
+++ b/apps/api/src/services/mcp/action-logs.ts
@@ -21,6 +21,12 @@ const SECRET_PATTERN_ALL = new RegExp(SECRET_PATTERN.source, "gi");
const OBJECTIVE_MAX_LENGTH = 1000;
const ERROR_CODE_PATTERN = /^(?=.{2,64}$)[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
const MCP_CLIENT_SOURCES = ["client_info", "user_agent", "oauth"] as const;
+const RATE_LIMIT_RETRY_OUTCOMES = [
+ "recovered",
+ "failed",
+ "over_cap",
+ "not_retryable",
+] as const;
const DURATION_MS_MAX = 2_147_483_647;
const INVALID_ARGUMENTS_MAX = 10;
const INVALID_ARGUMENT_PATTERN =
@@ -49,6 +55,7 @@ const ALLOWED_FIELDS = new Set([
"llm_model",
"duration_ms",
"invalid_arguments",
+ "rate_limit_retry",
]);
export class McpActionLogValidationError extends Error {}
@@ -176,6 +183,7 @@ type McpActionLogInput = {
llm_model: string | null;
duration_ms: number | null;
invalid_arguments: string[];
+ rate_limit_retry: (typeof RATE_LIMIT_RETRY_OUTCOMES)[number] | null;
};
type McpActionLogRow = {
@@ -232,6 +240,17 @@ export function normalizeMcpActionLogInput(
) {
invalid("mcp_client_source must be client_info, user_agent or oauth");
}
+ const rateLimitRetry = payload.rate_limit_retry ?? null;
+ if (
+ rateLimitRetry !== null &&
+ !RATE_LIMIT_RETRY_OUTCOMES.includes(
+ rateLimitRetry as (typeof RATE_LIMIT_RETRY_OUTCOMES)[number],
+ )
+ ) {
+ invalid(
+ "rate_limit_retry must be recovered, failed, over_cap or not_retryable",
+ );
+ }
const resource = text(payload.resource, "resource", 128, true)!;
if (!RESOURCES.has(resource)) {
invalid("resource must be a canonical hosted MCP URL");
@@ -259,6 +278,7 @@ export function normalizeMcpActionLogInput(
llm_model: text(payload.llm_model, "llm_model"),
duration_ms: durationMs(payload.duration_ms),
invalid_arguments: invalidArguments(payload.invalid_arguments),
+ rate_limit_retry: rateLimitRetry as McpActionLogInput["rate_limit_retry"],
};
}