Skip to content

Commit 70d360e

Browse files
committed
pdf-server: dynamically add arxiv URLs in read_pdf_bytes
Fixes 'PDF not found' error when server restarts between display_pdf (which adds the entry) and read_pdf_bytes (which previously only looked up existing entries). Now read_pdf_bytes mirrors display_pdf's logic and dynamically adds arxiv URLs to the index.
1 parent 7347cf2 commit 70d360e

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

examples/pdf-server/server.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,20 @@ export function createServer(): McpServer {
8383
byteCount,
8484
} = ReadPdfBytesInputSchema.parse(args);
8585
const url = isArxivUrl(rawUrl) ? normalizeArxivUrl(rawUrl) : rawUrl;
86-
const entry = findEntryByUrl(pdfIndex, url);
87-
if (!entry) throw new Error(`PDF not found: ${url}`);
86+
let entry = findEntryByUrl(pdfIndex, url);
87+
88+
// Dynamically add arxiv URLs (handles server restart between display_pdf and read_pdf_bytes)
89+
if (!entry) {
90+
if (isFileUrl(url)) {
91+
throw new Error("File URLs must be in the initial list");
92+
}
93+
if (!isArxivUrl(url)) {
94+
throw new Error(`PDF not found: ${url}`);
95+
}
96+
entry = createEntry(url);
97+
await populatePdfMetadata(entry);
98+
pdfIndex.entries.push(entry);
99+
}
88100

89101
const chunk = await loadPdfBytesChunk(entry, offset, byteCount);
90102
return {

0 commit comments

Comments
 (0)