深度研究 MCP
📚 概述
DeepResearch MCP 是一款基于模型上下文协议 (MCP) 构建的强大研究助手。它通过网络搜索、分析和综合报告生成,对任何主题进行智能迭代研究。
🌟 主要特点
- 智能主题探索——自动识别知识差距并生成重点搜索查询
- 全面的内容提取——增强网页抓取功能,改进内容组织
- 结构化知识处理——在管理令牌使用的同时保留重要信息
- 学术报告生成——创建包含执行摘要、分析和可视化内容的详细、结构良好的报告
- 完整的参考书目- 正确引用所有来源并附有编号
- 自适应内容管理- 自动管理内容以保持在令牌限制内
- 错误恢复——当无法进行完整处理时,从错误中恢复并生成部分报告
🛠️ 建筑
┌────────────────────┐ ┌─────────────────┐ ┌────────────────┐
│ │ │ │ │ │
│ MCP Server Layer ├────►│ Research Service├────►│ Search Service │
│ (Tools & Prompts) │ │ (Session Mgmt) │ │ (Firecrawl) │
│ │ │ │ │ │
└────────────────────┘ └─────────┬───────┘ └────────────────┘
│
▼
┌─────────────────┐
│ │
│ OpenAI Service │
│ (Analysis/Rpt) │
│ │
└─────────────────┘
💻安装
先决条件
- Node.js 18 或更高版本
- OpenAI API 密钥
- Firecrawl API 密钥
设置步骤
- 克隆存储库
git clone <repository-url>
cd deep-research-mcp
- 安装依赖项
- 配置环境变量编辑
.env
文件并添加您的 API 密钥:OPENAI_API_KEY=sk-your-openai-api-key
FIRECRAWL_API_KEY=your-firecrawl-api-key
- 构建项目
🚀 使用方法
运行 MCP 服务器
在 stdio 上启动服务器以进行 MCP 客户端连接:
使用示例客户端
对特定主题进行指定深度的研究:
npm run client "Your research topic" 3
参数:
- 第一个参数:研究主题或查询
- 第二个参数:研究深度(迭代次数,默认值:2)
- 第三个参数(可选):“complete” 使用完整研究工具(一步过程)
例子:
npm run client "the impact of climate change on coral reefs" 3 complete
示例输出
DeepResearch MCP 将生成一份综合报告,其中包括:
- 执行摘要——研究结果的简要概述
- 引言——研究主题的背景和重要性
- 方法论——研究方法的描述
- 综合分析——对主题进行详细检查
- 比较分析——关键方面的视觉比较
- 讨论——研究结果和含义的解释
- 局限性——研究中的制约因素和差距
- 结论- 最终见解和建议
- 参考书目- 包含 URL 的完整来源列表
🔧 MCP 集成
可用的 MCP 资源
资源路径 | 描述 |
---|
research://state/{sessionId} | 访问研究会话的当前状态 |
research://findings/{sessionId} | 访问会话收集到的结果 |
可用的 MCP 工具
工具名称 | 描述 | 参数 |
---|
initialize-research | 开始新的研究会话 | query :字符串, depth :数字 |
execute-research-step | 执行下一步研究 | sessionId :字符串 |
generate-report | 创建最终报告 | sessionId :字符串, timeout :数字(可选) |
complete-research | 执行整个研究过程 | query :字符串, depth :数字, timeout :数字(可选) |
🖥️ Claude 桌面集成
DeepResearch MCP 可以与 Claude Desktop 集成,为 Claude 提供直接研究能力。
配置步骤
- 复制示例配置
cp claude_desktop_config_sample.json ~/path/to/claude/desktop/config/directory/claude_desktop_config.json
- 编辑配置文件更新路径以指向 deep-research-mcp 的安装并添加您的 API 密钥:
{
"mcpServers": {
"deep-research": {
"command": "node",
"args": [
"/absolute/path/to/your/deep-research-mcp/dist/index.js"
],
"env": {
"FIRECRAWL_API_KEY": "your-firecrawler-api-key",
"OPENAI_API_KEY": "your-openai-api-key"
}
}
}
}
- 重启Claude桌面保存配置后,重新启动 Claude Desktop 以使更改生效。
- 与 Claude Desktop 一起使用现在你可以要求 Claude 使用以下命令进行研究:
Can you research the impact of climate change on coral reefs and provide a detailed report?
📋 示例客户端代码
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
async function main() {
// Connect to the server
const transport = new StdioClientTransport({
command: "node",
args: ["dist/index.js"]
});
const client = new Client({ name: "deep-research-client", version: "1.0.0" });
await client.connect(transport);
// Initialize research
const initResult = await client.callTool({
name: "initialize-research",
arguments: {
query: "The impact of artificial intelligence on healthcare",
depth: 3
}
});
// Parse the response to get sessionId
const { sessionId } = JSON.parse(initResult.content[0].text);
// Execute steps until complete
let currentDepth = 0;
while (currentDepth < 3) {
const stepResult = await client.callTool({
name: "execute-research-step",
arguments: { sessionId }
});
const stepInfo = JSON.parse(stepResult.content[0].text);
currentDepth = stepInfo.currentDepth;
console.log(`Completed step ${stepInfo.currentDepth}/${stepInfo.maxDepth}`);
}
// Generate final report with timeout
const report = await client.callTool({
name: "generate-report",
arguments: {
sessionId,
timeout: 180000 // 3 minutes timeout
}
});
console.log("Final Report:");
console.log(report.content[0].text);
}
main().catch(console.error);
🔍 故障排除
常见问题
- 超出令牌限制:对于非常大的研究主题,您可能会遇到 OpenAI 令牌限制错误。请尝试:
- 降低研究深度
- 使用更具体的查询
- 将复杂的主题分解成更小的子主题
- 超时错误:对于复杂的研究,该过程可能会超时。解决方案:
- 增加工具调用中的超时参数
- 使用超时时间较长的
complete-research
工具 - 以更小的块进行研究
- API 速率限制:如果您遇到来自 OpenAI 或 Firecrawl 的速率限制错误:
- 在研究步骤之间实施延迟
- 使用具有更高速率限制的 API 密钥
- 使用指数退避算法重试
📝 许可证
国际学习中心
🙏 致谢