MCP 服务器:Ollama 深度研究员
这是LangChain Ollama 深度研究员的模型上下文协议 (MCP) 服务器适配版。它提供作为 MCP 工具的深度研究功能,可在模型上下文协议生态系统中使用,允许 AI 助手通过 Ollama 使用本地 LLM 对主题进行深入研究。
核心功能
该服务器通过 MCP 工具和资源提供研究能力,使用由Ollama托管的任何 LLM。
研究过程
给定一个主题,它将:
- 生成网络搜索查询
- 通过Tavily或Perplexity API收集网络搜索结果
- 汇总搜索结果
- 反思总结,检查知识差距
- 生成新的搜索查询来弥补差距
- 通过多个研究周期反复改进摘要
- 提供最终的 markdown 摘要,其中包含所有使用的来源
先决条件
- Node.js(用于运行 MCP 服务器)
- Python 3.10 或更高版本
- 能够运行您选择的 Ollama 模型的计算(CPU/GPU)
- 至少 8GB RAM 用于运行更大的语言模型
- 所需的 API 密钥:
确保你能从终端/命令提示符运行 Node.js 和 npm。你可以使用以下命令验证安装:
node --version
npm --version
python --version
如果这些命令失败,您可能需要:
- 安装后重新启动终端/计算机
- 将 Node.js 添加到您的系统 PATH:
- Windows:编辑系统环境变量 → 环境变量 → Path → 添加 Node.js 安装目录
- macOS/Linux:通常由安装程序处理
安装
选项 1:标准安装
- 为您的平台下载并安装Ollama
- 克隆此存储库并安装依赖项:
git clone https://github.com/Cam10001110101/mcp-server-ollama-deep-researcher
cd mcp-server-ollama-deep-researcher
npm install
- 安装 Python 依赖项:
首先,安装 uv(建议安装以获得更好的性能和依赖性解析):
# Windows
pip install uv
# macOS/Linux
pip3 install uv
然后使用 pyproject.toml 安装项目依赖项:
注意:这将以可编辑模式安装项目,并包含 pyproject.toml 中指定的所有依赖项。如果您更喜欢 pip:
pip install . # Windows
pip3 install . # macOS/Linux
- 构建 TypeScript 代码:
- 从Ollama获得本地 LLM 学位:
ollama pull deepseek-r1:8b
选项 2:Docker 安装
您还可以使用 Docker 运行 MCP 服务器,从而简化设置过程。
- 下载并安装适合您平台的Docker
- 克隆此存储库:
git clone https://github.com/Cam10001110101/mcp-server-ollama-deep-researcher
cd mcp-server-ollama-deep-researcher
- 使用您的 API 密钥创建一个
.env
文件(您可以从.env.example
复制):
cp .env.example .env
# Edit the .env file with your API keys
- 使帮助脚本可执行:
- 构建并运行 Docker 容器:
- 确保 Ollama 在您的主机上运行:
ollama pull deepseek-r1:8b # or your preferred model
ollama serve
帮助脚本提供了几个命令:
对于 macOS/Linux(使用 run-docker.sh):
./run-docker.sh start
- 构建并启动 Docker 容器./run-docker.sh stop
停止Docker容器./run-docker.sh restart
重新启动 Docker 容器./run-docker.sh logs
- 显示来自 Docker 容器的日志./run-docker.sh status
- 检查 Docker 容器的状态./run-docker.sh help
显示帮助信息
对于 Windows(使用 run-docker.bat):
run-docker.bat start
- 构建并启动 Docker 容器run-docker.bat stop
- 停止 Docker 容器run-docker.bat restart
- 重新启动 Docker 容器run-docker.bat logs
- 显示来自 Docker 容器的日志run-docker.bat status
- 检查 Docker 容器的状态run-docker.bat help
- 显示帮助信息
注意:Docker 容器已配置为连接到主机上运行的 Ollama。如果您也想在容器中运行 Ollama,请在 docker-compose.yml 文件中取消注释 Ollama 服务。
客户端配置
将服务器添加到您的 MCP 客户端配置:
对于 Claude 桌面应用程序:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
对于 Cline(VS 代码扩展):
- Windows:
%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
- macOS:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
- Linux:
~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
选项 1:标准安装配置
{
"mcpServers": {
"ollama-deep-researcher": {
"command": "node",
"args": ["path/to/mcp-server-ollama-deep-researcher/build/index.js"],
"env": {
"LANGSMITH_TRACING": "true",
"LANGSMITH_ENDPOINT": "https://api.smith.langchain.com",
"LANGSMITH_API_KEY": "your-langsmith-key",
"LANGSMITH_PROJECT": "ollama-deep-researcher-mcp-server",
"TAVILY_API_KEY": "your-tavily-key", // Include tvly- prefix
"PERPLEXITY_API_KEY": "your-perplexity-key",
"PYTHONPATH": "path/to/mcp-server-ollama-deep-researcher/src"
}
}
}
}
注意:用系统的绝对路径替换路径:
- Windows:使用
C:\\Users\\username\\path\\to\\mcp-server-ollama-deep-researcher
- macOS/Linux:使用
/Users/username/path/to/mcp-server-ollama-deep-researcher
对于 macOS/Linux,您可能还需要添加:
选项 2:Docker 安装配置
如果您正在使用 Docker 容器,则可以配置 MCP 客户端以连接到正在运行的容器:
{
"mcpServers": {
"ollama-deep-researcher": {
"command": "docker",
"args": ["exec", "-i", "ollama-deep-researcher-mcp", "node", "build/index.js"],
"env": {}
}
}
}
此配置假设 Docker 容器正在运行。环境变量已在 Docker 容器中设置,因此您无需在 MCP 客户端配置中指定它们。
追踪与监控
该服务器与 LangSmith 集成,可全面跟踪和监控研究过程:
- 操作追踪:
- 所有 LLM 互动均有记录
- 网络搜索操作受到监控
- 跟踪研究工作流程步骤
- 性能监控:
- 调试和优化:
使用您配置的项目名称访问https://smith.langchain.com上的所有跟踪。
MCP 资源
研究结果自动存储为 MCP 资源,从而实现:
- 持久访问
- 可通过
research://{topic}
URI 访问结果 - 自动存储已完成的研究
- 带有元数据的 JSON 格式内容
- 资源面板集成
- 研究成果出现在 MCP 客户端的资源面板中
- 轻松访问过去的研究主题
- 每个结果的时间戳和描述
- 上下文管理
- 在对话中有效地重复使用研究成果
- 通过资源引用减少令牌使用
- 选择性纳入研究背景
可用工具
配置
- maxLoops :研究迭代次数(1-5)
- llmModel :要使用的 Ollama 模型(例如,“deepseek-r1:1.5b”、“llama3.2”)
- searchApi :要使用的搜索 API(“perplexity”或“tavily”)
配置研究参数。
{
"name": "configure",
"arguments": {
"maxLoops": 3,
"llmModel": "deepseek-r1:1.5b",
"searchApi": "tavily"
}
}
研究
使用网络搜索和 LLM 综合研究任何主题。
{
"name": "research",
"arguments": {
"topic": "Austin LangChain, aimug.org"
}
}
获取状态
了解正在进行的研究的当前状态。
{
"name": "get_status",
"arguments": {
"_dummy": "dummy"
}
}
提示
使用默认搜索 API、模型和最大迭代次数(循环)
提示示例:“研究 AI-First 应用程序”
更改默认配置并开始研究
语法: configure with <searchapi> and <model> then research <topic>
提示示例:“使用 perplexity 和 deepseek-r1:8b 进行配置,然后研究 AI-First 应用程序”
Ollama 研究工作流程
研究过程受到IterDRAG的启发。此方法将查询分解为子查询,检索每个子查询的文档,回答子查询,然后通过检索第二个子查询的文档来构建答案。
该过程的工作原理如下:
- 给定用户提供的主题,使用本地 LLM(通过Ollama )生成网络搜索查询
- 使用搜索引擎(为Tavily配置)查找相关来源
- 使用 LLM 总结与用户提供的研究主题相关的网络搜索结果
- 然后,利用法学硕士(LLM)来反思总结,找出知识差距
- 它生成一个新的搜索查询来解决知识差距
- 该过程不断重复,摘要会根据来自网络搜索的新信息进行迭代更新
- 它将在研究兔子洞中重复
- 运行可配置的迭代次数
输出
输出是一个 markdown 文件,其中包含研究摘要,以及研究过程中使用的所有来源的引用。
研究期间收集的所有来源均会保留,并可在最终输出中引用:
系统集成概述
故障排除
以下是您可能遇到的常见问题的解决方案:
Ollama连接问题
- 确保 Ollama 正在运行:在终端中执行
ollama list
- 尝试通过关闭应用程序(系统托盘/菜单栏)在终端模式下运行 ollama,然后执行
ollama serve
- 检查是否可以通过
localhost:11434
、 0.0.0.0:11434
或127.0.0.1:11434
访问 Ollama
API 密钥问题
- 验证您的 API 密钥是否在配置文件中正确设置
- 验证您的路径参数是否指向此 repo 中 index.js 的实际位置
- 确保 API 密钥周围没有多余的空格或引号
- 检查您的 API 密钥是否具有足够的信用/权限
MCP 服务器问题
npx @modelcontextprotocol/inspector node path/to/server/index.js --model llama3.2 --max-loops 3 --search-api tavily
Docker 问题
- 如果您遇到 Docker 容器问题:
- 检查容器是否正在运行:
docker ps
- 查看容器日志:
docker logs ollama-deep-researcher-mcp
- 确保您的
.env
文件包含有效的 API 密钥 - 验证 Ollama 是否在主机上运行并可从容器访问
- 如果使用 host.docker.internal 不起作用,请尝试在 OLLAMA_BASE_URL 环境变量中使用主机的 IP 地址
- 对于容器之间的网络问题,请确保它们位于同一个 Docker 网络上
- 如果您在容器中运行 Ollama:
- 取消注释 docker-compose.yml 中的 Ollama 服务
- 确保 Ollama 容器分配了足够的资源
- 拉取Ollama容器中的模型:
docker exec -it ollama ollama pull deepseek-r1:8b
构建问题
- 如果
npm run build
失败并显示“无法识别‘node’”:- 确保 Node.js 已正确安装
- 将 Node.js 添加到您的系统 PATH:
- Windows:编辑系统环境变量 → 环境变量 → Path → 添加 Node.js 安装目录
- macOS/Linux:通常由安装程序处理
- 重新启动终端/计算机
- 尝试运行
node --version
来验证安装
Python 问题
视窗:
- 确保 Python 位于你的 PATH 中
- 尝试使用
python
而不是python3
- 检查 pip 是否已安装:
python -m pip --version
macOS/Linux:
- 使用
python3
而不是python
- 检查 pip 是否已安装:
python3 -m pip --version
- 您可能需要安装 pip:
sudo apt install python3-pip
(Ubuntu/Debian)或brew install python3
(macOS)
错误处理
服务器提供了以下清晰的错误消息:
- API 密钥缺失或无效
- 配置问题
- 搜索 API 问题
- LLM 处理错误
需要改进
- 更紧密地重新集成和验证 langgraph 以获得更多有趣的用例。
建筑学
有关服务器架构和实现的详细信息,请参阅.context/index.md 。
Glama.ai徽章
示例提示和输出记录
迅速的
Configure with perplexity and deepseek-r1:8b then research AI-First Applications
配置输出
{
"searchApi": "perplexity",
"llmModel": "deepseek-r1:8b",
"maxLoops": 3
}
Ollama 研究员成果
Research configuration updated:
Max Loops: 3
LLM Model: deepseek-r1:8b
Search API: perplexity
### Complete Research Results
**Updated Summary: AI-First Applications in Healthcare: Focus on PathAI**
1. **Design Principles**:
- PathAI exemplifies a data-driven approach by leveraging extensive datasets to train advanced AI models like PLUTO.
- Collaboration is central to their success, integrating technology into clinical workflows through partnerships with institutions such as Cleveland Clinic.
2. **Industry Transformations**:
- In healthcare, PathAI has significantly impacted diagnostic accuracy and efficiency. Their foundation model, PLUTO, demonstrates superior performance in various pathology tasks, outperforming existing models while reducing costs.
- Collaborations with leading institutions have facilitated the creation of digital pathology data networks, enhancing research and clinical care.
3. **Scalability and Performance**:
- PathAI's PLUTO model offers enhanced efficiency and compactness, significantly reducing training and inference costs.
- This innovation underscores their commitment to scalable and effective solutions in healthcare.
4. **Growth and Impact**:
- PathAI's growth strategy includes strategic partnerships and collaborations, such as their partnership with Cleveland Clinic and acquisition by Quest Diagnostics.
- These moves accelerate AI and digital pathology adoption, particularly in cancer diagnosis.
This summary highlights PathAI's contributions to healthcare through innovative technology and strategic collaborations, emphasizing their role in driving advancements and improving patient outcomes.
## Sources
### Perplexity Search 1
1. https://intelifaz.com/insights/ai-first-software-design
2. https://www.uxdesigninstitute.com/blog/how-to-design-for-ai-first-products/
3. https://vux.world/ai-design-principles/
4. https://www.leanware.co/insights/ai-first-apps
5. https://adamfard.com/blog/ai-ux-design-framework
6. https://www.sgh.com/insight/artificial-intelligence-best-practices/
7. https://www.index.dev/blog/generative-ai-application-design-principles
8. https://onstrategyhq.com/resources/ai-guiding-principles/
9. https://orangematter.solarwinds.com/2024/04/29/introducing-ai-by-design-principles-for-responsible-ai/
10. https://principles.design/examples/10-principles-for-design-in-the-age-of-ai
### Perplexity Search 2
1. https://cloud.google.com/transform/101-real-world-generative-ai-use-cases-from-industry-leaders
2. https://www.cloudera.com/resources/the-art-of-the-possible/ai-first-benefits-5-real-world-outcomes.html
3. https://builtin.com/artificial-intelligence/examples-ai-in-industry
4. https://www.uxforai.com/p/the-rise-of-ai-first-products
5. https://www.1051theblaze.com/ai-first-mobile-apps/
6. https://www.techtarget.com/searchenterpriseai/tip/The-history-of-artificial-intelligence-Complete-AI-timeline
7. https://gitnation.com/contents/demystifying-ai-first-building-applications-for-the-future
8. https://fptsoftware.com/resource-center/blogs/the-ai-first-future-challenges-and-opportunities
9. https://online.maryville.edu/blog/history-of-ai/
10. https://www.audience.io/blog/artificial-intelligence-first-party-data-the-future-of-data
### Perplexity Search 3
1. https://monday.com/blog/rnd/technical-specification/
2. https://softwaremind.com/blog/8-steps-for-successful-software-implementation/
3. https://www.infotech.com/research/ss/build-your-enterprise-application-implementation-playbook
4. https://interactiveimmersive.io/blog/touchdesigner-lessons/04-technical-implementation-design/
5. https://www.indeed.com/career-advice/finding-a-job/technical-requirements
6. https://www.techtarget.com/searchcustomerexperience/definition/implementation
7. https://theobogroup.com/what-to-know-about-technical-implementations/
8. https://www.ntietz.com/blog/whats-behind-just-implementation/
9. https://public.cyber.mil/stigs/
### Perplexity Search 4
1. https://www.ittbiomed.com/transforming-pathology-with-ai/
2. https://www.pathai.com/resources/pathai-commences-new-year-with-strong-foundation-for-growth-following-key-2023-achievements-in-ai-powered-pathology-products-strategic-partnerships-and-leadership-team-hires/
3. https://canvasbusinessmodel.com/blogs/target-market/pathai-target-market
4. https://www.pathologynews.com/industry-news/pathai-launches-new-pathologist-centric-features-on-aisight-to-enable-efficient-case-review-through-intelligent-case-prioritization-and-real-time-multi-institutional-collaboration/
5. https://newsroom.clevelandclinic.org/2022/03/10/pathai-and-cleveland-clinic-announce-collaboration-to-build-digital-pathology-infrastructure-and-evolve-use-of-ai-powered-pathology-algorithms-in-research-and-clinical-care
6. https://academic.oup.com/jamia/article/30/9/1503/7174318
7. https://hitconsultant.net/2024/05/14/pathai-unveils-ai-foundation-model-built-for-disease-detection/
8. https://newsroom.questdiagnostics.com/2024-05-01-Quest-Diagnostics-to-Acquire-PathAI-Diagnostics-to-Accelerate-AI-and-Digital-Pathology-Adoption-in-Cancer-Diagnosis-Forms-Licensing-Agreements-with-PathAI
9. https://www.multimodal.dev/post/ai-in-healthcare
10. https://canvasbusinessmodel.com/blogs/growth-strategy/pathai-growth-strategy
克劳德最终输出
Key Principles of AI-First Applications:
1. Human-AI Collaboration
- Applications are designed with AI as a core component rather than an add-on
- Focus on augmenting human capabilities rather than replacing them
- Clear feedback loops between AI systems and human users
2. Data-Centric Architecture
- Built around robust data pipelines and continuous learning
- Strong emphasis on data quality and governance
- Scalable infrastructure to handle growing datasets
3. Adaptive User Experience
- Interfaces that evolve based on user interaction patterns
- Contextual awareness and personalization
- Clear communication of AI capabilities and limitations
Real-World Example: PathAI in Healthcare
Core Technology:
- PLUTO foundation model demonstrates superior performance in pathology tasks
- Focuses on efficiency and cost reduction while maintaining high accuracy
- Built for scalability and integration into existing workflows
Implementation Strategy:
- Strategic partnerships with healthcare institutions like Cleveland Clinic
- Creation of digital pathology data networks
- Focus on practical clinical applications and research
Impact:
- Improved diagnostic accuracy in cancer detection
- Enhanced efficiency in pathology workflows
- Reduced costs through optimized resource utilization
Best Practices for AI-First Applications:
1. Technical Implementation
- Start with clear use cases and success metrics
- Build robust data pipelines and validation processes
- Implement continuous monitoring and model updating
2. User Experience
- Design transparent interfaces that build trust
- Provide clear feedback on AI decisions and confidence levels
- Allow for human oversight and intervention
3. Integration and Scaling
- Focus on seamless integration with existing workflows
- Build scalable infrastructure from the start
- Plan for continuous improvement and iteration