@cyanheads/pubmed-mcp-server
Version:
Search PubMed/Europe PMC, fetch articles and full text (PMC/EPMC/Unpaywall), citations, MeSH terms via MCP. STDIO or Streamable HTTP.
36 lines • 1.65 kB
TypeScript
/**
* @fileoverview Rate-limited request scheduler for NCBI E-utility calls. Caps
* concurrent in-flight requests and enforces a minimum start-gap between
* dispatches to stay within NCBI's documented per-second ceiling. Supports
* abort-during-wait so callers' deadlines can bound queue time end-to-end.
* @module src/services/ncbi/request-queue
*/
import type { NcbiRequestParams } from './types.js';
/**
* Schedules NCBI API requests against two independent ceilings:
*
* - **Throughput** (`minStartGapMs`): minimum delay between two consecutive
* dispatch times. Matches NCBI's per-second start-rate cap (≈3/s without
* an API key, ≈10/s with one).
* - **Concurrency** (`maxConcurrent`): maximum number of requests in flight
* simultaneously. Decouples concurrency from rate, so slow upstream
* responses don't block new dispatches.
*
* Enqueue accepts an optional `AbortSignal` so callers can bound their total
* time inside the scheduler — when the signal fires, a still-waiting task
* rejects immediately instead of sitting behind a saturated worker for
* minutes.
*/
export declare class NcbiRequestQueue {
private readonly waiters;
private readonly minStartGapMs;
private readonly maxConcurrent;
private readonly maxQueueSize;
private inFlight;
private lastStartTime;
private nextDispatchTimer;
constructor(minStartGapMs: number, maxConcurrent?: number, maxQueueSize?: number);
enqueue<T>(task: () => Promise<T>, endpoint: string, params: NcbiRequestParams, signal?: AbortSignal): Promise<T>;
private tryDispatch;
}
//# sourceMappingURL=request-queue.d.ts.map