MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / checkPlatformBan

Function checkPlatformBan

server/src/middleware/auth.ts:120–135  ·  view source on GitHub ↗

* Check platform ban with caching. Returns the ban if active, or null if not banned.

(cacheKey: string, checker: () => Promise<{ banned: boolean; ban?: Ban }>)

Source from the content-addressed store, hash-verified

118 * Check platform ban with caching. Returns the ban if active, or null if not banned.
119 */
120async function checkPlatformBan(cacheKey: string, checker: () => Promise<{ banned: boolean; ban?: Ban }>): Promise<Ban | null> {
121 const now = Date.now();
122 const cached = banCache.get(cacheKey);
123 if (cached && cached.expiresAt > now) {
124 return cached.banned ? (cached.ban ?? null) : null;
125 }
126
127 const result = await checker();
128 if (banCache.size > 10_000) banCache.clear();
129 banCache.set(cacheKey, {
130 banned: result.banned,
131 ban: result.ban,
132 expiresAt: now + BAN_CACHE_TTL_MS,
133 });
134 return result.banned ? (result.ban ?? null) : null;
135}
136
137/**
138 * Send a 403 ban response.

Callers 1

requireAuthFunction · 0.85

Calls 4

nowMethod · 0.80
getMethod · 0.45
clearMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected