@cyanheads/biorxiv-mcp-server 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +12 -8
- package/CLAUDE.md +12 -8
- package/Dockerfile +3 -3
- package/README.md +31 -30
- package/changelog/0.4.x/0.4.1.md +27 -0
- package/changelog/0.4.x/0.4.2.md +34 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-get-fulltext.tool.d.ts +8 -6
- package/dist/mcp-server/tools/definitions/biorxiv-get-fulltext.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-get-fulltext.tool.js +94 -28
- package/dist/mcp-server/tools/definitions/biorxiv-get-fulltext.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-get-preprint.tool.d.ts +24 -9
- package/dist/mcp-server/tools/definitions/biorxiv-get-preprint.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-get-preprint.tool.js +137 -52
- package/dist/mcp-server/tools/definitions/biorxiv-get-preprint.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-get-published-version.tool.d.ts +22 -9
- package/dist/mcp-server/tools/definitions/biorxiv-get-published-version.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-get-published-version.tool.js +78 -33
- package/dist/mcp-server/tools/definitions/biorxiv-get-published-version.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-list-published-versions.tool.d.ts +25 -5
- package/dist/mcp-server/tools/definitions/biorxiv-list-published-versions.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-list-published-versions.tool.js +130 -22
- package/dist/mcp-server/tools/definitions/biorxiv-list-published-versions.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-list-recent.tool.d.ts +5 -2
- package/dist/mcp-server/tools/definitions/biorxiv-list-recent.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-list-recent.tool.js +51 -34
- package/dist/mcp-server/tools/definitions/biorxiv-list-recent.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-search-preprints.tool.d.ts +24 -7
- package/dist/mcp-server/tools/definitions/biorxiv-search-preprints.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-search-preprints.tool.js +78 -38
- package/dist/mcp-server/tools/definitions/biorxiv-search-preprints.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +47 -19
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
- package/dist/services/biorxiv/biorxiv-service.d.ts +51 -31
- package/dist/services/biorxiv/biorxiv-service.d.ts.map +1 -1
- package/dist/services/biorxiv/biorxiv-service.js +132 -74
- package/dist/services/biorxiv/biorxiv-service.js.map +1 -1
- package/dist/services/biorxiv/types.d.ts +33 -6
- package/dist/services/biorxiv/types.d.ts.map +1 -1
- package/dist/services/biorxiv-fulltext/biorxiv-fulltext-service.d.ts +9 -6
- package/dist/services/biorxiv-fulltext/biorxiv-fulltext-service.d.ts.map +1 -1
- package/dist/services/biorxiv-fulltext/biorxiv-fulltext-service.js +178 -23
- package/dist/services/biorxiv-fulltext/biorxiv-fulltext-service.js.map +1 -1
- package/dist/services/europe-pmc/europe-pmc-service.d.ts +26 -6
- package/dist/services/europe-pmc/europe-pmc-service.d.ts.map +1 -1
- package/dist/services/europe-pmc/europe-pmc-service.js +124 -32
- package/dist/services/europe-pmc/europe-pmc-service.js.map +1 -1
- package/dist/services/shared.d.ts +105 -5
- package/dist/services/shared.d.ts.map +1 -1
- package/dist/services/shared.js +191 -9
- package/dist/services/shared.js.map +1 -1
- package/dist/services/upstream-text-tables.d.ts +11 -1
- package/dist/services/upstream-text-tables.d.ts.map +1 -1
- package/dist/services/upstream-text-tables.js +42 -1
- package/dist/services/upstream-text-tables.js.map +1 -1
- package/package.json +6 -6
- package/server.json +3 -3
|
@@ -5,17 +5,20 @@
|
|
|
5
5
|
* abstracts for records that fall back to EuropePMC metadata: the ranked search
|
|
6
6
|
* uses the `lite` result type, which never carries `abstractText`, so abstracts
|
|
7
7
|
* come from one DOI-keyed `core` query instead. All requests
|
|
8
|
-
* include a polite User-Agent and are retried with exponential backoff
|
|
8
|
+
* include a polite User-Agent and are retried with exponential backoff inside
|
|
9
|
+
* the calling tool's deadline, which bounds every attempt and backoff.
|
|
9
10
|
* Detects HTML error pages, retries an HTTP 200 body that carries no result
|
|
10
11
|
* list, and classifies an origin rate limit (HTTP 429) as its own retryable
|
|
11
12
|
* `rate_limited` condition carrying the parsed `Retry-After` wait — never the
|
|
12
|
-
* upstream response body.
|
|
13
|
+
* upstream response body. A cursor page that fails every attempt the way a
|
|
14
|
+
* malformed `cursorMark` does is told apart from an outage by one request for
|
|
15
|
+
* the same query's first page.
|
|
13
16
|
* @module services/europe-pmc/europe-pmc-service
|
|
14
17
|
*/
|
|
15
18
|
import { McpError, rateLimited, serviceUnavailable, validationError, } from '@cyanheads/mcp-ts-core/errors';
|
|
16
|
-
import { fetchWithTimeout
|
|
19
|
+
import { fetchWithTimeout } from '@cyanheads/mcp-ts-core/utils';
|
|
17
20
|
import { getServerConfig } from '../../config/server-config.js';
|
|
18
|
-
import { describeWait, detectHtmlError, normalizeUpstreamText, parseRetryAfterSeconds, SERVER_VERSION, } from '../shared.js';
|
|
21
|
+
import { describeWait, detectHtmlError, normalizeUpstreamText, parseRetryAfterSeconds, remainingBudgetMs, retryWithinBudget, SERVER_VERSION, } from '../shared.js';
|
|
19
22
|
/**
|
|
20
23
|
* The one status this service classifies itself rather than treating as a bug.
|
|
21
24
|
* Passing it to `fetchWithTimeout` only lowers the log severity from `error` to
|
|
@@ -24,25 +27,62 @@ import { describeWait, detectHtmlError, normalizeUpstreamText, parseRetryAfterSe
|
|
|
24
27
|
const EXPECTED_STATUSES = [429];
|
|
25
28
|
/**
|
|
26
29
|
* `data.reason` on the error thrown for an HTTP 200 body with no `resultList`.
|
|
27
|
-
* EuropePMC answers some requests with only `{"version":"6.9"}
|
|
28
|
-
* for a valid first page or cursor page
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* EuropePMC answers some requests with only `{"version":"6.9"}`, intermittently
|
|
31
|
+
* for a valid first page or cursor page. Read as data, the body becomes a
|
|
32
|
+
* zero-result page, so it is thrown as a transient `ServiceUnavailable` inside
|
|
33
|
+
* `withRetry` instead.
|
|
31
34
|
*/
|
|
32
35
|
const EMPTY_BODY_REASON = 'empty_response_body';
|
|
36
|
+
/**
|
|
37
|
+
* How one failed attempt reads if a malformed `cursorMark` caused it — HTTP 503
|
|
38
|
+
* or the empty body — or `undefined` for a failure no malformed token produces.
|
|
39
|
+
*/
|
|
40
|
+
function tokenFailure(err) {
|
|
41
|
+
if (!(err instanceof McpError))
|
|
42
|
+
return;
|
|
43
|
+
const data = err.data;
|
|
44
|
+
if (data?.reason === EMPTY_BODY_REASON)
|
|
45
|
+
return 'came back with no result list';
|
|
46
|
+
if (data?.status === 503)
|
|
47
|
+
return 'failed with HTTP 503';
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The `invalid_cursor_mark` error a cursor page's failure becomes if the token
|
|
52
|
+
* is to blame, or `undefined` when the failure is not one a malformed token
|
|
53
|
+
* produces. EuropePMC answers a `cursorMark` it does not recognize on every
|
|
54
|
+
* attempt — with its generic outage answer, HTTP 503, and earlier with the
|
|
55
|
+
* empty body — so only a ladder that ran every attempt and failed each one of
|
|
56
|
+
* those two ways qualifies; `answers` holds how they failed, and is `undefined`
|
|
57
|
+
* once any attempt failed some other way. Only the same query's first page
|
|
58
|
+
* answering (see `EuropePmcService.firstPageAnswers`) then settles that the
|
|
59
|
+
* token was at fault. A ladder the budget cut short ends on
|
|
60
|
+
* `retry_deadline_exceeded` and no `status`, so it never qualifies: the
|
|
61
|
+
* attempts that did not run might have answered.
|
|
62
|
+
*
|
|
63
|
+
* The message is written here rather than kept from the exhausted error, whose
|
|
64
|
+
* `(failed after N attempts)` suffix would reach the caller inside the tool's
|
|
65
|
+
* message; the count is in `data.retryAttempts`.
|
|
66
|
+
*/
|
|
67
|
+
function asInvalidCursorMark(err, cursorMark, answers) {
|
|
68
|
+
if (!answers || !tokenFailure(err))
|
|
69
|
+
return;
|
|
70
|
+
const { retryAttempts } = err.data;
|
|
71
|
+
if (typeof retryAttempts !== 'number')
|
|
72
|
+
return;
|
|
73
|
+
return validationError(`EuropePMC did not recognize the supplied cursor_mark — ${retryAttempts} consecutive attempts ${[...answers].join(' or ')}, while the first page of the same query answered.`, { reason: 'invalid_cursor_mark', cursor_mark: cursorMark, retryAttempts }, { cause: err });
|
|
74
|
+
}
|
|
33
75
|
/**
|
|
34
76
|
* Re-throws a failed EuropePMC call with the two conditions this service
|
|
35
77
|
* classifies itself:
|
|
36
78
|
*
|
|
37
|
-
* - an empty body that outlasted every retry
|
|
38
|
-
* page was requested (`invalid_cursor_mark`), an upstream failure on a first
|
|
39
|
-
* page, which has no caller input to blame;
|
|
79
|
+
* - an empty body that outlasted every retry, as an upstream failure;
|
|
40
80
|
* - HTTP 429, as its own retryable `rate_limited` condition.
|
|
41
81
|
*
|
|
42
82
|
* Everything else — 5xx, timeout, network error, the HTML-error guard below —
|
|
43
83
|
* re-throws untouched for the framework's auto-classifier.
|
|
44
84
|
*
|
|
45
|
-
* The empty-body
|
|
85
|
+
* The empty-body error is built fresh rather than re-thrown: `withRetry`
|
|
46
86
|
* suffixes an exhausted error's message with `(failed after N attempts)`, and
|
|
47
87
|
* that wording would otherwise reach the caller inside the tool's message. The
|
|
48
88
|
* attempt count moves to `data.retryAttempts`.
|
|
@@ -54,7 +94,7 @@ const EMPTY_BODY_REASON = 'empty_response_body';
|
|
|
54
94
|
* and fails fast when the requested wait exceeds its cap, so by the time a 429
|
|
55
95
|
* reaches here the waiting is over and only classification is left.
|
|
56
96
|
*/
|
|
57
|
-
function rethrowClassified(err
|
|
97
|
+
function rethrowClassified(err) {
|
|
58
98
|
const data = err instanceof McpError
|
|
59
99
|
? err.data
|
|
60
100
|
: undefined;
|
|
@@ -62,12 +102,9 @@ function rethrowClassified(err, cursorMark) {
|
|
|
62
102
|
// Always set: the empty body is transient, so it only escapes `withRetry`
|
|
63
103
|
// exhausted, and exhaustion is what attaches the count.
|
|
64
104
|
const retryAttempts = data.retryAttempts;
|
|
65
|
-
|
|
66
|
-
if (cursorMark !== '*') {
|
|
67
|
-
throw validationError(`EuropePMC did not recognize the supplied cursor_mark — ${tries} came back with no result list.`, { reason: 'invalid_cursor_mark', cursor_mark: cursorMark, retryAttempts }, { cause: err });
|
|
68
|
-
}
|
|
69
|
-
throw serviceUnavailable(`EuropePMC answered ${tries} with HTTP 200 and no result list.`, { reason: EMPTY_BODY_REASON, retryAttempts }, { cause: err });
|
|
105
|
+
throw serviceUnavailable(`EuropePMC answered ${retryAttempts} consecutive attempts with HTTP 200 and no result list.`, { reason: EMPTY_BODY_REASON, retryAttempts }, { cause: err });
|
|
70
106
|
}
|
|
107
|
+
// A 429 the budget ran out after arrives here in place of the expiry.
|
|
71
108
|
if (data?.status !== 429)
|
|
72
109
|
throw err;
|
|
73
110
|
const retryAfter = parseRetryAfterSeconds(data.retryAfter);
|
|
@@ -100,10 +137,17 @@ export class EuropePmcService {
|
|
|
100
137
|
* firstPublicationDate), which carries no abstract — see `getAbstracts`.
|
|
101
138
|
* Throws a retryable `rate_limited` error when the origin returns HTTP 429.
|
|
102
139
|
* A body with no result list is retried; if every attempt returns one, throws
|
|
103
|
-
* `
|
|
104
|
-
*
|
|
140
|
+
* `ServiceUnavailable` (`empty_response_body`).
|
|
141
|
+
*
|
|
142
|
+
* On a cursor page other than `*`, a ladder that every attempt failed with
|
|
143
|
+
* HTTP 503 or the empty body sends one more request, unretried: the same
|
|
144
|
+
* query's first page. When that answers, throws `ValidationError`
|
|
145
|
+
* (`invalid_cursor_mark`) — four requests plus one; otherwise the ladder's
|
|
146
|
+
* own failure. A deadline that runs out first is a `Timeout` expiry either
|
|
147
|
+
* way: fewer attempts than the full ladder do not establish that the cursor
|
|
148
|
+
* is at fault.
|
|
105
149
|
*/
|
|
106
|
-
async search(options, ctx) {
|
|
150
|
+
async search(options, deadline, ctx) {
|
|
107
151
|
const limit = Math.min(options.limit ?? 25, 100);
|
|
108
152
|
// Base terms: the free-text keyword query and/or an AUTH: author clause.
|
|
109
153
|
// At least one is guaranteed non-empty by the tool's input refinement.
|
|
@@ -147,10 +191,22 @@ export class EuropePmcService {
|
|
|
147
191
|
format: 'json',
|
|
148
192
|
});
|
|
149
193
|
const url = `${this.baseUrl}/search?${params.toString()}&filter=${filterParam}`;
|
|
194
|
+
// How each attempt failed, while every one failed the way a malformed token
|
|
195
|
+
// does; cleared for good by any other failure, so a ladder that merely ended
|
|
196
|
+
// on an HTTP 503 or the empty body is never checked against the first page.
|
|
197
|
+
let tokenAnswers = new Set();
|
|
198
|
+
const observed = (attempt) => (a) => attempt(a).catch((err) => {
|
|
199
|
+
const answer = tokenFailure(err);
|
|
200
|
+
if (answer)
|
|
201
|
+
tokenAnswers?.add(answer);
|
|
202
|
+
else
|
|
203
|
+
tokenAnswers = undefined;
|
|
204
|
+
throw err;
|
|
205
|
+
});
|
|
150
206
|
try {
|
|
151
|
-
return await
|
|
152
|
-
const response = await fetchWithTimeout(url, 20_000, ctx, {
|
|
153
|
-
signal
|
|
207
|
+
return await retryWithinBudget(observed(async ({ signal, remainingMs }) => {
|
|
208
|
+
const response = await fetchWithTimeout(url, Math.min(20_000, remainingMs), ctx, {
|
|
209
|
+
signal,
|
|
154
210
|
headers: { 'User-Agent': this.userAgent },
|
|
155
211
|
expectedStatuses: EXPECTED_STATUSES,
|
|
156
212
|
});
|
|
@@ -183,15 +239,51 @@ export class EuropePmcService {
|
|
|
183
239
|
// callers read "no field" as "no more pages".
|
|
184
240
|
...(data.nextCursorMark && { nextCursorMark: data.nextCursorMark }),
|
|
185
241
|
};
|
|
186
|
-
}, {
|
|
242
|
+
}), {
|
|
187
243
|
operation: 'EuropePmcService.search',
|
|
188
244
|
context: ctx,
|
|
189
245
|
baseDelayMs: 300,
|
|
190
246
|
signal: ctx.signal,
|
|
247
|
+
deadline,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
const invalidCursor = cursorMark === '*' ? undefined : asInvalidCursorMark(err, cursorMark, tokenAnswers);
|
|
252
|
+
if (invalidCursor) {
|
|
253
|
+
params.set('cursorMark', '*');
|
|
254
|
+
params.set('pageSize', '1');
|
|
255
|
+
const firstPageUrl = `${this.baseUrl}/search?${params.toString()}&filter=${filterParam}`;
|
|
256
|
+
if (await this.firstPageAnswers(firstPageUrl, deadline, ctx))
|
|
257
|
+
throw invalidCursor;
|
|
258
|
+
}
|
|
259
|
+
rethrowClassified(err);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Whether EuropePMC answers a first-page search right now: one request, never
|
|
264
|
+
* retried, timed out at 20 s or what is left of the call's budget, and not
|
|
265
|
+
* sent at all once that budget is spent. A miss of any kind — a status, the
|
|
266
|
+
* empty body, a page that is not JSON, a network error, the timeout — is
|
|
267
|
+
* `false`; retrying would only add requests against an origin that may be in
|
|
268
|
+
* outage. A caller cancellation is re-thrown, never read as a miss.
|
|
269
|
+
*/
|
|
270
|
+
async firstPageAnswers(url, deadline, ctx) {
|
|
271
|
+
const budgetMs = remainingBudgetMs(deadline);
|
|
272
|
+
if (budgetMs === 0)
|
|
273
|
+
return false;
|
|
274
|
+
try {
|
|
275
|
+
const response = await fetchWithTimeout(url, Math.min(20_000, budgetMs), ctx, {
|
|
276
|
+
signal: ctx.signal,
|
|
277
|
+
headers: { 'User-Agent': this.userAgent },
|
|
278
|
+
expectedStatuses: EXPECTED_STATUSES,
|
|
191
279
|
});
|
|
280
|
+
const data = JSON.parse(await response.text());
|
|
281
|
+
return data?.resultList != null;
|
|
192
282
|
}
|
|
193
283
|
catch (err) {
|
|
194
|
-
|
|
284
|
+
if (ctx.signal.aborted)
|
|
285
|
+
throw err;
|
|
286
|
+
return false;
|
|
195
287
|
}
|
|
196
288
|
}
|
|
197
289
|
/**
|
|
@@ -203,7 +295,7 @@ export class EuropePmcService {
|
|
|
203
295
|
* absent from the map. Throws on failure — classified like `search`, with an
|
|
204
296
|
* HTTP 429 as a retryable `rate_limited` error carrying `Retry-After`.
|
|
205
297
|
*/
|
|
206
|
-
async getAbstracts(dois, ctx) {
|
|
298
|
+
async getAbstracts(dois, deadline, ctx) {
|
|
207
299
|
const unique = [...new Set(dois.map((doi) => doi.toLowerCase()))];
|
|
208
300
|
// Quotes are stripped so a stray one cannot end the DOI phrase early.
|
|
209
301
|
const clause = unique.map((doi) => `DOI:"${doi.replace(/"/g, '')}"`).join(' OR ');
|
|
@@ -216,9 +308,9 @@ export class EuropePmcService {
|
|
|
216
308
|
});
|
|
217
309
|
const url = `${this.baseUrl}/search?${params.toString()}`;
|
|
218
310
|
try {
|
|
219
|
-
return await
|
|
220
|
-
const response = await fetchWithTimeout(url, 20_000, ctx, {
|
|
221
|
-
signal
|
|
311
|
+
return await retryWithinBudget(async ({ signal, remainingMs }) => {
|
|
312
|
+
const response = await fetchWithTimeout(url, Math.min(20_000, remainingMs), ctx, {
|
|
313
|
+
signal,
|
|
222
314
|
headers: { 'User-Agent': this.userAgent },
|
|
223
315
|
expectedStatuses: EXPECTED_STATUSES,
|
|
224
316
|
});
|
|
@@ -245,11 +337,11 @@ export class EuropePmcService {
|
|
|
245
337
|
context: ctx,
|
|
246
338
|
baseDelayMs: 300,
|
|
247
339
|
signal: ctx.signal,
|
|
340
|
+
deadline,
|
|
248
341
|
});
|
|
249
342
|
}
|
|
250
343
|
catch (err) {
|
|
251
|
-
|
|
252
|
-
rethrowClassified(err, '*');
|
|
344
|
+
rethrowClassified(err);
|
|
253
345
|
}
|
|
254
346
|
}
|
|
255
347
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"europe-pmc-service.js","sourceRoot":"","sources":["../../../src/services/europe-pmc/europe-pmc-service.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"europe-pmc-service.js","sourceRoot":"","sources":["../../../src/services/europe-pmc/europe-pmc-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EACL,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,eAAe,GAChB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAqB,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAEL,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAO9B;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,GAAG,CAAC,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAEhD;;;GAGG;AACH,SAAS,YAAY,CAAC,GAAY;IAChC,IAAI,CAAC,CAAC,GAAG,YAAY,QAAQ,CAAC;QAAE,OAAO;IACvC,MAAM,IAAI,GAAG,GAAG,CAAC,IAA0D,CAAC;IAC5E,IAAI,IAAI,EAAE,MAAM,KAAK,iBAAiB;QAAE,OAAO,+BAA+B,CAAC;IAC/E,IAAI,IAAI,EAAE,MAAM,KAAK,GAAG;QAAE,OAAO,sBAAsB,CAAC;IACxD,OAAO;AACT,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,mBAAmB,CAC1B,GAAY,EACZ,UAAkB,EAClB,OAAwC;IAExC,IAAI,CAAC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;QAAE,OAAO;IAC3C,MAAM,EAAE,aAAa,EAAE,GAAI,GAAgB,CAAC,IAAmC,CAAC;IAChF,IAAI,OAAO,aAAa,KAAK,QAAQ;QAAE,O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UAAU,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;oBAC/C,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC;oBACnC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;oBACzD,IAAI,GAAG,IAAI,QAAQ,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;wBAAE,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;gBAC3E,CAAC;gBACD,OAAO,SAAS,CAAC;YACnB,CAAC,EACD;gBACE,SAAS,EAAE,+BAA+B;gBAC1C,OAAO,EAAE,GAAG;gBACZ,WAAW,EAAE,GAAG;gBAChB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,QAAQ;aACT,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,iBAAiB,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAED,gFAAgF;AAEhF,IAAI,QAAsC,CAAC;AAE3C,MAAM,UAAU,oBAAoB,CAAC,MAAiB,EAAE,OAAuB;IAC7E,QAAQ,GAAG,IAAI,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,IAAI,CAAC,QAAQ;QACX,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;IAC/F,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
* HTML error detection, DOI and ROR ID input normalization, calendar-date and
|
|
4
4
|
* upstream-text normalization, the Markdown escaper every `format()` applies
|
|
5
5
|
* to upstream text, `Retry-After` parsing and rate-limit rejection lookup
|
|
6
|
-
* shared by every fetch path,
|
|
7
|
-
*
|
|
6
|
+
* shared by every fetch path, the per-tool-call time budget every upstream
|
|
7
|
+
* request draws on (with the retry ladder that runs inside it and keeps an
|
|
8
|
+
* origin's 429 as its answer when the budget runs out), the per-server DOI fan-out that settles on the server holding the DOI, and the
|
|
9
|
+
* server version string used in User-Agent headers across all services.
|
|
8
10
|
* @module services/shared
|
|
9
11
|
*/
|
|
12
|
+
import { type RetryAttempt, type RetryOptions } from '@cyanheads/mcp-ts-core/utils';
|
|
10
13
|
/** Detect HTML error pages returned instead of JSON by upstream APIs. */
|
|
11
14
|
export declare function detectHtmlError(text: string): boolean;
|
|
12
15
|
/**
|
|
@@ -21,6 +24,14 @@ export declare function detectHtmlError(text: string): boolean;
|
|
|
21
24
|
* without a prior regex gate.
|
|
22
25
|
*/
|
|
23
26
|
export declare function isValidCalendarDate(dateStr: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The DOI prefixes bioRxiv and medRxiv issue preprint DOIs under — both servers
|
|
29
|
+
* share both, so a prefix never names the server. Cold Spring Harbor
|
|
30
|
+
* Laboratory Press also registers its journal articles under `10.1101/`
|
|
31
|
+
* (`10.1101/gr.…`, `gad.…`, `lm.…`), so a DOI here is a preprint DOI or one of
|
|
32
|
+
* those; any other DOI is a journal article's.
|
|
33
|
+
*/
|
|
34
|
+
export declare const BIORXIV_DOI_PREFIXES: readonly ['10.1101/', '10.64898/'];
|
|
24
35
|
/** A preprint DOI reduced to its bare form, plus the revision a version suffix named. */
|
|
25
36
|
export interface NormalizedDoi {
|
|
26
37
|
/** Bare DOI, e.g. `10.64898/2026.03.11.711201`. */
|
|
@@ -29,7 +40,7 @@ export interface NormalizedDoi {
|
|
|
29
40
|
version?: string;
|
|
30
41
|
}
|
|
31
42
|
/**
|
|
32
|
-
* Reduce a pasted preprint reference to its bare DOI. Accepts the bare DOI
|
|
43
|
+
* Reduce a pasted preprint or journal reference to its bare DOI. Accepts the bare DOI
|
|
33
44
|
* itself, a `https://doi.org/` or `http(s)://dx.doi.org/` resolver URL, a
|
|
34
45
|
* `doi:` label, or a `{www.}{biorxiv,medrxiv}.org/content/` article URL — any
|
|
35
46
|
* of them with a trailing `vN` revision and an article-tab suffix (`.full`,
|
|
@@ -38,8 +49,13 @@ export interface NormalizedDoi {
|
|
|
38
49
|
* suffix named alongside the DOI, and `undefined` when what is left is not a
|
|
39
50
|
* DOI — callers raise their `invalid_doi_format` on that.
|
|
40
51
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
52
|
+
* On a DOI under {@link BIORXIV_DOI_PREFIXES}, any article-tab suffix is
|
|
53
|
+
* stripped, only ever as text around the bioRxiv/medRxiv identifier, never
|
|
54
|
+
* characters of one. Any other DOI is a journal's, whose own trailing
|
|
55
|
+
* components (`10.7554/eLife.55185.sa1`, `….pone.0123456.g001`, Wiley's `.x`)
|
|
56
|
+
* name a different record than the DOI without them, so only the page-format
|
|
57
|
+
* tabs (`.pdf`, `.full`, `.full.pdf`, `.full-text`, …) and a `vN` revision
|
|
58
|
+
* after a digit are stripped from it, never one of its own components.
|
|
43
59
|
*/
|
|
44
60
|
export declare function normalizeDoi(input: string): NormalizedDoi | undefined;
|
|
45
61
|
/**
|
|
@@ -56,6 +72,13 @@ export declare function normalizeRorId(input: string): string | undefined;
|
|
|
56
72
|
* into raw title and abstract text, so no upstream markup reaches
|
|
57
73
|
* `structuredContent` or the rendered `content[]`. Handles:
|
|
58
74
|
*
|
|
75
|
+
* - the two backslash escapes bioRxiv abstracts posted before December 2019
|
|
76
|
+
* carry: a literal backslash-`n` (single, paired, or longer runs) read as a
|
|
77
|
+
* real line break, and a literal backslash-`"` read as `"` — first, so the
|
|
78
|
+
* heading and list handling below sees the breaks. Only in text with no real
|
|
79
|
+
* line break, the one form those abstracts use, and never where the
|
|
80
|
+
* backslash follows another backslash or a backslash-`n` opens a TeX
|
|
81
|
+
* control word (`\nabla`, `\neq`);
|
|
59
82
|
* - whole blocks removed with everything inside: figures (`O_FIG … C_FIG`),
|
|
60
83
|
* display figures (`O_FIG_DISPLAY_L … C_FIG_DISPLAY`), and tables
|
|
61
84
|
* (`O_TBL … C_TBL`, caption included) — image refs, `SRC=` paths,
|
|
@@ -146,6 +169,83 @@ export declare function findRateLimit(errors: readonly unknown[]): {
|
|
|
146
169
|
* named no usable wait.
|
|
147
170
|
*/
|
|
148
171
|
export declare function describeWait(seconds: number | undefined): string;
|
|
172
|
+
/**
|
|
173
|
+
* A not-found recovery hint for a lookup across `servers`. A call that checked
|
|
174
|
+
* one server only is first sent to the other, since bioRxiv and medRxiv share
|
|
175
|
+
* their DOI prefixes; a call that checked both gets `hint` alone.
|
|
176
|
+
*/
|
|
177
|
+
export declare function notFoundHint(servers: readonly string[], hint: string): string;
|
|
178
|
+
/**
|
|
179
|
+
* Wall-clock budget for one tool call: every upstream request the call makes,
|
|
180
|
+
* with each request's attempts, backoffs, and honored `Retry-After` waits. Kept
|
|
181
|
+
* under the 60-second request timeout MCP SDK clients default to, so a hung
|
|
182
|
+
* origin surfaces as this server's classified error — or as the degraded result
|
|
183
|
+
* a tool already returns for an optional step — before the client gives up.
|
|
184
|
+
*/
|
|
185
|
+
export declare const CALL_BUDGET_MS = 50000;
|
|
186
|
+
/**
|
|
187
|
+
* The instant, in epoch milliseconds, one tool call's {@link CALL_BUDGET_MS}
|
|
188
|
+
* runs out. A handler starts it once with {@link startCallDeadline} and passes
|
|
189
|
+
* the same value to every service call, so requests chained one after another
|
|
190
|
+
* share one budget instead of each starting its own.
|
|
191
|
+
*/
|
|
192
|
+
export type CallDeadline = number & {
|
|
193
|
+
readonly __brand: 'CallDeadline';
|
|
194
|
+
};
|
|
195
|
+
/** Starts a tool call's budget. Call once per tool call, before its first upstream request. */
|
|
196
|
+
export declare function startCallDeadline(): CallDeadline;
|
|
197
|
+
/**
|
|
198
|
+
* What is left of a call's budget, in milliseconds — 0 once it has run out.
|
|
199
|
+
* Every retry ladder's `deadlineMs` is drawn from it ({@link ladderBudgetMs}).
|
|
200
|
+
*/
|
|
201
|
+
export declare function remainingBudgetMs(deadline: CallDeadline): number;
|
|
202
|
+
/**
|
|
203
|
+
* `withRetry`'s `deadlineMs` for a ladder about to start: what is left of the
|
|
204
|
+
* call's budget. A budget already spent fails here, before any request, as the
|
|
205
|
+
* call running out of time — a ladder started with nothing left would report
|
|
206
|
+
* exceeding a "0ms retry deadline", which tells a caller nothing.
|
|
207
|
+
*/
|
|
208
|
+
export declare function ladderBudgetMs(deadline: CallDeadline, operation: string): number;
|
|
209
|
+
/**
|
|
210
|
+
* Runs one retry ladder on what is left of a call's budget: `withRetry` with
|
|
211
|
+
* {@link ladderBudgetMs} as its `deadlineMs`, so a spent budget fails before
|
|
212
|
+
* any request. The ladder remembers the last HTTP 429 an attempt received.
|
|
213
|
+
* When the budget then runs out — in the backoff after it, or by cutting a
|
|
214
|
+
* later attempt short — `withRetry` rejects with a `Timeout`
|
|
215
|
+
* (`reason: 'retry_deadline_exceeded'`) whose `cause` is only the last
|
|
216
|
+
* attempt; the ladder rejects with the 429 instead, `Retry-After` and all,
|
|
217
|
+
* since it is still the origin's answer and the one the services classify.
|
|
218
|
+
* Every other failure is rejected as `withRetry` threw it.
|
|
219
|
+
*/
|
|
220
|
+
export declare function retryWithinBudget<T>(attempt: (attempt: RetryAttempt) => Promise<T>, options: Omit<RetryOptions, 'deadlineMs' | 'operation'> & {
|
|
221
|
+
deadline: CallDeadline;
|
|
222
|
+
operation: string;
|
|
223
|
+
}): Promise<T>;
|
|
224
|
+
/**
|
|
225
|
+
* One leg of a per-server fan-out as it stood when {@link firstHit} settled:
|
|
226
|
+
* its settled result, or `undefined` for a leg still running then — aborted,
|
|
227
|
+
* and never read as a failure.
|
|
228
|
+
*/
|
|
229
|
+
export type LegOutcome<T> = PromiseSettledResult<T> | undefined;
|
|
230
|
+
/**
|
|
231
|
+
* Runs one DOI lookup per server and settles on the first leg whose answer
|
|
232
|
+
* `isHit` accepts, or once every leg has settled. A DOI lives on one server, so
|
|
233
|
+
* once a leg holds it no other leg's answer can change the result: the legs
|
|
234
|
+
* still running are aborted rather than awaited, so a stalled server that does
|
|
235
|
+
* not hold the DOI never spends the call's budget. Each leg runs on its own
|
|
236
|
+
* signal combined with `callerSignal`, so a caller cancellation still stops
|
|
237
|
+
* every leg; check the caller's signal afterwards, as after any fan-out.
|
|
238
|
+
*
|
|
239
|
+
* Returns the hit, if any, and each leg's outcome at that moment, in leg order.
|
|
240
|
+
* Without a hit every leg had settled, so no outcome is `undefined`.
|
|
241
|
+
*/
|
|
242
|
+
export declare function firstHit<T>(legs: readonly ((signal: AbortSignal) => Promise<T>)[], isHit: (value: T) => boolean, callerSignal: AbortSignal): Promise<{
|
|
243
|
+
hit: {
|
|
244
|
+
leg: number;
|
|
245
|
+
value: T;
|
|
246
|
+
} | undefined;
|
|
247
|
+
outcomes: LegOutcome<T>[];
|
|
248
|
+
}>;
|
|
149
249
|
/**
|
|
150
250
|
* Version string used in outbound User-Agent headers. Derived from package.json
|
|
151
251
|
* (the single source of truth) so it can never drift from the released version.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/services/shared.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/services/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAa,MAAM,8BAA8B,CAAC;AAU/F,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAU5D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,YAAI,UAAU,EAAE,WAAW,CAAU,CAAC;AAEvE,yFAAyF;AACzF,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,6FAA6F;IAC7F,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA2CD;;;;;;;;;;;;;;;;;GAiBG;AAC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