使用说明
研究MCP服务器
基于FastMCP的模型上下文协议(MCP)服务器,用于搜索和管理arXiv的学术论文。此服务器演示了如何使用工具、资源和提示模板构建MCP服务器。
特性
工具
- 搜索路径:在arXiv中搜索特定主题的论文,并将元数据存储在本地
- 提取信息:按ID检索特定论文的详细元数据
资源
- papers://folders:列出所有可用的研究主题文件夹
- 论文://{主题}:获取特定研究主题的所有论文
提示模板
- generate_search_prompt:生成一个结构化的提示,以指导对特定主题的研究
安装
-
克隆或下载此项目
-
安装依赖项:
pip install -r requirements.txt
运行服务器
单独模式
直接运行服务器:
python research_server.py
使用克劳德桌面
将服务器添加到您的Claude Desktop配置中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
配置:
{
"mcpServers": {
"research": {
"command": "python",
"args": [
"/absolute/path/to/research_server.py"
]
}
}
}
替换 /absolute/path/to/research_server.py 使用文件的实际路径。
使用Python客户端
快速开始
运行交互式演示:
python example_usage.py
这将向您展示一个包含各种示例的交互式菜单。
基本客户端使用
from research_client import ResearchClient
import asyncio
async def main():
client = ResearchClient()
# Connect to the server
await client.connect("./research_server.py")
# Search for papers
paper_ids = await client.search_papers("machine learning", max_results=5)
# Get detailed information
for paper_id in paper_ids:
await client.extract_info(paper_id)
# Browse topics
await client.get_folders()
# Close connection
await client.close()
asyncio.run(main())
可用客户端方法
连接
connect(server_script_path)-连接到MCP服务器close()-关闭连接
工具
search_papers(topic, max_results)-搜索某一主题的论文extract_info(paper_id)-获取有关论文的详细信息
资源
get_folders()-列出所有研究主题文件夹get_topic_papers(topic)-获取特定主题的所有论文
提示
get_search_prompt(topic, num_papers)-生成搜索提示模板
发现
list_tools()-列出所有可用工具list_resources()-列出所有可用资源list_prompts()-列出所有可用的提示模板
使用示例
示例1:文献综述
from research_client import ResearchClient
import asyncio
async def literature_review():
client = ResearchClient()
await client.connect("./research_server.py")
# Search for papers
paper_ids = await client.search_papers("neural networks", max_results=5)
# Get details for each paper
for paper_id in paper_ids:
paper = await client.extract_info(paper_id)
print(f"Title: {paper['title']}")
print(f"Authors: {', '.join(paper['authors'])}")
await client.close()
asyncio.run(literature_review())
示例2:比较主题
async def compare_topics():
client = ResearchClient()
await client.connect("./research_server.py")
topics = ["deep learning", "machine learning", "AI"]
for topic in topics:
await client.search_papers(topic, max_results=3)
# View all collected topics
folders = await client.get_folders()
await client.close()
asyncio.run(compare_topics())
示例3:交互式菜单(推荐)
python example_usage.py
从以下选项中选择:
- 文献综述-搜索和分析某一主题的论文
- 比较多个主题-比较不同领域的论文
- 深潜-获取特定论文的全面细节
- 浏览资源-探索存储的研究数据
- 生成研究提示-创建结构化的研究提示
- 运行所有示例-按顺序执行所有示例
与Claude Desktop一起使用
使用Claude Desktop配置时,您可以使用自然语言:
- 搜索论文:
Use the search_papers tool to find papers about "machine learning"
- 获取纸张详细信息:
Use the extract_info tool to get details for paper ID "2301.12345"
- 列出所有主题:
Show me the papers://folders resource
- 查看某个主题的论文:
Show me papers://machine_learning
- 使用提示模板:
Use the generate_search_prompt template for "quantum computing" with 10 papers
项目结构
MCP_server/
├── research_server.py # Main MCP server implementation
├── research_client.py # Python client for the MCP server
├── example_usage.py # Interactive examples and demos
├── requirements.txt # Python dependencies
├── README.md # This file
├── .gitignore # Git ignore rules
├── .claude_mcp_config.json # Example MCP configuration
└── data/
└── papers/ # Storage for paper metadata
├── topic1/ # Papers organized by topic
├── topic2/
└── ...
运作原理
建筑
该项目由两个主要部分组成:
-
MCP服务器 (
research_server.py)- 采用FastMCP框架构建
- 显示工具、资源和提示模板
- 处理arXiv API通信
- 管理本地纸张存储
-
Python客户端 (
research_client.py)- 通过stdio连接到MCP服务器
- 提供异步方法来调用工具和访问资源
- 处理JSON解析和格式化
- 管理连接生命周期
搜索论文工具
- 获取主题并搜索arXiv的API
- 解析XML响应以提取论文元数据
- 将论文本地存储在特定主题的文件夹中
- 返回找到的纸张ID列表
提取信息工具
- 按ID在本地存储中搜索纸张
- 返回完整的元数据,包括:
- 标题和作者
- 摘要/总结
- 出版日期
- PDF链接
资源
资源提供对存储数据的只读访问:
- 列出你探索过的所有研究主题
- 查看特定主题下的所有论文
提示模板
可重复使用的提示,指导AI:
- 搜索某一主题的论文
- 提取并分析纸张详细信息
- 提供结构化的总结和建议
客户端-服务器通信
- 客户端将服务器作为子进程生成
- 通过JSON-RPC在stdio上进行通信
- 客户端发送工具调用、资源请求和提示查询
- 服务器处理请求并返回结构化响应
- 客户端解析并呈现结果
数据存储
所有纸质元数据都以JSON格式存储在本地:
- 地点:
data/papers/{topic}/{paper_id}.json - 格式:JSON,包括标题、作者、摘要、出版日期和PDF链接
API 参考
search_papers(主题:str,max_results:int=5)->列表[str]
搜索arXiv并存储纸张元数据。
参数:
topic:要搜索的研究主题max_results:要检索的最大论文数(默认值:5)
退货: 纸张ID列表
extract_info(paper_id:str)->str
获取特定论文的元数据。
参数:
paper_id:arXiv纸张ID(例如“2301.12345”)
退货: 带纸质元数据的JSON字符串
资源:papers://folders
列出所有包含纸张计数的主题文件夹。
退货: 带有主题和计数的JSON
资源:论文://{主题}
获取特定主题的所有论文。
参数:
topic:主题名称
退货: JSON,包含主题中的所有论文
generate_search_prompt(主题:str,num_papers:int=5)->str
生成研究提示。
参数:
topic:研究主题num_papers:要搜索的论文数(默认值:5)
退货: 格式化提示字符串
故障排除
服务器问题
服务器无法启动
- 确保安装了所有依赖项:
pip install -r requirements.txt - 检查Python版本(需要3.8+)
- 验证服务器脚本路径是否正确
未找到文件
- 请确保您首先使用以下工具搜索了论文
search_papers - 检查一下
data/papers目录存在并且具有写入权限
arXiv API错误
- arXiv API有费率限制;在搜索之间等待几秒钟
- 检查您的互联网连接
- 验证arXiv API是否可访问(尝试访问http://export.arxiv.org/api/query在浏览器中)
客户问题
连接错误
- 确保中的服务器脚本路径
connect()是正确和绝对的 - 检查Python是否在您的PATH中
- 验证没有其他进程正在使用服务器
异步运行时错误
- 确保您正在运行客户端代码
asyncio.run() - 没有适当的wait语句,不要混合使用async和sync代码
JSON解析错误
- 检查服务器是否返回有效的JSON
- 确保您使用的是最新版本的客户端
- 首先尝试独立运行服务器以验证其是否正常工作
导入错误
- 安装所有依赖项:
pip install -r requirements.txt - 验证您是否在正确的目录中
- 检查Python路径和虚拟环境
贡献
请随时使用其他功能扩展此服务器:
- 支持其他学术数据库(PubMed、Semantic Scholar)
- 纸张相似性分析
- 引文图可视化
- 自动生成文献综述
许可证
MIT许可证-您可以自由使用和修改您的项目。