mcp and content fix

This commit is contained in:
2026-10-14 13:28:04 +02:00
parent 015092e773
commit a7846d9770
18 changed files with 336 additions and 154 deletions
+28
View File
@@ -0,0 +1,28 @@
export type RateLimitArgs = {
/** Identifier to limit on — typically the client IP. */
key: string;
/** Max submissions allowed per window. Defaults to 5. */
max?: number;
/** Separate counter space per feature, e.g. 'form', 'search', 'mcp'. Default 'form'. */
scope?: string;
/** Window length in ms. Defaults to 60_000 (one minute). */
windowMs?: number;
};
/**
* Returns true when the request is within the limit, false when it should be
* rejected. A missing key (no IP) is allowed through — better to accept a
* submission than to block everyone behind a proxy that strips the header.
*/
export declare function checkRateLimit({ cost, key, max, scope, windowMs }: {
cost?: number;
} & RateLimitArgs): boolean;
/** Seconds until the key's window resets — for a Retry-After header. */
export declare function retryAfterSeconds(key: string, scope?: string): number;
/**
* Client IP from a Request. Cloudflare's `cf-connecting-ip` first (set by the
* edge, the real visitor), then the first `x-forwarded-for` hop, then
* `x-real-ip`. Empty string when none — the limiter then lets the request through.
*/
export declare function clientIp(req: Request): string;
/** Standard 429 for route handlers. */
export declare function tooManyRequests(key: string, scope: string, body: unknown): Response;