@cyanheads/biorxiv-mcp-server 0.2.2 → 0.2.4
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 +7 -2
- package/CLAUDE.md +7 -2
- package/README.md +12 -7
- package/changelog/0.2.x/0.2.3.md +26 -0
- package/changelog/0.2.x/0.2.4.md +17 -0
- package/dist/mcp-server/tools/definitions/biorxiv-get-fulltext.tool.d.ts +13 -2
- 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 +45 -5
- 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 +11 -0
- 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 +50 -13
- 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 +10 -1
- 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 +26 -1
- package/dist/mcp-server/tools/definitions/biorxiv-get-published-version.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/biorxiv-list-recent.tool.d.ts +16 -0
- 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 +54 -12
- 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 +23 -0
- 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 +85 -19
- package/dist/mcp-server/tools/definitions/biorxiv-search-preprints.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/index.d.ts +39 -2
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -1
- package/dist/services/biorxiv/biorxiv-service.d.ts +7 -1
- package/dist/services/biorxiv/biorxiv-service.d.ts.map +1 -1
- package/dist/services/biorxiv/biorxiv-service.js +148 -92
- package/dist/services/biorxiv/biorxiv-service.js.map +1 -1
- package/dist/services/biorxiv-fulltext/biorxiv-fulltext-service.d.ts.map +1 -1
- package/dist/services/biorxiv-fulltext/biorxiv-fulltext-service.js +1 -19
- package/dist/services/biorxiv-fulltext/biorxiv-fulltext-service.js.map +1 -1
- package/dist/services/europe-pmc/europe-pmc-service.d.ts +4 -0
- package/dist/services/europe-pmc/europe-pmc-service.d.ts.map +1 -1
- package/dist/services/europe-pmc/europe-pmc-service.js +83 -35
- package/dist/services/europe-pmc/europe-pmc-service.js.map +1 -1
- package/dist/services/shared.d.ts +35 -2
- package/dist/services/shared.d.ts.map +1 -1
- package/dist/services/shared.js +64 -2
- package/dist/services/shared.js.map +1 -1
- package/package.json +1 -1
- package/server.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"biorxiv-fulltext-service.js","sourceRoot":"","sources":["../../../src/services/biorxiv-fulltext/biorxiv-fulltext-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"biorxiv-fulltext-service.js","sourceRoot":"","sources":["../../../src/services/biorxiv-fulltext/biorxiv-fulltext-service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ClF,SAAS;SACV,CAAC;QACF,0EAA0E;QAC1E,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,kBAAkB,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC;IACzC,CAAC;CACF;AAED,gFAAgF;AAEhF,IAAI,QAA4C,CAAC;AAEjD,MAAM,UAAU,0BAA0B,CAAC,MAAiB,EAAE,OAAuB;IACnF,QAAQ,GAAG,IAAI,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,yBAAyB;IACvC,IAAI,CAAC,QAAQ;QACX,MAAM,IAAI,KAAK,CACb,uFAAuF,CACxF,CAAC;IACJ,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* for preprint keyword search. Returns ranked DOI lists used by
|
|
4
4
|
* biorxiv_search_preprints for bioRxiv/medRxiv enrichment. All requests
|
|
5
5
|
* include a polite User-Agent and are retried with exponential backoff.
|
|
6
|
+
* Detects HTML error pages, and classifies an origin rate limit (HTTP 429) as
|
|
7
|
+
* its own retryable `rate_limited` condition carrying the parsed `Retry-After`
|
|
8
|
+
* wait — never the upstream response body.
|
|
6
9
|
* @module services/europe-pmc/europe-pmc-service
|
|
7
10
|
*/
|
|
8
11
|
import type { Context } from '@cyanheads/mcp-ts-core';
|
|
@@ -34,6 +37,7 @@ export declare class EuropePmcService {
|
|
|
34
37
|
* with DOIs plus the upstream hitCount grand total, used to drive bioRxiv API
|
|
35
38
|
* enrichment. Requests the minimal field set (doi, title, authorString,
|
|
36
39
|
* firstPublicationDate, abstractText).
|
|
40
|
+
* Throws a retryable `rate_limited` error when the origin returns HTTP 429.
|
|
37
41
|
*/
|
|
38
42
|
search(options: SearchOptions, ctx: Context): Promise<EuropePmcSearchResult>;
|
|
39
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"europe-pmc-service.d.ts","sourceRoot":"","sources":["../../../src/services/europe-pmc/europe-pmc-service.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"europe-pmc-service.d.ts","sourceRoot":"","sources":["../../../src/services/europe-pmc/europe-pmc-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAWrE,OAAO,KAAK,EAEV,qBAAqB,EAEtB,MAAM,YAAY,CAAC;AA+CpB,MAAM,WAAW,aAAa;IAC5B,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,oDAAoD;IACpD,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,YAAY,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAMvD;IAED;;;;;;OAMG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA6FjF;CACF;AAMD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAErF;AAED,wBAAgB,mBAAmB,IAAI,gBAAgB,CAItD"}
|
|
@@ -3,12 +3,53 @@
|
|
|
3
3
|
* for preprint keyword search. Returns ranked DOI lists used by
|
|
4
4
|
* biorxiv_search_preprints for bioRxiv/medRxiv enrichment. All requests
|
|
5
5
|
* include a polite User-Agent and are retried with exponential backoff.
|
|
6
|
+
* Detects HTML error pages, and classifies an origin rate limit (HTTP 429) as
|
|
7
|
+
* its own retryable `rate_limited` condition carrying the parsed `Retry-After`
|
|
8
|
+
* wait — never the upstream response body.
|
|
6
9
|
* @module services/europe-pmc/europe-pmc-service
|
|
7
10
|
*/
|
|
8
|
-
import { serviceUnavailable } from '@cyanheads/mcp-ts-core/errors';
|
|
11
|
+
import { McpError, rateLimited, serviceUnavailable } from '@cyanheads/mcp-ts-core/errors';
|
|
9
12
|
import { fetchWithTimeout, withRetry } from '@cyanheads/mcp-ts-core/utils';
|
|
10
13
|
import { getServerConfig } from '../../config/server-config.js';
|
|
11
|
-
import { asRc, detectHtmlError, normalizeUpstreamText, SERVER_VERSION } from '../../services/shared.js';
|
|
14
|
+
import { asRc, describeWait, detectHtmlError, normalizeUpstreamText, parseRetryAfterSeconds, SERVER_VERSION, } from '../../services/shared.js';
|
|
15
|
+
/**
|
|
16
|
+
* The one status this service classifies itself rather than treating as a bug.
|
|
17
|
+
* Passing it to `fetchWithTimeout` only lowers the log severity from `error` to
|
|
18
|
+
* `debug`; the thrown error and its classification are unchanged.
|
|
19
|
+
*/
|
|
20
|
+
const EXPECTED_STATUSES = [429];
|
|
21
|
+
/**
|
|
22
|
+
* Re-throws a failed EuropePMC call, classifying HTTP 429 as its own retryable
|
|
23
|
+
* `rate_limited` condition. Everything else — 5xx, timeout, network error, the
|
|
24
|
+
* HTML-error guard below — re-throws untouched for the framework's
|
|
25
|
+
* auto-classifier.
|
|
26
|
+
*
|
|
27
|
+
* `fetchWithTimeout` attaches the upstream response body to `err.data`
|
|
28
|
+
* (`body`/`responseBody`), so the replacement payload is built from scratch
|
|
29
|
+
* rather than spread: only the parsed `Retry-After` crosses into it. Retry is
|
|
30
|
+
* not this function's concern — `withRetry` already honors `data.retryAfter`
|
|
31
|
+
* and fails fast when the requested wait exceeds its cap, so by the time a 429
|
|
32
|
+
* reaches here the waiting is over and only classification is left.
|
|
33
|
+
*/
|
|
34
|
+
function rethrowClassified(err) {
|
|
35
|
+
const data = err instanceof McpError
|
|
36
|
+
? err.data
|
|
37
|
+
: undefined;
|
|
38
|
+
if (data?.status !== 429)
|
|
39
|
+
throw err;
|
|
40
|
+
const retryAfter = parseRetryAfterSeconds(data.retryAfter);
|
|
41
|
+
const wait = describeWait(retryAfter);
|
|
42
|
+
throw rateLimited(retryAfter === undefined
|
|
43
|
+
? 'EuropePMC is rate-limiting this host (HTTP 429).'
|
|
44
|
+
: `EuropePMC is rate-limiting this host (HTTP 429) and asked for a ${retryAfter}-second wait before the next request.`, {
|
|
45
|
+
reason: 'rate_limited',
|
|
46
|
+
retryable: true,
|
|
47
|
+
...(retryAfter !== undefined && { retryAfter }),
|
|
48
|
+
recovery: {
|
|
49
|
+
hint: `Wait ${wait} before querying EuropePMC again — only keyword search reaches this origin, so preprint metadata lookups on api.biorxiv.org are outside this limit.`,
|
|
50
|
+
},
|
|
51
|
+
}, { cause: err });
|
|
52
|
+
}
|
|
12
53
|
export class EuropePmcService {
|
|
13
54
|
baseUrl;
|
|
14
55
|
userAgent;
|
|
@@ -24,6 +65,7 @@ export class EuropePmcService {
|
|
|
24
65
|
* with DOIs plus the upstream hitCount grand total, used to drive bioRxiv API
|
|
25
66
|
* enrichment. Requests the minimal field set (doi, title, authorString,
|
|
26
67
|
* firstPublicationDate, abstractText).
|
|
68
|
+
* Throws a retryable `rate_limited` error when the origin returns HTTP 429.
|
|
27
69
|
*/
|
|
28
70
|
async search(options, ctx) {
|
|
29
71
|
const limit = Math.min(options.limit ?? 25, 100);
|
|
@@ -68,42 +110,48 @@ export class EuropePmcService {
|
|
|
68
110
|
});
|
|
69
111
|
const url = `${this.baseUrl}/search?${params.toString()}&filter=${filterParam}`;
|
|
70
112
|
const rc = asRc(ctx);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
113
|
+
try {
|
|
114
|
+
return await withRetry(async () => {
|
|
115
|
+
const response = await fetchWithTimeout(url, 20_000, rc, {
|
|
116
|
+
signal: ctx.signal,
|
|
117
|
+
headers: { 'User-Agent': this.userAgent },
|
|
118
|
+
expectedStatuses: EXPECTED_STATUSES,
|
|
119
|
+
});
|
|
120
|
+
const text = await response.text();
|
|
121
|
+
if (detectHtmlError(text)) {
|
|
122
|
+
throw serviceUnavailable('EuropePMC returned HTML instead of JSON — service may be degraded.', { url });
|
|
123
|
+
}
|
|
124
|
+
const data = JSON.parse(text);
|
|
125
|
+
const results = (data.resultList?.result ?? [])
|
|
126
|
+
.filter((raw) => raw.doi != null)
|
|
127
|
+
.map((raw) => {
|
|
128
|
+
const title = normalizeUpstreamText(raw.title);
|
|
129
|
+
const abstract = normalizeUpstreamText(raw.abstractText);
|
|
130
|
+
return {
|
|
131
|
+
doi: raw.doi,
|
|
132
|
+
...(title && { title }),
|
|
133
|
+
...(raw.authorString && { authors: raw.authorString }),
|
|
134
|
+
...(raw.firstPublicationDate && { publishedDate: raw.firstPublicationDate }),
|
|
135
|
+
...(abstract && { abstract }),
|
|
136
|
+
};
|
|
137
|
+
});
|
|
86
138
|
return {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
...(
|
|
139
|
+
hitCount: data.hitCount ?? results.length,
|
|
140
|
+
results,
|
|
141
|
+
// Absent on the last page (EuropePMC omits it) — omit here too so
|
|
142
|
+
// callers read "no field" as "no more pages".
|
|
143
|
+
...(data.nextCursorMark && { nextCursorMark: data.nextCursorMark }),
|
|
92
144
|
};
|
|
145
|
+
}, {
|
|
146
|
+
operation: 'EuropePmcService.search',
|
|
147
|
+
context: rc,
|
|
148
|
+
baseDelayMs: 300,
|
|
149
|
+
signal: ctx.signal,
|
|
93
150
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// callers read "no field" as "no more pages".
|
|
99
|
-
...(data.nextCursorMark && { nextCursorMark: data.nextCursorMark }),
|
|
100
|
-
};
|
|
101
|
-
}, {
|
|
102
|
-
operation: 'EuropePmcService.search',
|
|
103
|
-
context: rc,
|
|
104
|
-
baseDelayMs: 300,
|
|
105
|
-
signal: ctx.signal,
|
|
106
|
-
});
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
rethrowClassified(err);
|
|
154
|
+
}
|
|
107
155
|
}
|
|
108
156
|
}
|
|
109
157
|
// ─── Init / accessor ─────────────────────────────────────────────────────────
|
|
@@ -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;;;;;;;;;GASG;AAIH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAE1F,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,IAAI,EACJ,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,GACf,MAA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QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Shared utilities for biorxiv-mcp-server service layer. Provides
|
|
3
|
-
* the Context→RequestContext cast, HTML error detection, and
|
|
4
|
-
*
|
|
3
|
+
* the Context→RequestContext cast, HTML error detection, calendar-date and
|
|
4
|
+
* upstream-text normalization, `Retry-After` parsing and rate-limit rejection
|
|
5
|
+
* lookup shared by every fetch path, and the server version string used in
|
|
6
|
+
* User-Agent headers across all services.
|
|
5
7
|
* @module services/shared
|
|
6
8
|
*/
|
|
7
9
|
import type { Context } from '@cyanheads/mcp-ts-core';
|
|
@@ -45,6 +47,37 @@ export declare function isValidCalendarDate(dateStr: string): boolean;
|
|
|
45
47
|
* fields as absent rather than as empty strings.
|
|
46
48
|
*/
|
|
47
49
|
export declare function normalizeUpstreamText(text: string | undefined): string | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Reads a `Retry-After` header value as a wait in whole seconds. RFC 9110 §10.2.3
|
|
52
|
+
* allows either delta-seconds or an HTTP-date; the date form is converted to a
|
|
53
|
+
* wait from now and clamped at zero. Returns undefined for an absent, malformed,
|
|
54
|
+
* or unparseable value so callers fall back to generic wording rather than
|
|
55
|
+
* echoing an uninterpretable header into agent-facing prose.
|
|
56
|
+
*
|
|
57
|
+
* Shared by every fetch path — the JSON API, the full-text article origin, and
|
|
58
|
+
* EuropePMC each surface the same header and must read it identically.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseRetryAfterSeconds(raw: unknown): number | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Finds an origin rate limit among a set of rejections, recognising the
|
|
63
|
+
* `reason: 'rate_limited'` marker this server's services attach when they
|
|
64
|
+
* classify an HTTP 429. Returns the wait the caller should honor — the longest
|
|
65
|
+
* of the reported ones, since a shorter wait would still land inside whichever
|
|
66
|
+
* origin asked for the longer one — or an empty object when a rate limit fired
|
|
67
|
+
* without a usable `Retry-After`. Returns undefined when no rejection was a
|
|
68
|
+
* rate limit, so callers fall through to their generic upstream-failure
|
|
69
|
+
* contract entry.
|
|
70
|
+
*/
|
|
71
|
+
export declare function findRateLimit(errors: readonly unknown[]): {
|
|
72
|
+
retryAfter?: number;
|
|
73
|
+
} | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Renders a `Retry-After` wait as the phrase every rate-limit recovery hint
|
|
76
|
+
* interpolates, so the wording an agent reads is identical whichever origin or
|
|
77
|
+
* tool produced the limit — including the fallback for a 429 whose response
|
|
78
|
+
* named no usable wait.
|
|
79
|
+
*/
|
|
80
|
+
export declare function describeWait(seconds: number | undefined): string;
|
|
48
81
|
/**
|
|
49
82
|
* Version string used in outbound User-Agent headers. Derived from package.json
|
|
50
83
|
* (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;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAGnE;;;GAGG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAEjD;AAED,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAU5D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAuBlF;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOvE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAiB7F;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAEhE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,EAAE,MAA4B,CAAC"}
|
package/dist/services/shared.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Shared utilities for biorxiv-mcp-server service layer. Provides
|
|
3
|
-
* the Context→RequestContext cast, HTML error detection, and
|
|
4
|
-
*
|
|
3
|
+
* the Context→RequestContext cast, HTML error detection, calendar-date and
|
|
4
|
+
* upstream-text normalization, `Retry-After` parsing and rate-limit rejection
|
|
5
|
+
* lookup shared by every fetch path, and the server version string used in
|
|
6
|
+
* User-Agent headers across all services.
|
|
5
7
|
* @module services/shared
|
|
6
8
|
*/
|
|
9
|
+
import { McpError } from '@cyanheads/mcp-ts-core/errors';
|
|
7
10
|
import packageJson from '../../package.json' with { type: 'json' };
|
|
8
11
|
/**
|
|
9
12
|
* Cast Context to RequestContext for fetchWithTimeout / withRetry.
|
|
@@ -81,6 +84,65 @@ export function normalizeUpstreamText(text) {
|
|
|
81
84
|
.trim();
|
|
82
85
|
return cleaned || undefined;
|
|
83
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Reads a `Retry-After` header value as a wait in whole seconds. RFC 9110 §10.2.3
|
|
89
|
+
* allows either delta-seconds or an HTTP-date; the date form is converted to a
|
|
90
|
+
* wait from now and clamped at zero. Returns undefined for an absent, malformed,
|
|
91
|
+
* or unparseable value so callers fall back to generic wording rather than
|
|
92
|
+
* echoing an uninterpretable header into agent-facing prose.
|
|
93
|
+
*
|
|
94
|
+
* Shared by every fetch path — the JSON API, the full-text article origin, and
|
|
95
|
+
* EuropePMC each surface the same header and must read it identically.
|
|
96
|
+
*/
|
|
97
|
+
export function parseRetryAfterSeconds(raw) {
|
|
98
|
+
if (typeof raw !== 'string')
|
|
99
|
+
return;
|
|
100
|
+
const trimmed = raw.trim();
|
|
101
|
+
if (/^\d+$/.test(trimmed))
|
|
102
|
+
return Number(trimmed);
|
|
103
|
+
const dateMs = Date.parse(trimmed);
|
|
104
|
+
if (Number.isNaN(dateMs))
|
|
105
|
+
return;
|
|
106
|
+
return Math.max(0, Math.round((dateMs - Date.now()) / 1000));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Finds an origin rate limit among a set of rejections, recognising the
|
|
110
|
+
* `reason: 'rate_limited'` marker this server's services attach when they
|
|
111
|
+
* classify an HTTP 429. Returns the wait the caller should honor — the longest
|
|
112
|
+
* of the reported ones, since a shorter wait would still land inside whichever
|
|
113
|
+
* origin asked for the longer one — or an empty object when a rate limit fired
|
|
114
|
+
* without a usable `Retry-After`. Returns undefined when no rejection was a
|
|
115
|
+
* rate limit, so callers fall through to their generic upstream-failure
|
|
116
|
+
* contract entry.
|
|
117
|
+
*/
|
|
118
|
+
export function findRateLimit(errors) {
|
|
119
|
+
let found = false;
|
|
120
|
+
let longest;
|
|
121
|
+
for (const err of errors) {
|
|
122
|
+
if (!(err instanceof McpError))
|
|
123
|
+
continue;
|
|
124
|
+
const data = err.data;
|
|
125
|
+
if (data?.reason !== 'rate_limited')
|
|
126
|
+
continue;
|
|
127
|
+
found = true;
|
|
128
|
+
if (typeof data.retryAfter === 'number' &&
|
|
129
|
+
(longest === undefined || data.retryAfter > longest)) {
|
|
130
|
+
longest = data.retryAfter;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!found)
|
|
134
|
+
return;
|
|
135
|
+
return longest === undefined ? {} : { retryAfter: longest };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Renders a `Retry-After` wait as the phrase every rate-limit recovery hint
|
|
139
|
+
* interpolates, so the wording an agent reads is identical whichever origin or
|
|
140
|
+
* tool produced the limit — including the fallback for a 429 whose response
|
|
141
|
+
* named no usable wait.
|
|
142
|
+
*/
|
|
143
|
+
export function describeWait(seconds) {
|
|
144
|
+
return seconds === undefined ? 'a minute or two' : `${seconds} seconds`;
|
|
145
|
+
}
|
|
84
146
|
/**
|
|
85
147
|
* Version string used in outbound User-Agent headers. Derived from package.json
|
|
86
148
|
* (the single source of truth) so it can never drift from the released version.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/services/shared.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/services/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAEzD,OAAO,WAAW,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAEnE;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAC,GAAY;IAC/B,OAAO,GAAgC,CAAC;AAC1C,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,mCAAmC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,MAAM,KAAK,GAAG,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAA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AAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAW,WAAW,CAAC,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyanheads/biorxiv-mcp-server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"mcpName": "io.github.cyanheads/biorxiv-mcp-server",
|
|
5
5
|
"description": "Search and retrieve bioRxiv and medRxiv preprints — by DOI, date interval, or keyword — via MCP. STDIO or Streamable HTTP.",
|
|
6
6
|
"type": "module",
|
package/server.json
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
"url": "https://github.com/cyanheads/biorxiv-mcp-server",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.4",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
14
14
|
"identifier": "@cyanheads/biorxiv-mcp-server",
|
|
15
15
|
"runtimeHint": "bun",
|
|
16
|
-
"version": "0.2.
|
|
16
|
+
"version": "0.2.4",
|
|
17
17
|
"packageArguments": [
|
|
18
18
|
{
|
|
19
19
|
"type": "positional",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
63
63
|
"identifier": "@cyanheads/biorxiv-mcp-server",
|
|
64
64
|
"runtimeHint": "bun",
|
|
65
|
-
"version": "0.2.
|
|
65
|
+
"version": "0.2.4",
|
|
66
66
|
"packageArguments": [
|
|
67
67
|
{
|
|
68
68
|
"type": "positional",
|