@fre4x/arxiv 1.0.64 → 1.0.65-beta.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/dist/index.js +75 -39
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -47418,53 +47418,90 @@ var parser = new XMLParser({
|
|
|
47418
47418
|
attributeNamePrefix: "@_",
|
|
47419
47419
|
isArray: (tagName) => ["entry", "author", "category", "link"].includes(tagName)
|
|
47420
47420
|
});
|
|
47421
|
+
function isXmlNode(value) {
|
|
47422
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
47423
|
+
}
|
|
47424
|
+
function getXmlNode(value) {
|
|
47425
|
+
return isXmlNode(value) ? value : void 0;
|
|
47426
|
+
}
|
|
47427
|
+
function getXmlNodeArray(value) {
|
|
47428
|
+
if (Array.isArray(value)) {
|
|
47429
|
+
return value.filter(isXmlNode);
|
|
47430
|
+
}
|
|
47431
|
+
const node = getXmlNode(value);
|
|
47432
|
+
return node ? [node] : [];
|
|
47433
|
+
}
|
|
47434
|
+
function getXmlString(value) {
|
|
47435
|
+
return typeof value === "string" ? value : void 0;
|
|
47436
|
+
}
|
|
47437
|
+
function getXmlScalarText(value) {
|
|
47438
|
+
if (typeof value === "string") {
|
|
47439
|
+
return value;
|
|
47440
|
+
}
|
|
47441
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
47442
|
+
return String(value);
|
|
47443
|
+
}
|
|
47444
|
+
return void 0;
|
|
47445
|
+
}
|
|
47446
|
+
function getXmlText(value) {
|
|
47447
|
+
const direct = getXmlScalarText(value);
|
|
47448
|
+
if (direct !== void 0) {
|
|
47449
|
+
return direct;
|
|
47450
|
+
}
|
|
47451
|
+
const node = getXmlNode(value);
|
|
47452
|
+
if (!node) {
|
|
47453
|
+
return "";
|
|
47454
|
+
}
|
|
47455
|
+
return getXmlScalarText(node["#text"]) ?? "";
|
|
47456
|
+
}
|
|
47421
47457
|
function extractArxivId(fullId) {
|
|
47422
47458
|
const match = fullId.match(/abs\/([^v]+)/);
|
|
47423
47459
|
return match ? match[1] : fullId;
|
|
47424
47460
|
}
|
|
47425
47461
|
function parsePaper(entry) {
|
|
47426
|
-
const
|
|
47427
|
-
|
|
47428
|
-
|
|
47429
|
-
|
|
47430
|
-
|
|
47431
|
-
const categories =
|
|
47432
|
-
|
|
47433
|
-
|
|
47434
|
-
|
|
47435
|
-
|
|
47436
|
-
|
|
47437
|
-
|
|
47438
|
-
|
|
47439
|
-
|
|
47440
|
-
|
|
47441
|
-
|
|
47462
|
+
const authors = getXmlNodeArray(entry.author).map(
|
|
47463
|
+
(author) => ({
|
|
47464
|
+
name: getXmlText(author.name)
|
|
47465
|
+
})
|
|
47466
|
+
);
|
|
47467
|
+
const categories = getXmlNodeArray(entry.category).map(
|
|
47468
|
+
(category) => ({
|
|
47469
|
+
term: getXmlText(category["@_term"]),
|
|
47470
|
+
scheme: getXmlString(category["@_scheme"]),
|
|
47471
|
+
label: getXmlString(category["@_label"])
|
|
47472
|
+
})
|
|
47473
|
+
);
|
|
47474
|
+
const links = getXmlNodeArray(entry.link).map((link) => ({
|
|
47475
|
+
href: getXmlText(link["@_href"]),
|
|
47476
|
+
rel: getXmlString(link["@_rel"]),
|
|
47477
|
+
type: getXmlString(link["@_type"]),
|
|
47478
|
+
title: getXmlString(link["@_title"])
|
|
47442
47479
|
}));
|
|
47443
47480
|
const pdfLink = links.find(
|
|
47444
47481
|
(l) => l.title === "pdf" || l.type === "application/pdf"
|
|
47445
47482
|
);
|
|
47446
47483
|
const pdfUrl = pdfLink?.href;
|
|
47447
|
-
const primaryCategoryRaw = entry["arxiv:primary_category"];
|
|
47484
|
+
const primaryCategoryRaw = getXmlNode(entry["arxiv:primary_category"]);
|
|
47448
47485
|
const primaryCategory = primaryCategoryRaw ? {
|
|
47449
|
-
term:
|
|
47450
|
-
scheme: primaryCategoryRaw["@_scheme"]
|
|
47486
|
+
term: getXmlText(primaryCategoryRaw["@_term"]),
|
|
47487
|
+
scheme: getXmlString(primaryCategoryRaw["@_scheme"])
|
|
47451
47488
|
} : void 0;
|
|
47452
|
-
const fullId =
|
|
47489
|
+
const fullId = getXmlText(entry.id);
|
|
47453
47490
|
return {
|
|
47454
47491
|
id: fullId,
|
|
47455
47492
|
arxivId: extractArxivId(fullId),
|
|
47456
|
-
title:
|
|
47457
|
-
summary:
|
|
47493
|
+
title: getXmlText(entry.title).replace(/\s+/g, " ").trim(),
|
|
47494
|
+
summary: getXmlText(entry.summary).replace(/\s+/g, " ").trim(),
|
|
47458
47495
|
authors,
|
|
47459
47496
|
categories,
|
|
47460
47497
|
primaryCategory,
|
|
47461
|
-
published:
|
|
47462
|
-
updated:
|
|
47498
|
+
published: getXmlText(entry.published),
|
|
47499
|
+
updated: getXmlText(entry.updated),
|
|
47463
47500
|
links,
|
|
47464
47501
|
pdfUrl,
|
|
47465
|
-
doi: entry["arxiv:doi"],
|
|
47466
|
-
journalRef: entry["arxiv:journal_ref"],
|
|
47467
|
-
comment: entry["arxiv:comment"]
|
|
47502
|
+
doi: getXmlString(entry["arxiv:doi"]),
|
|
47503
|
+
journalRef: getXmlString(entry["arxiv:journal_ref"]),
|
|
47504
|
+
comment: getXmlString(entry["arxiv:comment"])
|
|
47468
47505
|
};
|
|
47469
47506
|
}
|
|
47470
47507
|
var ArxivApiClient = class {
|
|
@@ -47500,26 +47537,20 @@ var ArxivApiClient = class {
|
|
|
47500
47537
|
}
|
|
47501
47538
|
parseResponse(xml) {
|
|
47502
47539
|
const parsed = parser.parse(xml);
|
|
47503
|
-
const feed = parsed.feed;
|
|
47540
|
+
const feed = parsed.feed ?? {};
|
|
47504
47541
|
const totalResults = parseInt(
|
|
47505
|
-
|
|
47506
|
-
feed["opensearch:totalResults"]?.["#text"] ?? feed["opensearch:totalResults"] ?? "0"
|
|
47507
|
-
),
|
|
47542
|
+
getXmlText(feed["opensearch:totalResults"]) || "0",
|
|
47508
47543
|
10
|
|
47509
47544
|
);
|
|
47510
47545
|
const startIndex = parseInt(
|
|
47511
|
-
|
|
47512
|
-
feed["opensearch:startIndex"]?.["#text"] ?? feed["opensearch:startIndex"] ?? "0"
|
|
47513
|
-
),
|
|
47546
|
+
getXmlText(feed["opensearch:startIndex"]) || "0",
|
|
47514
47547
|
10
|
|
47515
47548
|
);
|
|
47516
47549
|
const itemsPerPage = parseInt(
|
|
47517
|
-
|
|
47518
|
-
feed["opensearch:itemsPerPage"]?.["#text"] ?? feed["opensearch:itemsPerPage"] ?? "0"
|
|
47519
|
-
),
|
|
47550
|
+
getXmlText(feed["opensearch:itemsPerPage"]) || "0",
|
|
47520
47551
|
10
|
|
47521
47552
|
);
|
|
47522
|
-
const rawEntries = feed.entry
|
|
47553
|
+
const rawEntries = getXmlNodeArray(feed.entry);
|
|
47523
47554
|
const papers = rawEntries.map(parsePaper);
|
|
47524
47555
|
return { totalResults, startIndex, itemsPerPage, papers };
|
|
47525
47556
|
}
|
|
@@ -47642,7 +47673,12 @@ async function handleArxivSearch(params) {
|
|
|
47642
47673
|
text: truncateToLimit(JSON.stringify(result, null, 2))
|
|
47643
47674
|
}
|
|
47644
47675
|
],
|
|
47645
|
-
structuredContent:
|
|
47676
|
+
structuredContent: {
|
|
47677
|
+
totalResults: result.totalResults,
|
|
47678
|
+
startIndex: result.startIndex,
|
|
47679
|
+
itemsPerPage: result.itemsPerPage,
|
|
47680
|
+
papers: result.papers
|
|
47681
|
+
}
|
|
47646
47682
|
};
|
|
47647
47683
|
}
|
|
47648
47684
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fre4x/arxiv",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.65-beta.1",
|
|
4
4
|
"description": "An arXiv MCP server for searching and retrieving academic papers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dev": "tsx src/index.ts",
|
|
18
18
|
"watch": "tsc -w",
|
|
19
19
|
"inspector": "npm run build && node ../scripts/run-official-inspector.mjs node dist/index.js",
|
|
20
|
-
"test": "vitest run --exclude dist"
|
|
20
|
+
"test": "node ../scripts/run-vitest.mjs run --exclude dist"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"mcp",
|