Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions app/mcp/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function authorizeToolCall(
};
}
if (rateLimit.status === "unavailable") {
return { result: rateLimitUnavailableResult() };
return { result: rateLimitUnavailableResult(auth.userId, bucket) };
}
return { userId: auth.userId };
}
Expand All @@ -150,8 +150,14 @@ function rateLimitResult(
};
}

function rateLimitUnavailableResult(): CallToolResult {
log.warn("rate limit unavailable; rejecting request");
function rateLimitUnavailableResult(
userId: string,
bucket: { name: string }
): CallToolResult {
log.warn("rate limit unavailable; rejecting request", {
bucket: bucket.name,
userId,
});
return {
content: [
{
Expand Down
2 changes: 2 additions & 0 deletions lib/collections/link-reachability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export async function consumeProbeBudget(
if (!redis) {
if (isRedisConfigured()) {
log.warn("Link probe budget unavailable; refusing probes", {
amount,
userId,
});
return { allowed: false, retryAfterMs: PROBE_BUDGET_WINDOW_MS };
Expand Down Expand Up @@ -142,6 +143,7 @@ export async function consumeProbeBudget(
} catch (error) {
if (isRedisConfigured()) {
log.warn("Link probe Redis budget failed; refusing probes", {
amount,
error,
userId,
});
Expand Down
1 change: 1 addition & 0 deletions lib/integrations/mcp/rate-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export async function checkMcpRateLimit(
log.warn("MCP rate limit counter failed; failing closed", {
bucket: bucket.name,
error,
userId,
});
return { status: "unavailable" };
}
Expand Down