@cyanheads/cern-inspire-mcp-server 0.1.1
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 +504 -0
- package/CLAUDE.md +504 -0
- package/Dockerfile +177 -0
- package/LICENSE +201 -0
- package/README.md +311 -0
- package/changelog/0.1.x/0.1.0.md +9 -0
- package/changelog/0.1.x/0.1.1.md +22 -0
- package/changelog/template.md +151 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server/resources/definitions/index.d.ts +106 -0
- package/dist/mcp-server/resources/definitions/index.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/index.js +7 -0
- package/dist/mcp-server/resources/definitions/index.js.map +1 -0
- package/dist/mcp-server/resources/definitions/inspire-literature.resource.d.ts +110 -0
- package/dist/mcp-server/resources/definitions/inspire-literature.resource.d.ts.map +1 -0
- package/dist/mcp-server/resources/definitions/inspire-literature.resource.js +69 -0
- package/dist/mcp-server/resources/definitions/inspire-literature.resource.js.map +1 -0
- package/dist/mcp-server/tools/definitions/export-citations.tool.d.ts +65 -0
- package/dist/mcp-server/tools/definitions/export-citations.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/export-citations.tool.js +120 -0
- package/dist/mcp-server/tools/definitions/export-citations.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-citation-summary.tool.d.ts +159 -0
- package/dist/mcp-server/tools/definitions/get-citation-summary.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-citation-summary.tool.js +262 -0
- package/dist/mcp-server/tools/definitions/get-citation-summary.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/get-paper.tool.d.ts +195 -0
- package/dist/mcp-server/tools/definitions/get-paper.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/get-paper.tool.js +356 -0
- package/dist/mcp-server/tools/definitions/get-paper.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/index.d.ts +675 -0
- package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/index.js +23 -0
- package/dist/mcp-server/tools/definitions/index.js.map +1 -0
- package/dist/mcp-server/tools/definitions/list-reference.tool.d.ts +33 -0
- package/dist/mcp-server/tools/definitions/list-reference.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/list-reference.tool.js +312 -0
- package/dist/mcp-server/tools/definitions/list-reference.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-authors.tool.d.ts +92 -0
- package/dist/mcp-server/tools/definitions/search-authors.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/search-authors.tool.js +298 -0
- package/dist/mcp-server/tools/definitions/search-authors.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-experiments.tool.d.ts +80 -0
- package/dist/mcp-server/tools/definitions/search-experiments.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/search-experiments.tool.js +223 -0
- package/dist/mcp-server/tools/definitions/search-experiments.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-hepdata.tool.d.ts +81 -0
- package/dist/mcp-server/tools/definitions/search-hepdata.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/search-hepdata.tool.js +225 -0
- package/dist/mcp-server/tools/definitions/search-hepdata.tool.js.map +1 -0
- package/dist/mcp-server/tools/definitions/search-literature.tool.d.ts +127 -0
- package/dist/mcp-server/tools/definitions/search-literature.tool.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/search-literature.tool.js +331 -0
- package/dist/mcp-server/tools/definitions/search-literature.tool.js.map +1 -0
- package/dist/mcp-server/tools/inputs.d.ts +80 -0
- package/dist/mcp-server/tools/inputs.d.ts.map +1 -0
- package/dist/mcp-server/tools/inputs.js +100 -0
- package/dist/mcp-server/tools/inputs.js.map +1 -0
- package/dist/services/http/fetch-bounded.d.ts +45 -0
- package/dist/services/http/fetch-bounded.d.ts.map +1 -0
- package/dist/services/http/fetch-bounded.js +79 -0
- package/dist/services/http/fetch-bounded.js.map +1 -0
- package/dist/services/inspire/identifiers.d.ts +55 -0
- package/dist/services/inspire/identifiers.d.ts.map +1 -0
- package/dist/services/inspire/identifiers.js +98 -0
- package/dist/services/inspire/identifiers.js.map +1 -0
- package/dist/services/inspire/inspire-service.d.ts +104 -0
- package/dist/services/inspire/inspire-service.d.ts.map +1 -0
- package/dist/services/inspire/inspire-service.js +525 -0
- package/dist/services/inspire/inspire-service.js.map +1 -0
- package/dist/services/inspire/normalize.d.ts +30 -0
- package/dist/services/inspire/normalize.d.ts.map +1 -0
- package/dist/services/inspire/normalize.js +438 -0
- package/dist/services/inspire/normalize.js.map +1 -0
- package/dist/services/inspire/types.d.ts +505 -0
- package/dist/services/inspire/types.d.ts.map +1 -0
- package/dist/services/inspire/types.js +8 -0
- package/dist/services/inspire/types.js.map +1 -0
- package/dist/services/inspire/vocabulary.d.ts +22 -0
- package/dist/services/inspire/vocabulary.d.ts.map +1 -0
- package/dist/services/inspire/vocabulary.js +68 -0
- package/dist/services/inspire/vocabulary.js.map +1 -0
- package/dist/utils/render.d.ts +40 -0
- package/dist/utils/render.d.ts.map +1 -0
- package/dist/utils/render.js +112 -0
- package/dist/utils/render.js.map +1 -0
- package/package.json +112 -0
- package/server.json +100 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview cern_inspire_search_literature — one page of INSPIRE-HEP
|
|
3
|
+
* literature search results for INSPIRE query syntax or free text, filtered by
|
|
4
|
+
* document type, subject, and year, sorted by relevance, recency, or citations.
|
|
5
|
+
* @module mcp-server/tools/definitions/search-literature.tool
|
|
6
|
+
*/
|
|
7
|
+
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
8
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
9
|
+
import { blankAsUnset, documentTypesInput, formatAppliedFilters, hasFacetFilters, subjectsInput, yearFromInput, yearToInput, } from '../inputs.js';
|
|
10
|
+
import { getInspireService } from '../../../services/inspire/inspire-service.js';
|
|
11
|
+
import { inline, quote } from '../../../utils/render.js';
|
|
12
|
+
/** INSPIRE serves at most this many results of one query (`page × size`). */
|
|
13
|
+
const RESULT_WINDOW = 10_000;
|
|
14
|
+
/** Above this many matches a query is flagged as possibly mis-parsed (Design Decisions #17). */
|
|
15
|
+
const BROAD_MATCH_THRESHOLD = 100_000;
|
|
16
|
+
/** INSPIRE's short-form field operators, recognized at the start of a clause. */
|
|
17
|
+
const SHORT_OPERATORS = new Set([
|
|
18
|
+
'a',
|
|
19
|
+
'au',
|
|
20
|
+
'author',
|
|
21
|
+
't',
|
|
22
|
+
'ti',
|
|
23
|
+
'title',
|
|
24
|
+
'cn',
|
|
25
|
+
'collaboration',
|
|
26
|
+
'j',
|
|
27
|
+
'journal',
|
|
28
|
+
'd',
|
|
29
|
+
'date',
|
|
30
|
+
'de',
|
|
31
|
+
'topcite',
|
|
32
|
+
'tc',
|
|
33
|
+
'eprint',
|
|
34
|
+
'k',
|
|
35
|
+
'keyword',
|
|
36
|
+
'rn',
|
|
37
|
+
'fa',
|
|
38
|
+
'ac',
|
|
39
|
+
]);
|
|
40
|
+
/** Tokens after which a new search clause starts. */
|
|
41
|
+
const CLAUSE_LEADERS = new Set(['and', 'or', 'not', 'find', 'f']);
|
|
42
|
+
/** A `field:value` token (`refersto:recid:1`, `collaboration:atlas`), optionally after `(`. */
|
|
43
|
+
const FIELD_PREFIX = /^\(*[a-z_.]+:/i;
|
|
44
|
+
/** An author operator (`a`, `au`, `author`, `exactauthor:`). */
|
|
45
|
+
const AUTHOR_OPERATOR = /(?:^|[\s(])(?:a|au|author)\s|exactauthor:/i;
|
|
46
|
+
/** An INSPIRE BAI-shaped token: `Jane.Doe.1`, `J.Doe.1`. */
|
|
47
|
+
const BAI_TOKEN = /[A-Za-z][\w'-]*\.[A-Za-z][\w'-]*\.\d+/;
|
|
48
|
+
/** True when the query uses a field operator rather than bare words. */
|
|
49
|
+
function hasFieldOperator(query) {
|
|
50
|
+
const tokens = query.trim().split(/\s+/);
|
|
51
|
+
return tokens.some((token, i) => {
|
|
52
|
+
if (FIELD_PREFIX.test(token))
|
|
53
|
+
return true;
|
|
54
|
+
if (i === tokens.length - 1)
|
|
55
|
+
return false;
|
|
56
|
+
const clauseStart = i === 0 || token.startsWith('(') || CLAUSE_LEADERS.has(tokens[i - 1]?.toLowerCase() ?? '');
|
|
57
|
+
return clauseStart && SHORT_OPERATORS.has(token.replace(/^\(+/, '').toLowerCase());
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const SORTS = ['relevance', 'mostrecent', 'mostcited'];
|
|
61
|
+
const literatureHitSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
recid: z.string().describe('INSPIRE literature record ID; pass to cern_inspire_get_paper.'),
|
|
64
|
+
title: z.string().describe('Title as INSPIRE records it (LaTeX left as published).'),
|
|
65
|
+
firstAuthor: z
|
|
66
|
+
.object({
|
|
67
|
+
name: z.string().describe('First author, "Surname, Given names".'),
|
|
68
|
+
recid: z
|
|
69
|
+
.string()
|
|
70
|
+
.optional()
|
|
71
|
+
.describe('INSPIRE author record ID, when linked; pass as query to cern_inspire_search_authors for the profile.'),
|
|
72
|
+
})
|
|
73
|
+
.optional()
|
|
74
|
+
.describe('First author, when INSPIRE indexes one.'),
|
|
75
|
+
authorCount: z
|
|
76
|
+
.number()
|
|
77
|
+
.optional()
|
|
78
|
+
.describe('Number of authors, when INSPIRE indexes the count.'),
|
|
79
|
+
collaborations: z
|
|
80
|
+
.array(z.string().describe('Collaboration name.'))
|
|
81
|
+
.describe('Collaborations credited on the paper; empty for most non-collaboration papers.'),
|
|
82
|
+
date: z
|
|
83
|
+
.string()
|
|
84
|
+
.optional()
|
|
85
|
+
.describe('Earliest date INSPIRE records for the paper: YYYY, YYYY-MM, or YYYY-MM-DD.'),
|
|
86
|
+
documentTypes: z
|
|
87
|
+
.array(z.string().describe('INSPIRE document type.'))
|
|
88
|
+
.describe('INSPIRE document types.'),
|
|
89
|
+
citationCount: z.number().describe('Citations INSPIRE counts for the paper.'),
|
|
90
|
+
citationCountWithoutSelf: z
|
|
91
|
+
.number()
|
|
92
|
+
.optional()
|
|
93
|
+
.describe('Citations excluding self-citations, when INSPIRE reports it.'),
|
|
94
|
+
arxivId: z.string().optional().describe('arXiv identifier, when the paper has one.'),
|
|
95
|
+
arxivCategories: z
|
|
96
|
+
.array(z.string().describe('arXiv category.'))
|
|
97
|
+
.describe('arXiv categories of the e-print.'),
|
|
98
|
+
doi: z.string().optional().describe('First DOI, when the paper has one.'),
|
|
99
|
+
publication: z
|
|
100
|
+
.string()
|
|
101
|
+
.optional()
|
|
102
|
+
.describe('First publication reference: "Journal Vol (Year) pages" or its free-text form.'),
|
|
103
|
+
abstractSnippet: z
|
|
104
|
+
.string()
|
|
105
|
+
.optional()
|
|
106
|
+
.describe('Start of the abstract (arXiv-sourced when available), up to 300 characters at a word boundary.'),
|
|
107
|
+
abstractTruncated: z
|
|
108
|
+
.boolean()
|
|
109
|
+
.optional()
|
|
110
|
+
.describe('True when the abstract continues past the snippet; cern_inspire_get_paper has it in full.'),
|
|
111
|
+
})
|
|
112
|
+
.describe('One matching paper.');
|
|
113
|
+
function renderHit(hit, position) {
|
|
114
|
+
const lines = [`### ${position}. ${inline(hit.title) || '(untitled)'}`];
|
|
115
|
+
const facts = [`**recid:** ${hit.recid}`];
|
|
116
|
+
if (hit.date)
|
|
117
|
+
facts.push(`**Date:** ${inline(hit.date)}`);
|
|
118
|
+
facts.push(`**Citations:** ${hit.citationCount}${hit.citationCountWithoutSelf === undefined
|
|
119
|
+
? ''
|
|
120
|
+
: ` (${hit.citationCountWithoutSelf} without self-citations)`}`);
|
|
121
|
+
lines.push(facts.join(' · '));
|
|
122
|
+
const firstAuthor = hit.firstAuthor
|
|
123
|
+
? `${inline(hit.firstAuthor.name)}${hit.firstAuthor.recid ? ` (author recid ${hit.firstAuthor.recid})` : ''}`
|
|
124
|
+
: 'Not available';
|
|
125
|
+
lines.push(`**First author:** ${firstAuthor} · **Authors:** ${hit.authorCount ?? 'Not available'}`);
|
|
126
|
+
if (hit.collaborations.length > 0) {
|
|
127
|
+
lines.push(`**Collaborations:** ${hit.collaborations.map(inline).join(', ')}`);
|
|
128
|
+
}
|
|
129
|
+
if (hit.documentTypes.length > 0) {
|
|
130
|
+
lines.push(`**Document types:** ${hit.documentTypes.map(inline).join(', ')}`);
|
|
131
|
+
}
|
|
132
|
+
const ids = [];
|
|
133
|
+
if (hit.arxivId) {
|
|
134
|
+
const categories = hit.arxivCategories.length > 0 ? ` (${hit.arxivCategories.map(inline).join(', ')})` : '';
|
|
135
|
+
ids.push(`**arXiv:** ${inline(hit.arxivId)}${categories}`);
|
|
136
|
+
}
|
|
137
|
+
if (hit.doi)
|
|
138
|
+
ids.push(`**DOI:** ${inline(hit.doi)}`);
|
|
139
|
+
if (hit.publication)
|
|
140
|
+
ids.push(`**Publication:** ${inline(hit.publication)}`);
|
|
141
|
+
if (ids.length > 0)
|
|
142
|
+
lines.push(ids.join(' · '));
|
|
143
|
+
if (hit.abstractSnippet) {
|
|
144
|
+
lines.push(hit.abstractTruncated
|
|
145
|
+
? '**Abstract** (truncated; cern_inspire_get_paper has it in full):'
|
|
146
|
+
: '**Abstract:**', quote(hit.abstractSnippet));
|
|
147
|
+
}
|
|
148
|
+
return lines;
|
|
149
|
+
}
|
|
150
|
+
export const searchLiteratureTool = tool('cern_inspire_search_literature', {
|
|
151
|
+
title: 'Search INSPIRE literature',
|
|
152
|
+
description: 'Search INSPIRE-HEP papers with INSPIRE query syntax or free text, filtered by document type, subject, and year, sorted by relevance, recency, or citations. Returns one page of papers with recid, title, first author, date, citation counts, arXiv ID, DOI, publication, and an abstract snippet; pass a recid to cern_inspire_get_paper for the full record or to cern_inspire_export_citations ("recid:N") for BibTeX. INSPIRE never rejects malformed syntax: an unparsed operator widens or empties the match, so a very broad or empty result usually means the query needs fixing (cern_inspire_list_reference topic search_syntax). Only the first 10,000 results of a query are reachable.',
|
|
153
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
|
|
154
|
+
input: z.object({
|
|
155
|
+
query: z
|
|
156
|
+
.string()
|
|
157
|
+
.trim()
|
|
158
|
+
.min(1)
|
|
159
|
+
.max(1000)
|
|
160
|
+
.describe('INSPIRE query syntax or free text. Common operators: "a Jane.Doe.1" or "a Doe, J" (author), "t higgs boson" (title words), "cn atlas" or "collaboration:atlas" (collaboration), "date > 2015", "topcite 500+" (cited 500+ times), "refersto:recid:451647" (papers citing a record), "citedby:recid:451647" (its references), "j Phys.Rev.Lett." (journal), "eprint 1207.7214"; combine with and/or/not. Bare words search all fields. INSPIRE does not reject malformed syntax; see cern_inspire_list_reference topic search_syntax for the rest.'),
|
|
161
|
+
sort: blankAsUnset(z.enum(SORTS).default('relevance')).describe('Result order: relevance (default), mostrecent, or mostcited.'),
|
|
162
|
+
document_types: documentTypesInput,
|
|
163
|
+
subjects: subjectsInput,
|
|
164
|
+
year_from: yearFromInput,
|
|
165
|
+
year_to: yearToInput,
|
|
166
|
+
page: blankAsUnset(z.number().int().min(1).default(1)).describe('Page number, starting at 1. page × size may not exceed 10,000.'),
|
|
167
|
+
size: blankAsUnset(z.number().int().min(1).max(100).default(10)).describe('Papers per page (1–100, default 10).'),
|
|
168
|
+
}),
|
|
169
|
+
output: z.object({
|
|
170
|
+
papers: z
|
|
171
|
+
.array(literatureHitSchema)
|
|
172
|
+
.describe('The papers on this page, in the requested order.'),
|
|
173
|
+
page: z.number().describe('The page returned.'),
|
|
174
|
+
size: z.number().describe('The page size requested.'),
|
|
175
|
+
hasMore: z.boolean().describe('True when INSPIRE has a further page of results.'),
|
|
176
|
+
}),
|
|
177
|
+
enrichment: {
|
|
178
|
+
totalCount: z.number().describe('Total literature records the query matched.'),
|
|
179
|
+
truncated: z.boolean().describe('True when more results exist beyond this page.'),
|
|
180
|
+
shown: z.number().describe('Number of papers on this page.'),
|
|
181
|
+
cap: z.number().describe('The page size applied.'),
|
|
182
|
+
nextPage: z
|
|
183
|
+
.number()
|
|
184
|
+
.optional()
|
|
185
|
+
.describe('The page number to request next, when one exists within the 10,000-result window.'),
|
|
186
|
+
appliedFilters: z
|
|
187
|
+
.string()
|
|
188
|
+
.describe('Sort and filters applied, e.g. "sort=mostcited; years=2012–2015", or "none".'),
|
|
189
|
+
notice: z.string().optional().describe('Guidance on an empty, very broad, or paged result.'),
|
|
190
|
+
},
|
|
191
|
+
enrichmentTrailer: {
|
|
192
|
+
nextPage: { label: 'Next page' },
|
|
193
|
+
appliedFilters: { label: 'Applied filters' },
|
|
194
|
+
},
|
|
195
|
+
errors: [
|
|
196
|
+
{
|
|
197
|
+
reason: 'beyond_result_window',
|
|
198
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
199
|
+
when: 'page × size exceeds the 10,000 results INSPIRE serves for one query.',
|
|
200
|
+
recovery: 'Narrow the query with year_from/year_to, document_types, or tighter terms until it matches under 10,000 records, then page again with cern_inspire_search_literature.',
|
|
201
|
+
severity: 'notice',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
reason: 'invalid_year_range',
|
|
205
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
206
|
+
when: 'year_from is later than year_to.',
|
|
207
|
+
recovery: 'Swap year_from and year_to so the range runs forward, or drop one bound for an open range, then retry this call.',
|
|
208
|
+
severity: 'notice',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
reason: 'invalid_query',
|
|
212
|
+
code: JsonRpcErrorCode.ValidationError,
|
|
213
|
+
when: 'INSPIRE answered 400 to a parameter value it refuses.',
|
|
214
|
+
recovery: 'Check the query and filters against cern_inspire_list_reference topic search_syntax, then retry cern_inspire_search_literature with corrected values.',
|
|
215
|
+
severity: 'notice',
|
|
216
|
+
thrownBy: 'service',
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
reason: 'inspire_rate_limited',
|
|
220
|
+
code: JsonRpcErrorCode.RateLimited,
|
|
221
|
+
when: 'INSPIRE returned 429 after the pacer and retries.',
|
|
222
|
+
recovery: 'Wait the retry-after seconds this error states (at least 5), then retry this call; INSPIRE allows 15 requests per 5 seconds from one address.',
|
|
223
|
+
retryable: true,
|
|
224
|
+
thrownBy: 'service',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
reason: 'pacer_shed',
|
|
228
|
+
code: JsonRpcErrorCode.RateLimited,
|
|
229
|
+
when: "The server's outbound INSPIRE queue could not start the request within the call's remaining budget.",
|
|
230
|
+
recovery: "This server's INSPIRE request queue is saturated; wait the seconds in this error's retryAfter field (about 5 when it is not shown), then retry this call with fewer cern_inspire calls running in parallel.",
|
|
231
|
+
retryable: true,
|
|
232
|
+
thrownBy: 'service',
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
reason: 'upstream_unreadable',
|
|
236
|
+
code: JsonRpcErrorCode.ServiceUnavailable,
|
|
237
|
+
when: 'The INSPIRE body exceeded the byte ceiling, was HTML where JSON was expected, or was invalid JSON.',
|
|
238
|
+
recovery: 'Retry this call in a few seconds; if it fails again, retry cern_inspire_search_literature with a smaller size.',
|
|
239
|
+
thrownBy: 'service',
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
async handler(input, ctx) {
|
|
243
|
+
const filters = {
|
|
244
|
+
documentTypes: input.document_types,
|
|
245
|
+
subjects: input.subjects,
|
|
246
|
+
yearFrom: input.year_from,
|
|
247
|
+
yearTo: input.year_to,
|
|
248
|
+
};
|
|
249
|
+
const appliedFilters = formatAppliedFilters({ sort: input.sort, ...filters });
|
|
250
|
+
ctx.enrich({ truncated: false, shown: 0, cap: input.size, appliedFilters });
|
|
251
|
+
ctx.enrich.total(0);
|
|
252
|
+
if (input.year_from !== undefined &&
|
|
253
|
+
input.year_to !== undefined &&
|
|
254
|
+
input.year_from > input.year_to) {
|
|
255
|
+
throw ctx.fail('invalid_year_range', `year_from (${input.year_from}) is later than year_to (${input.year_to}).`);
|
|
256
|
+
}
|
|
257
|
+
if (input.page * input.size > RESULT_WINDOW) {
|
|
258
|
+
throw ctx.fail('beyond_result_window', `page ${input.page} × size ${input.size} reaches past the first 10,000 results, which is all INSPIRE serves for one query.`, { page: input.page, size: input.size });
|
|
259
|
+
}
|
|
260
|
+
const inspire = getInspireService();
|
|
261
|
+
const result = await inspire.searchLiterature({ query: input.query, sort: input.sort, page: input.page, size: input.size, ...filters }, inspire.beginCall(ctx));
|
|
262
|
+
ctx.enrich.total(result.total);
|
|
263
|
+
ctx.enrich({ shown: result.papers.length });
|
|
264
|
+
ctx.log.info('Literature search completed', {
|
|
265
|
+
total: result.total,
|
|
266
|
+
shown: result.papers.length,
|
|
267
|
+
page: input.page,
|
|
268
|
+
});
|
|
269
|
+
const notices = [];
|
|
270
|
+
if (result.papers.length === 0) {
|
|
271
|
+
notices.push(...zeroHitNotice(input, result.total, filters));
|
|
272
|
+
}
|
|
273
|
+
else if (result.total > BROAD_MATCH_THRESHOLD) {
|
|
274
|
+
notices.push(`This query matched ${result.total.toLocaleString('en-US')} of INSPIRE's ~1.9 M records. INSPIRE does not reject malformed syntax (an unparsed operator widens the match), so check the query against cern_inspire_list_reference topic search_syntax.`);
|
|
275
|
+
}
|
|
276
|
+
if (result.hasMore) {
|
|
277
|
+
const nextPage = input.page + 1;
|
|
278
|
+
const reachable = nextPage * input.size <= RESULT_WINDOW;
|
|
279
|
+
if (reachable)
|
|
280
|
+
ctx.enrich({ nextPage });
|
|
281
|
+
notices.unshift(reachable
|
|
282
|
+
? `More results: request page ${nextPage} for the next ${input.size}.`
|
|
283
|
+
: 'INSPIRE serves only the first 10,000 results of a query; narrow it with year_from/year_to, document_types, or tighter terms to reach the rest.');
|
|
284
|
+
ctx.enrich.truncated({
|
|
285
|
+
shown: result.papers.length,
|
|
286
|
+
cap: input.size,
|
|
287
|
+
guidance: notices.join(' '),
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
else if (notices.length > 0) {
|
|
291
|
+
ctx.enrich.notice(notices.join(' '));
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
papers: result.papers,
|
|
295
|
+
page: input.page,
|
|
296
|
+
size: input.size,
|
|
297
|
+
hasMore: result.hasMore,
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
format: (result) => {
|
|
301
|
+
const lines = [
|
|
302
|
+
`## INSPIRE literature, page ${result.page}`,
|
|
303
|
+
`**Page:** ${result.page} · **Size:** ${result.size} · **Papers on this page:** ${result.papers.length} · **More pages:** ${result.hasMore ? 'yes' : 'no'}`,
|
|
304
|
+
];
|
|
305
|
+
const offset = (result.page - 1) * result.size;
|
|
306
|
+
result.papers.forEach((hit, i) => {
|
|
307
|
+
lines.push('', ...renderHit(hit, offset + i + 1));
|
|
308
|
+
});
|
|
309
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
/** The zero-hit notice fragments that hold for this call (design § search_literature). */
|
|
313
|
+
function zeroHitNotice(input, total, filters) {
|
|
314
|
+
if (total > 0) {
|
|
315
|
+
return [
|
|
316
|
+
`Page ${input.page} is past the last page (${Math.ceil(total / input.size)}); request a lower page.`,
|
|
317
|
+
];
|
|
318
|
+
}
|
|
319
|
+
const fragments = [`No INSPIRE literature matched "${inline(input.query)}".`];
|
|
320
|
+
if (hasFacetFilters(filters)) {
|
|
321
|
+
fragments.push(`Filters narrowed the set (${formatAppliedFilters(filters)}); drop them to widen — multiple document_types or subjects must all hold.`);
|
|
322
|
+
}
|
|
323
|
+
if (!hasFieldOperator(input.query)) {
|
|
324
|
+
fragments.push('Bare words search all fields; use "t <words>" for titles or "a <name>" for authors — see cern_inspire_list_reference topic search_syntax.');
|
|
325
|
+
}
|
|
326
|
+
if (AUTHOR_OPERATOR.test(input.query) && BAI_TOKEN.test(input.query)) {
|
|
327
|
+
fragments.push('Author BAIs are exact and case-sensitive, and usually spell out the first name (Jane.Doe.1, not J.Doe.1); resolve the person with cern_inspire_search_authors.');
|
|
328
|
+
}
|
|
329
|
+
return fragments;
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=search-literature.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-literature.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/search-literature.tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,aAAa,EACb,aAAa,EACb,WAAW,GACZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAE1E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAElD,6EAA6E;AAC7E,MAAM,aAAa,GAAG,MAAM,CAAC;AAE7B,gGAAgG;AAChG,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAEtC,iFAAiF;AACjF,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,GAAG;IACH,IAAI;IACJ,QAAQ;IACR,GAAG;IACH,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,eAAe;IACf,GAAG;IACH,SAAS;IACT,GAAG;IACH,MAAM;IACN,IAAI;IACJ,SAAS;IACT,IAAI;IACJ,QAAQ;IACR,GAAG;IACH,SAAS;IACT,IAAI;IACJ,IAAI;IACJ,IAAI;CACL,CAAC,CAAC;AAEH,qDAAqD;AACrD,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;AAElE,+FAA+F;AAC/F,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAEtC,gEAAgE;AAChE,MAA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IAAI,CAAC,0BAA0B;SACrG,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,CAAC,kCAAkC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9E,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,SAAS,CAAC,IAAI,CACZ,6BAA6B,oBAAoB,CAAC,OAAO,CAAC,4EAA4E,CACvI,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,SAAS,CAAC,IAAI,CACZ,2IAA2I,CAC5I,CAAC;IACJ,CAAC;IACD,IAAI,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACrE,SAAS,CAAC,IAAI,CACZ,gKAAgK,CACjK,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Input schemas and helpers shared across the INSPIRE tools: the
|
|
3
|
+
* blank-as-unset wrapper for form clients, the `paper` identifier input, the
|
|
4
|
+
* facet enum arrays (comma-joined or array, case-folded), the year bounds, the
|
|
5
|
+
* author-identifier inputs, and the applied-filters echo string.
|
|
6
|
+
* @module mcp-server/tools/inputs
|
|
7
|
+
*/
|
|
8
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
9
|
+
import type { FacetFilters } from '../../services/inspire/types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Treats `''` as unset before `schema` runs, so a form client's blank optional
|
|
12
|
+
* field (enums with a default included) takes the default instead of failing.
|
|
13
|
+
*/
|
|
14
|
+
export declare const blankAsUnset: <T extends z.ZodType>(schema: T) => z.ZodPreprocess<T, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* One paper identifier, normalized before the length and pattern checks (see
|
|
17
|
+
* `normalizePaperId`): recid, new or old arXiv ID, or DOI, at most 256 characters.
|
|
18
|
+
*/
|
|
19
|
+
export declare const paperInput: z.ZodPreprocess<z.ZodString, unknown>;
|
|
20
|
+
/** Up to 4 INSPIRE document types; multiple values AND together upstream. */
|
|
21
|
+
export declare const documentTypesInput: z.ZodPreprocess<z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
22
|
+
"activity report": "activity report";
|
|
23
|
+
article: "article";
|
|
24
|
+
book: "book";
|
|
25
|
+
"book chapter": "book chapter";
|
|
26
|
+
"conference paper": "conference paper";
|
|
27
|
+
introductory: "introductory";
|
|
28
|
+
lectures: "lectures";
|
|
29
|
+
note: "note";
|
|
30
|
+
proceedings: "proceedings";
|
|
31
|
+
published: "published";
|
|
32
|
+
report: "report";
|
|
33
|
+
review: "review";
|
|
34
|
+
thesis: "thesis";
|
|
35
|
+
}>>>, unknown>;
|
|
36
|
+
/** Up to 4 INSPIRE subject categories; multiple values AND together upstream. */
|
|
37
|
+
export declare const subjectsInput: z.ZodPreprocess<z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
38
|
+
Accelerators: "Accelerators";
|
|
39
|
+
Astrophysics: "Astrophysics";
|
|
40
|
+
Computing: "Computing";
|
|
41
|
+
"Condensed Matter": "Condensed Matter";
|
|
42
|
+
"Data Analysis and Statistics": "Data Analysis and Statistics";
|
|
43
|
+
"Experiment-HEP": "Experiment-HEP";
|
|
44
|
+
"Experiment-Nucl": "Experiment-Nucl";
|
|
45
|
+
"General Physics": "General Physics";
|
|
46
|
+
"Gravitation and Cosmology": "Gravitation and Cosmology";
|
|
47
|
+
Instrumentation: "Instrumentation";
|
|
48
|
+
Lattice: "Lattice";
|
|
49
|
+
"Math and Math Physics": "Math and Math Physics";
|
|
50
|
+
Other: "Other";
|
|
51
|
+
"Phenomenology-HEP": "Phenomenology-HEP";
|
|
52
|
+
"Quantum Physics": "Quantum Physics";
|
|
53
|
+
"Theory-HEP": "Theory-HEP";
|
|
54
|
+
"Theory-Nucl": "Theory-Nucl";
|
|
55
|
+
Unknown: "Unknown";
|
|
56
|
+
}>>>, unknown>;
|
|
57
|
+
/** Earliest publication year to include (inclusive); maps to INSPIRE `earliest_date`. */
|
|
58
|
+
export declare const yearFromInput: z.ZodPreprocess<z.ZodOptional<z.ZodNumber>, unknown>;
|
|
59
|
+
/** Latest publication year to include (inclusive); maps to INSPIRE `earliest_date`. */
|
|
60
|
+
export declare const yearToInput: z.ZodPreprocess<z.ZodOptional<z.ZodNumber>, unknown>;
|
|
61
|
+
/** A required author name or identifier, normalized by `normalizeAuthorId` (ORCID URL, checksum, `INSPIRE-` case). */
|
|
62
|
+
export declare const authorQueryInput: z.ZodPreprocess<z.ZodString, unknown>;
|
|
63
|
+
/** An optional author identifier (BAI, ORCID, INSPIRE ID, or recid); blank is unset. */
|
|
64
|
+
export declare const authorIdInput: z.ZodPreprocess<z.ZodOptional<z.ZodString>, unknown>;
|
|
65
|
+
/** `2012–2015`, `2012–` (open end), `–1990` (open start), or `undefined` when neither bound is set. */
|
|
66
|
+
export declare function yearRangeLabel(yearFrom: number | undefined, yearTo: number | undefined): string | undefined;
|
|
67
|
+
/** The filters a call applied, for the `appliedFilters` echo. */
|
|
68
|
+
export interface AppliedFilters extends FacetFilters {
|
|
69
|
+
excludeSelfCitations?: boolean | undefined;
|
|
70
|
+
/** Echoed only when it is not the default `relevance`. */
|
|
71
|
+
sort?: string | undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The `appliedFilters` echo: `sort=mostcited; document_types=published;
|
|
75
|
+
* years=2012–2015`, or `none` when nothing narrows or reorders the result.
|
|
76
|
+
*/
|
|
77
|
+
export declare function formatAppliedFilters(filters: AppliedFilters): string;
|
|
78
|
+
/** True when any facet filter (document types, subjects, years) is set. */
|
|
79
|
+
export declare function hasFacetFilters(filters: FacetFilters): boolean;
|
|
80
|
+
//# sourceMappingURL=inputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|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|
1
|
+
/**
|
|
2
|
+
* @fileoverview Input schemas and helpers shared across the INSPIRE tools: the
|
|
3
|
+
* blank-as-unset wrapper for form clients, the `paper` identifier input, the
|
|
4
|
+
* facet enum arrays (comma-joined or array, case-folded), the year bounds, the
|
|
5
|
+
* author-identifier inputs, and the applied-filters echo string.
|
|
6
|
+
* @module mcp-server/tools/inputs
|
|
7
|
+
*/
|
|
8
|
+
import { z } from '@cyanheads/mcp-ts-core';
|
|
9
|
+
import { normalizeAuthorId, normalizePaperId, PAPER_ID_PATTERN, } from '../../services/inspire/identifiers.js';
|
|
10
|
+
import { DOCUMENT_TYPES, SUBJECTS } from '../../services/inspire/vocabulary.js';
|
|
11
|
+
/**
|
|
12
|
+
* Treats `''` as unset before `schema` runs, so a form client's blank optional
|
|
13
|
+
* field (enums with a default included) takes the default instead of failing.
|
|
14
|
+
*/
|
|
15
|
+
export const blankAsUnset = (schema) => z.preprocess((value) => (value === '' ? undefined : value), schema);
|
|
16
|
+
/**
|
|
17
|
+
* One paper identifier, normalized before the length and pattern checks (see
|
|
18
|
+
* `normalizePaperId`): recid, new or old arXiv ID, or DOI, at most 256 characters.
|
|
19
|
+
*/
|
|
20
|
+
export const paperInput = z
|
|
21
|
+
.preprocess((value) => (typeof value === 'string' ? normalizePaperId(value) : value), z
|
|
22
|
+
.string()
|
|
23
|
+
.max(256)
|
|
24
|
+
.regex(PAPER_ID_PATTERN, 'Expected an INSPIRE recid (451647), an arXiv ID (1207.7214 or hep-th/9711200), or a DOI (10.1016/…).'))
|
|
25
|
+
.describe("INSPIRE recid (e.g. 451647), arXiv ID (1207.7214 or hep-th/9711200, with or without 'arXiv:', a version suffix, or an arxiv.org URL), DOI (10.1016/…, with or without 'doi:' or a doi.org prefix; no * or ? wildcards), an inspirehep.net literature URL, or HEPData's ins<recid> form or hepdata.net record URL. Up to 256 characters.");
|
|
26
|
+
/**
|
|
27
|
+
* An optional array of enum values that also accepts a comma-joined string.
|
|
28
|
+
* `''` and `[]` are unset; each entry is trimmed, case-folded to the canonical
|
|
29
|
+
* spelling (a fixed lookup over the enum), de-duplicated, and the list is cut to
|
|
30
|
+
* `max + 1` so an oversized list fails with one bounded issue.
|
|
31
|
+
*/
|
|
32
|
+
function enumArray(values, max, itemDescription) {
|
|
33
|
+
const canonical = new Map(values.map((value) => [value.toLowerCase(), value]));
|
|
34
|
+
return z.preprocess((value) => {
|
|
35
|
+
if (value === '' || (Array.isArray(value) && value.length === 0))
|
|
36
|
+
return;
|
|
37
|
+
const list = typeof value === 'string' ? value.split(',') : value;
|
|
38
|
+
if (!Array.isArray(list))
|
|
39
|
+
return value;
|
|
40
|
+
const folded = list
|
|
41
|
+
.map((item) => {
|
|
42
|
+
if (typeof item !== 'string')
|
|
43
|
+
return item;
|
|
44
|
+
const trimmed = item.trim();
|
|
45
|
+
return canonical.get(trimmed.toLowerCase()) ?? trimmed;
|
|
46
|
+
})
|
|
47
|
+
.filter((item) => item !== '');
|
|
48
|
+
return folded.length === 0 ? undefined : [...new Set(folded)].slice(0, max + 1);
|
|
49
|
+
}, z.array(z.enum(values).describe(itemDescription)).max(max).optional());
|
|
50
|
+
}
|
|
51
|
+
/** Up to 4 INSPIRE document types; multiple values AND together upstream. */
|
|
52
|
+
export const documentTypesInput = enumArray(DOCUMENT_TYPES, 4, 'An INSPIRE document type (case-insensitive).').describe(`Restrict to INSPIRE document types, as an array or a comma-separated string (up to 4). Multiple values must ALL hold (published + review = published reviews), not either. Values: ${DOCUMENT_TYPES.join(', ')}.`);
|
|
53
|
+
/** Up to 4 INSPIRE subject categories; multiple values AND together upstream. */
|
|
54
|
+
export const subjectsInput = enumArray(SUBJECTS, 4, 'An INSPIRE subject category (case-insensitive).').describe(`Restrict to INSPIRE subject categories, as an array or a comma-separated string (up to 4). Multiple values must ALL hold, not either. Values: ${SUBJECTS.join(', ')}.`);
|
|
55
|
+
const year = () => blankAsUnset(z.number().int().min(1900).max(2100).optional());
|
|
56
|
+
/** Earliest publication year to include (inclusive); maps to INSPIRE `earliest_date`. */
|
|
57
|
+
export const yearFromInput = year().describe('Earliest year to include (1900–2100, inclusive), matched on the earliest date INSPIRE records for the paper. Omit for no lower bound.');
|
|
58
|
+
/** Latest publication year to include (inclusive); maps to INSPIRE `earliest_date`. */
|
|
59
|
+
export const yearToInput = year().describe('Latest year to include (1900–2100, inclusive), matched on the earliest date INSPIRE records for the paper. Omit for no upper bound.');
|
|
60
|
+
const asAuthorId = (value) => typeof value === 'string' ? normalizeAuthorId(value) : value;
|
|
61
|
+
/** A required author name or identifier, normalized by `normalizeAuthorId` (ORCID URL, checksum, `INSPIRE-` case). */
|
|
62
|
+
export const authorQueryInput = z
|
|
63
|
+
.preprocess(asAuthorId, z.string().min(1).max(200))
|
|
64
|
+
.describe('A physicist\'s name ("Witten, Edward" or "Edward Witten") or one identifier: INSPIRE BAI (Edward.Witten.1, exact and case-sensitive), ORCID (0000-0002-7752-6073 or an orcid.org URL), INSPIRE ID (INSPIRE-00136372), or author recid.');
|
|
65
|
+
/** An optional author identifier (BAI, ORCID, INSPIRE ID, or recid); blank is unset. */
|
|
66
|
+
export const authorIdInput = z
|
|
67
|
+
.preprocess((value) => {
|
|
68
|
+
const id = asAuthorId(value);
|
|
69
|
+
return id === '' ? undefined : id;
|
|
70
|
+
}, z.string().max(200).optional())
|
|
71
|
+
.describe('One author identifier: INSPIRE BAI (Edward.Witten.1, exact and case-sensitive), ORCID (0000-0002-7752-6073 or an orcid.org URL), INSPIRE ID (INSPIRE-00136372), or author recid. Not a name — resolve names with cern_inspire_search_authors first. Pass this or query, not both.');
|
|
72
|
+
/** `2012–2015`, `2012–` (open end), `–1990` (open start), or `undefined` when neither bound is set. */
|
|
73
|
+
export function yearRangeLabel(yearFrom, yearTo) {
|
|
74
|
+
if (yearFrom === undefined && yearTo === undefined)
|
|
75
|
+
return;
|
|
76
|
+
return `${yearFrom ?? ''}–${yearTo ?? ''}`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The `appliedFilters` echo: `sort=mostcited; document_types=published;
|
|
80
|
+
* years=2012–2015`, or `none` when nothing narrows or reorders the result.
|
|
81
|
+
*/
|
|
82
|
+
export function formatAppliedFilters(filters) {
|
|
83
|
+
const years = yearRangeLabel(filters.yearFrom, filters.yearTo);
|
|
84
|
+
const parts = [
|
|
85
|
+
filters.sort && filters.sort !== 'relevance' ? `sort=${filters.sort}` : undefined,
|
|
86
|
+
filters.documentTypes?.length ? `document_types=${filters.documentTypes.join(',')}` : undefined,
|
|
87
|
+
filters.subjects?.length ? `subjects=${filters.subjects.join(',')}` : undefined,
|
|
88
|
+
years ? `years=${years}` : undefined,
|
|
89
|
+
filters.excludeSelfCitations ? 'exclude_self_citations=true' : undefined,
|
|
90
|
+
].filter((part) => part !== undefined);
|
|
91
|
+
return parts.length === 0 ? 'none' : parts.join('; ');
|
|
92
|
+
}
|
|
93
|
+
/** True when any facet filter (document types, subjects, years) is set. */
|
|
94
|
+
export function hasFacetFilters(filters) {
|
|
95
|
+
return Boolean(filters.documentTypes?.length ||
|
|
96
|
+
filters.subjects?.length ||
|
|
97
|
+
filters.yearFrom !== undefined ||
|
|
98
|
+
filters.yearTo !== undefined);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=inputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.js","sourceRoot":"","sources":["../../../src/mcp-server/tools/inputs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5E;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAsB,MAAS,EAAE,EAAE,CAC7D,CAAC,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC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Q,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG;QACZ,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS;QACjF,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,kBAAkB,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;QAC/F,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,YAAY,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;QAC/E,KAAK,CAAC,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS;QACpC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,SAAS;KACzE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IACvC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxD,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,eAAe,CAAC,OAAqB;IACnD,OAAO,OAAO,CACZ,OAAO,CAAC,aAAa,EAAE,MAAM;QAC3B,OAAO,CAAC,QAAQ,EAAE,MAAM;QACxB,OAAO,CAAC,QAAQ,KAAK,SAAS;QAC9B,OAAO,CAAC,MAAM,KAAK,SAAS,CAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The single HTTP boundary every upstream service sits on: one
|
|
3
|
+
* request under a per-attempt timeout and the caller's signal, a body read as a
|
|
4
|
+
* stream under a byte ceiling, an accept-list of statuses returned to the caller,
|
|
5
|
+
* and transport failures classified so the retry layer can tell transient from
|
|
6
|
+
* final. Kept apart from any one service so each upstream reuses it.
|
|
7
|
+
* @module services/http/fetch-bounded
|
|
8
|
+
*/
|
|
9
|
+
/** Options for {@link fetchBounded}. */
|
|
10
|
+
export interface FetchBoundedOptions {
|
|
11
|
+
/** Statuses returned to the caller; any other status throws a classified `McpError`. */
|
|
12
|
+
accept: readonly number[];
|
|
13
|
+
/** Fetch implementation; defaults to the global `fetch`. */
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
/** Request headers. */
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
/** Body ceiling in bytes; a larger body is abandoned as `upstream_unreadable`. */
|
|
18
|
+
maxBytes: number;
|
|
19
|
+
/** Redirect mode; defaults to `follow`. */
|
|
20
|
+
redirect?: RequestInit['redirect'];
|
|
21
|
+
/** Logical upstream name used in error messages. */
|
|
22
|
+
service: string;
|
|
23
|
+
/** The caller's signal; when it fires, its reason is rethrown unchanged. */
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
/** Per-attempt timeout covering the request and the body read. */
|
|
26
|
+
timeoutMs: number;
|
|
27
|
+
}
|
|
28
|
+
/** A response whose status was on the accept-list, with its body read in full. */
|
|
29
|
+
export interface BoundedResponse {
|
|
30
|
+
headers: Headers;
|
|
31
|
+
status: number;
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Fetches `url` once and reads the body under `maxBytes`.
|
|
36
|
+
*
|
|
37
|
+
* - Status on `accept` → `{ status, headers, text }`.
|
|
38
|
+
* - Any other status → the `McpError` `httpErrorFromResponse` classifies (body captured, URL omitted).
|
|
39
|
+
* - Body over `maxBytes` (Content-Length checked first) → `ServiceUnavailable`, `reason: 'upstream_unreadable'`.
|
|
40
|
+
* - Caller signal fired → its reason, rethrown unchanged (never retried).
|
|
41
|
+
* - Per-attempt timeout fired → `Timeout` (retried by the caller's retry layer).
|
|
42
|
+
* - Network failure (`TypeError`, reset, DNS) → `ServiceUnavailable` (retried).
|
|
43
|
+
*/
|
|
44
|
+
export declare function fetchBounded(url: string, options: FetchBoundedOptions): Promise<BoundedResponse>;
|
|
45
|
+
//# sourceMappingURL=fetch-bounded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-bounded.d.ts","sourceRoot":"","sources":["../../../src/services/http/fetch-bounded.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,wFAAwF;IACxF,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,4DAA4D;IAC5D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,kFAAkF;IAClF,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACnC,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,kFAAkF;AAClF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,eAAe,CAAC,CAmC1B"}
|