@knath2000/codebase-indexing-mcp
Version:
MCP server for codebase indexing with Voyage AI embeddings and Qdrant vector storage
29 lines • 947 B
JavaScript
const WINDOW_MS = 60 * 1000; // 1 minute
const MAX_TOKENS = 30; // per workspace per minute
const buckets = new Map();
/**
* Simple token-bucket rate limiter keyed by `X-Workspace` header.
* Exposes 429 with Retry-After when exhausted.
*/
export function rateLimit(req, res, next) {
const workspace = String(req.header('X-Workspace') || 'default');
const now = Date.now();
let bucket = buckets.get(workspace);
if (!bucket) {
bucket = { tokens: MAX_TOKENS, last: now };
buckets.set(workspace, bucket);
}
// refill tokens based on elapsed time
const elapsed = now - bucket.last;
if (elapsed > WINDOW_MS) {
bucket.tokens = MAX_TOKENS;
bucket.last = now;
}
if (bucket.tokens <= 0) {
res.setHeader('Retry-After', '60');
return res.status(429).send('Rate limit exceeded');
}
bucket.tokens -= 1;
return next();
}
//# sourceMappingURL=rate-limit.js.map