@@ -19,7 +19,7 @@ import fs from "node:fs/promises";
1919import path from "node:path" ;
2020import { z } from "zod" ;
2121
22- import { buildPdfIndex , findEntryByUrl , createEntry , isArxivUrl , isFileUrl , toFileUrl } from "./src/pdf-indexer.js" ;
22+ import { buildPdfIndex , findEntryByUrl , createEntry , isArxivUrl , isFileUrl , toFileUrl , normalizeArxivUrl } from "./src/pdf-indexer.js" ;
2323import { loadPdfBytesChunk , populatePdfMetadata } from "./src/pdf-loader.js" ;
2424import { ReadPdfBytesInputSchema , PdfBytesChunkSchema , type PdfIndex } from "./src/types.js" ;
2525import { startServer } from "./server-utils.js" ;
@@ -86,13 +86,15 @@ export function createServer(): McpServer {
8686 } ) ,
8787 _meta : { ui : { resourceUri : RESOURCE_URI } } ,
8888 } ,
89- async ( { url, page } ) : Promise < CallToolResult > => {
89+ async ( { url : rawUrl , page } ) : Promise < CallToolResult > => {
9090 if ( ! pdfIndex ) throw new Error ( "Not initialized" ) ;
9191
92+ // Normalize arxiv URLs to PDF format
93+ const url = isArxivUrl ( rawUrl ) ? normalizeArxivUrl ( rawUrl ) : rawUrl ;
94+
9295 let entry = findEntryByUrl ( pdfIndex , url ) ;
9396
9497 if ( ! entry ) {
95- // Dynamic loading: only arxiv.org allowed
9698 if ( isFileUrl ( url ) ) {
9799 throw new Error ( "File URLs must be in the initial list" ) ;
98100 }
@@ -144,12 +146,14 @@ function parseArgs(): { urls: string[]; stdio: boolean } {
144146 if ( arg === "--stdio" ) {
145147 stdio = true ;
146148 } else if ( ! arg . startsWith ( "-" ) ) {
147- // Convert local paths to file:// URLs
148- if ( arg . startsWith ( "http://" ) || arg . startsWith ( "https://" ) || arg . startsWith ( "file://" ) ) {
149- urls . push ( arg ) ;
150- } else {
151- urls . push ( toFileUrl ( arg ) ) ;
149+ // Convert local paths to file:// URLs, normalize arxiv URLs
150+ let url = arg ;
151+ if ( ! arg . startsWith ( "http://" ) && ! arg . startsWith ( "https://" ) && ! arg . startsWith ( "file://" ) ) {
152+ url = toFileUrl ( arg ) ;
153+ } else if ( isArxivUrl ( arg ) ) {
154+ url = normalizeArxivUrl ( arg ) ;
152155 }
156+ urls . push ( url ) ;
153157 }
154158 }
155159
0 commit comments