关于 TypeScript MCP with Filesystem Server and Ollama Integration
这个 TypeScript 示例将 Ollama 对话连接到可配置的 MCP 服务,让模型通过交互式命令行界面调用工具。它还提供演示模式,可在不使用 LLM 的情况下测试文件系统和网络研究工具。
主要功能
- 01交互式 Ollama 聊天界面
- 02配置多个 MCP 服务
- 03支持 uvx 与 npx 服务
- 04文件系统与网络研究工具
- 05无需 LLM 的演示模式
适用场景
- 01与可调用 MCP 工具的 Ollama 模型对话
- 02不使用 LLM 测试文件系统和网络研究工具
- 03配置 Node.js 或 Python MCP 服务
MCP 相关
该项目充当 MCP 客户端,从 mcp-config.json 读取服务配置并连接到指定服务,包括基于 uvx 和 npx 的服务。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
14收录的工具列表 · 更新于 2 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| path | string | 是 | |
| tail | number | 否 | 如果提供,则仅返回文件末尾的 N 行 |
| head | number | 否 | 如果提供,则仅返回文件开头的 N 行 |
详细介绍
集成 Ollama 的 TypeScript MCP Agent
本项目演示了 Model Context Protocol (MCP) 服务与 Ollama 之间的集成,让 AI 模型能够通过统一接口与各种工具交互。
✨ 功能特性
- 支持多个 MCP 服务(uvx 和 npx 均已测试)
- 内置对文件系统操作和网络研究的支持
- 通过
mcp-config.json轻松配置,类似claude_desktop_config.json - 与 Ollama 集成的交互式聊天界面,应支持任何工具
- 独立演示模式,无需大模型即可测试网络和文件系统工具
🚀 快速开始
-
前置条件:
-
Node.js(版本 18 或更高)
-
已安装并运行 Ollama
-
全局安装你想使用的 MCP 工具:
# 用于文件系统操作 npm install -g @modelcontextprotocol/server-filesystem # 用于网络研究 npm install -g @mzxrai/mcp-webresearch
-
-
克隆并安装:
git clone https://github.com/ausboss/mcp-ollama-agent.git cd mcp-ollama-agent npm install -
在
mcp-config中配置你的工具和支持工具的 Ollama 模型:{ "mcpServers": { "filesystem": { "command": "npx", "args": ["@modelcontextprotocol/server-filesystem", "./"] }, "webresearch": { "command": "npx", "args": ["-y", "@mzxrai/mcp-webresearch"] } }, "ollama": { "host": "http://localhost:11434", "model": "qwen2.5:latest" } } -
运行演示,无需大模型即可测试文件系统和网络研究工具:
npx tsx ./src/demo.ts -
或者启动与 Ollama 的聊天界面:
npm start
⚙️ 配置
- MCP 服务: 将任何兼容 MCP 的服务添加到
mcpServers部分 - Ollama: 配置主机和模型(必须支持函数调用)
- 同时支持 Python(uvx)和 Node.js(npx)的 MCP 服务
💡 使用示例
本示例使用了此模型 qwen2.5:latest
Chat started. Type "exit" to end the conversation.
You: can you use your list directory tool to see whats in test-directory then use your read file tool to read it to me?
Model is using tools to help answer...
Using tool: list_directory
With arguments: { path: 'test-directory' }
Tool result: [ { type: 'text', text: '[FILE] test.txt' } ]
Assistant:
Model is using tools to help answer...
Using tool: read_file
With arguments: { path: 'test-directory/test.txt' }
Tool result: [ { type: 'text', text: 'rosebud' } ]
Assistant: The content of the file `test.txt` in the `test-directory` is:
rosebud
You: thanks
Assistant: You're welcome! If you have any other requests or need further assistance, feel free to ask.
系统提示词
某些本地模型可能需要在工具选择方面获得帮助。可在 ChatManager.ts 中自定义系统提示词,以改善工具使用。
🤝 贡献
欢迎贡献!请随时提交 issue 或 pull request。
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。