研究论文MCP试剂
一个全面的模型上下文协议(MCP)服务器,集成了后端API和React前端,用于研究论文处理、摘要和分类。
项目概述
该项目由三个主要部分组成:
- MCP服务器 -处理基于LLM的论文分析的模型上下文协议服务器
- 后端API -Express.js服务器,协调纸张处理并与MCP集成
- 前端用户界面 -React应用程序为论文上传和分析提供用户界面
主要特点
- 📄 研究论文上传和处理
- 🤖 使用多个LLM提供商进行人工智能支持的摘要和分类
- 🔄 无缝集成MCP,实现智能决策
- 🎨 用于论文管理和分析的现代React UI
- 📊 实时处理与进度跟踪
- 🔌 多提供商LLM支持(OpenAI、Claude、Deepseek、Gemini)
- 💾 没有API密钥的开发模拟响应
建筑
┌─────────────────┐
│ Frontend UI │ (React 18, TypeScript, Vite)
│ Port: 5173 │
└────────┬────────┘
│ HTTP API calls
↓
┌─────────────────────────┐
│ Backend API Server │ (Express, TypeScript)
│ Port: 3000 │
└────────┬────────────────┘
│ HTTP calls
↓
┌─────────────────────────────┐
│ MCP Server │ (Node.js, Model Context Protocol)
│ Port: 3001 │ - Summarization
│ - PDF Processing │ - Categorization
│ - LLM Integration │ - JSON Response Parsing
└─────────────────────────────┘
│
↓
LLM Provider
(OpenAI / Claude / Deepseek / Gemini)
or Mock Responses项目结构
mcp-research-agent/
├── README.md # This file
├── ARCHITECTURE.md # Detailed architecture documentation
├── SETUP_GUIDE.md # Step-by-step setup instructions
├── .env.example # Example environment configuration
│
├── mcp-server/ # MCP Server
│ ├── src/
│ │ ├── index.ts # Express server & routes
│ │ ├── mcp/
│ │ │ ├── llmClient.ts # Multi-provider LLM client
│ │ │ ├── mcpController.ts # Summarization logic
│ │ │ └── paperAnalyzer.ts # Paper analysis utilities
│ │ └── paperProcessor.ts # PDF processing
│ ├── dist/ # Compiled JavaScript
│ ├── package.json
│ ├── tsconfig.json
│ └── .env # Environment variables (API keys)
│
├── backend/ # Backend API
│ ├── src/
│ │ ├── index.ts # Express server setup
│ │ ├── routes/
│ │ │ ├── papers.ts # Paper endpoints
│ │ │ └── analysis.ts # Analysis endpoints
│ │ ├── services/
│ │ │ ├── mcpClient.ts # MCP integration
│ │ │ └── paperService.ts # Paper business logic
│ │ └── middleware/
│ │ ├── errorHandler.ts # Error handling
│ │ └── logger.ts # Request logging
│ ├── dist/ # Compiled JavaScript
│ ├── package.json
│ ├── tsconfig.json
│ └── .env # Environment variables
│
└── frontend/ # React Frontend
├── src/
│ ├── main.tsx
│ ├── App.tsx
│ ├── components/
│ │ ├── PaperUpload.tsx # File upload component
│ │ ├── PaperList.tsx # Paper display
│ │ ├── AnalysisResults.tsx # Results view
│ │ └── common/ # Shared components
│ ├── services/
│ │ └── api.ts # API client
│ ├── styles/ # CSS modules
│ └── types/ # TypeScript interfaces
├── public/
├── package.json
├── tsconfig.json
├── vite.config.ts
└── .env # Environment variables先决条件
- Node.js 18.x或更高
- npm 8.x或更高
- python 3.8+(用于PDF处理工具)
- 以下之一(可选,用于真实的LLM响应):
- OpenAI API密钥 - Anthropic(Claude)API密钥 - 深度搜索API密钥 - Google Gemini API密钥
安装
1.克隆和设置项目
cd /path/to/mcp-research-agent
npm install2.安装服务依赖关系
# MCP Server
cd mcp-server
npm install
npm run build
# Backend
cd ../backend
npm install
npm run build
# Frontend
cd ../frontend
npm install3.配置环境变量
复制 .env.example 到 .env 在每个服务目录中:
# MCP Server configuration
cp .env.example mcp-server/.env
# Backend configuration
cp .env.example backend/.env
# Frontend configuration
cp .env.example frontend/.env编辑每个 .env 使用您的配置文件:
mcp服务器/.env:
MCP_PORT=3001
# Choose ONE LLM provider by uncommenting and setting its API key
# The MCP will automatically detect which provider is available
# ===== OpenAI =====
# OPENAI_API_KEY=your-key-here
# OPENAI_MODEL=gpt-3.5-turbo
# ===== Claude (Anthropic) =====
# ANTHROPIC_API_KEY=your-key-here
# CLAUDE_MODEL=claude-3-5-sonnet-20241022
# ===== Deepseek =====
# DEEPSEEK_API_KEY=your-key-here
# DEEPSEEK_MODEL=deepseek-chat
# ===== Gemini =====
# GEMINI_API_KEY=your-key-here
# GEMINI_MODEL=gemini-pro后端/.env:
PORT=3000
MCP_URL=http://localhost:3001
DATABASE_URL=postgresql://user:password@localhost:5432/research_papers
NODE_ENV=development前端/.env:
VITE_API_URL=http://localhost:3000/api运行服务
选项1:在一个命令中运行所有服务
# From the project root
npm start这将与正确的日志记录并行启动所有三个服务。
选项2:在单独的终端中运行每个服务
终端1-MCP服务器:
cd mcp-server
npm start
# Output: MCP Server listening on port 3001终端2-后端API:
cd backend
npm start
# Output: Backend Server running on port 30003号航站楼-前端:
cd frontend
npm run dev
# Output: Local: http://localhost:5173选项3:使用Docker运行
# Build Docker images
docker-compose build
# Start all services
docker-compose up
# In separate terminal for logs
docker-compose logs -fAPI终点
MCP服务器(端口3001)
| 端点 | 方法 | 描述 |
|---|---|---|
/mcp/info | GET | 获取MCP服务器信息和可用的LLM提供程序 |
/mcp/summarize | POST | 总结和分类论文文本 |
/mcp/analyze | POST | 在纸上进行详细分析 |
POST/mcp/总结
curl -X POST http://localhost:3001/mcp/summarize \
-H "Content-Type: application/json" \
-d '{
"fullText": "Research paper content here...",
"title": "Paper Title"
}'答复:
{
"title": "Paper Title",
"summary": "Concise summary of the paper...",
"categories": ["Machine Learning", "NLP"],
"confidence": 0.95
}后端API(端口3000)
| 端点 | 方法 | 描述 |
|---|---|---|
/api/papers | GET | 列出所有论文 |
/api/papers | POST | 上传新论文 |
/api/papers/:id | 获取 | 获取论文详细信息 |
/api/papers/:id/analyze | POST | 纸质触发器分析 |
/api/analysis/:id | GET | 获取分析结果 |
前端(端口5173)
- 上传页面:上传PDF格式的研究论文
- 论文列表:查看所有上传的论文
- 分析视图:参见总结和分类结果
- 实时状态:监控处理进度
开发工作流程
建筑
# MCP Server
cd mcp-server && npm run build
# Backend
cd backend && npm run build
# Frontend
cd frontend && npm run build测试
# MCP Server tests
cd mcp-server && npm test
# Backend tests
cd backend && npm test
# Frontend tests
cd frontend && npm run test观看模式(用于开发)
# MCP Server - auto-rebuild on changes
cd mcp-server && npm run dev
# Backend - auto-rebuild and restart
cd backend && npm run dev
# Frontend - hot module replacement
cd frontend && npm run devLLM提供程序配置
使用模拟响应(不需要API密钥)
默认情况下,如果没有配置LLM API键,系统将使用模拟响应。这非常适合开发和测试。
使用真正的LLM提供者
系统会自动检测并使用此优先级中的第一个配置的提供程序:
- 克劳德(人类学) -可用免费积分:https://console.anthropic.com
- 深度求索 -非常便宜(每100万代币约0.14美元):https://platform.deepseek.com
- 双子座(谷歌) -免费套餐:https://aistudio.google.com
- 开放人工智能 -仅支付:https://platform.openai.com
要启用提供程序,请执行以下操作:
- 从提供程序获取API密钥
- 将其添加到您的
mcp-server/.env文件 - 重新启动MCP服务器
示例(使用Gemini):
GEMINI_API_KEY=AIzaSyB-xxxxxxxxxxxxx
GEMINI_MODEL=gemini-pro故障排除
端口已在使用中
# Kill process on port 3001
lsof -ti:3001 | xargs kill -9
# Kill process on port 3000
lsof -ti:3000 | xargs kill -9
# Kill process on port 5173
lsof -ti:5173 | xargs kill -9CORS错误
确保后端正在运行,并且前端中的VITE_API_URL与后端端口(3000)匹配。
LLM API错误
- 检查
.env文件具有有效的API密钥格式 - 验证API密钥是否具有足够的信用/权限
- 检查与LLM提供程序的网络连接
- 查看日志中的特定错误消息
构建错误
# Clean build
rm -rf dist
npm run build
# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
npm run build环境变量引用
MCP服务器
MCP_PORT-服务器端口(默认:3001)OPENAI_API_KEY-OpenAI API密钥OPENAI_MODEL-OpenAI模型名称ANTHROPIC_API_KEY-API密钥CLAUDE_MODEL-克劳德型号名称DEEPSEEK_API_KEY-深度搜索API密钥DEEPSEEK_MODEL-Deepseek模型名称GEMINI_API_KEY-Google Gemini API密钥GEMINI_MODEL-Gemini型号名称
后端
PORT-服务器端口(默认值:3000)MCP_URL-MCP服务器URLDATABASE_URL-PostgreSQL连接字符串NODE_ENV-环境(开发/生产)
前端
VITE_API_URL-后端API基本URL
性能优化
- 模拟响应:用于快速开发(即时响应)
- 双子座免费套餐:适合用真正的LLM进行测试
- 缓存:后端缓存摘要结果
- 延迟加载:前端延迟加载纸张列表
贡献
- 创建要素分支
- 做出改变
- 运行测试和构建
- 提交拉取请求
许可证
麻省理工学院
支持
有关问题和疑问,请参阅详细文档:
- 看
ARCHITECTURE.md技术深潜 - 看
SETUP_GUIDE.md有关详细的设置说明 - 检查
mcp-server/有关LLM集成的详细信息
