search_arxiv
Search for arXiv research papers using keywords and retrieve relevant results, including PDF links, to streamline access to scientific literature.
Instructions
搜索 arXiv 论文
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | 最大结果数量 | |
| query | Yes | 搜索英文关键词 |
Implementation Reference
- src/index.ts:34-68 (handler)Core handler function implementing the logic to search arXiv papers using ArXivClient, process entries, and return formatted results.async function searchArxivPapers(query: string, maxResults: number = 5): Promise<{totalResults: number, papers: any[]}> { try { const results = await arxivClient.search({ start: 0, searchQuery: { include: [ { field: "all", value: query } ] }, maxResults: maxResults }); const papers = results.entries.map(entry => { const urlParts = entry.url.split('/'); const arxivId = urlParts[urlParts.length - 1]; return { id: arxivId, url: entry.url, title: entry.title.replace(/\s+/g, ' ').trim(), summary: entry.summary.replace(/\s+/g, ' ').trim(), published: entry.published, authors: entry.authors || [] }; }); return { totalResults: results.totalResults, papers: papers }; } catch (error) { console.error("搜索 arXiv 论文时出错:", error); throw new Error(`搜索失败: ${error instanceof Error ? error.message : String(error)}`); } }
- src/index.ts:327-341 (schema)Input schema defining the parameters for the search_arxiv tool: required 'query' string and optional 'maxResults' number.inputSchema: { type: "object", properties: { query: { type: "string", description: "搜索英文关键词" }, maxResults: { type: "number", description: "最大结果数量", default: 5 } }, required: ["query"] }
- src/index.ts:324-342 (registration)Tool registration entry in the ListToolsRequest handler, including name, description, and input schema.{ name: "search_arxiv", description: "搜索 arXiv 论文", inputSchema: { type: "object", properties: { query: { type: "string", description: "搜索英文关键词" }, maxResults: { type: "number", description: "最大结果数量", default: 5 } }, required: ["query"] } },
- src/index.ts:400-412 (registration)Registration and dispatch logic in the CallToolRequest handler, extracting arguments, calling the search handler, formatting output, and returning MCP content.case "search_arxiv": { const { query, maxResults = 5 } = args as { query: string; maxResults?: number }; const results = await searchArxivPapers(query, maxResults); return { content: [{ type: "text", text: `找到 ${results.papers.length} 篇相关论文(总计 ${results.totalResults} 篇):\n\n${results.papers.map((paper, index) => `${index + 1}. **${paper.title}**\n ID: ${paper.id}\n 发布日期: ${paper.published}\n 作者: ${paper.authors.map((author: any) => author.name || author).join(', ')}\n 摘要: ${paper.summary.substring(0, 300)}...\n URL: ${paper.url}\n` ).join('\n')}` }] }; }