File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -344,6 +344,33 @@ export async function GET(request: Request) {
344344 }
345345
346346 if ( isTransportGetRequest ( request ) ) {
347+ const clientIp = getClientIp ( request )
348+ const rateLimitResult = await checkRateLimit ( clientIp )
349+
350+ if ( ! rateLimitResult . success ) {
351+ const retryAfter = Math . ceil ( ( rateLimitResult . reset - Date . now ( ) ) / 1000 )
352+ return new Response (
353+ JSON . stringify ( {
354+ jsonrpc : '2.0' ,
355+ id : null ,
356+ error : {
357+ code : - 32000 ,
358+ message : 'Rate limit exceeded' ,
359+ data : `Try again in ${ retryAfter } seconds`
360+ }
361+ } ) ,
362+ {
363+ status : 429 ,
364+ headers : {
365+ ...createCorsHeaders ( request ) ,
366+ ...createRateLimitHeaders ( rateLimitResult ) ,
367+ 'Retry-After' : String ( retryAfter ) ,
368+ 'Content-Type' : 'application/json'
369+ }
370+ }
371+ )
372+ }
373+
347374 try {
348375 return withRouteHeaders (
349376 request ,
@@ -357,7 +384,8 @@ export async function GET(request: Request) {
357384 : undefined ,
358385 telemetryEnabled : ! MCP_TELEMETRY_DISABLED
359386 }
360- )
387+ ) ,
388+ rateLimitResult
361389 )
362390 } catch ( error ) {
363391 captureServerException ( error , {
You can’t perform that action at this time.
0 commit comments