search_scihub
Search and download academic papers from Sci-Hub using DOI or URL. Automatically detects available mirrors and optionally saves PDF files to specified directories.
Instructions
Search and download papers from Sci-Hub using DOI or paper URL. Automatically detects and uses the fastest available mirror.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doiOrUrl | Yes | DOI (e.g., "10.1038/nature12373") or full paper URL | |
| downloadPdf | No | Whether to download the PDF file | |
| savePath | No | Directory to save the PDF file (if downloadPdf is true) |
Implementation Reference
- src/mcp/handleToolCall.ts:291-313 (handler)MCP tool handler for 'search_scihub': parses arguments, calls SciHubSearcher.search(), formats paper info response, optionally downloads PDF via SciHubSearcher.downloadPdf()case 'search_scihub': { const { doiOrUrl, downloadPdf, savePath } = args; const resolvedSavePath = savePath || './downloads'; const results = await searchers.scihub.search(doiOrUrl); if (results.length === 0) { return jsonTextResponse(`No paper found on Sci-Hub for: ${doiOrUrl}`); } const paper = results[0]; let responseText = `Found paper on Sci-Hub:\n\n${JSON.stringify(PaperFactory.toDict(paper), null, 2)}`; if (downloadPdf && paper.pdfUrl) { try { const filePath = await searchers.scihub.downloadPdf(doiOrUrl, { savePath: resolvedSavePath }); responseText += `\n\nPDF downloaded successfully to: ${filePath}`; } catch (downloadError: any) { responseText += `\n\nFailed to download PDF: ${downloadError.message}`; } } return jsonTextResponse(responseText); }
- src/mcp/tools.ts:314-337 (registration)Registers the 'search_scihub' tool with MCP SDK including name, description, and input schema{ name: 'search_scihub', description: 'Search and download papers from Sci-Hub using DOI or paper URL. Automatically detects and uses the fastest available mirror.', inputSchema: { type: 'object', properties: { doiOrUrl: { type: 'string', description: 'DOI (e.g., "10.1038/nature12373") or full paper URL' }, downloadPdf: { type: 'boolean', description: 'Whether to download the PDF file', default: false }, savePath: { type: 'string', description: 'Directory to save the PDF file (if downloadPdf is true)' } }, required: ['doiOrUrl'] } },
- src/mcp/schemas.ts:134-140 (schema)Zod schema definition for validating input arguments to the search_scihub toolexport const SearchSciHubSchema = z .object({ doiOrUrl: z.string().min(1), downloadPdf: z.boolean().optional().default(false), savePath: z.string().optional() }) .strip();
- Core search implementation in SciHubSearcher class: validates DOI/URL input, fetches paper metadata and PDF URL by scraping the fastest available Sci-Hub mirrorasync search(query: string, options?: SearchOptions): Promise<Paper[]> { // Sci-Hub 主要通过 DOI 或直接 URL 工作 // 如果输入不是 DOI 或 URL,返回空结果 if (!this.isValidDOIOrURL(query)) { return []; } try { const paperInfo = await this.fetchPaperInfo(query); if (paperInfo) { return [paperInfo]; } } catch (error) { logDebug('Sci-Hub search error:', error); } return []; }