mcpField
T
TypeScript MCP with Filesystem Server and Ollama Integration

TypeScript MCP with Filesystem Server and Ollama Integration

本地服务
github.com/ausbossAI 与智能体3062 周前更新

关于 TypeScript MCP with Filesystem Server and Ollama Integration

这个 TypeScript 示例将 Ollama 对话连接到可配置的 MCP 服务,让模型通过交互式命令行界面调用工具。它还提供演示模式,可在不使用 LLM 的情况下测试文件系统和网络研究工具。

主要功能

  1. 01交互式 Ollama 聊天界面
  2. 02配置多个 MCP 服务
  3. 03支持 uvx 与 npx 服务
  4. 04文件系统与网络研究工具
  5. 05无需 LLM 的演示模式

适用场景

  1. 01与可调用 MCP 工具的 Ollama 模型对话
  2. 02不使用 LLM 测试文件系统和网络研究工具
  3. 03配置 Node.js 或 Python MCP 服务

MCP 相关

该项目充当 MCP 客户端,从 mcp-config.json 读取服务配置并连接到指定服务,包括基于 uvx 和 npx 的服务。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"ollama-agent": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem"
]
}
}
}
启动命令npx -y @modelcontextprotocol/server-filesystem

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npm@modelcontextprotocol/server-filesystem

工具

14

收录的工具列表 · 更新于 2 周前

参数类型必填说明
pathstring是
tailnumber否如果提供,则仅返回文件末尾的 N 行
headnumber否如果提供,则仅返回文件开头的 N 行

详细介绍

集成 Ollama 的 TypeScript MCP Agent

本项目演示了 Model Context Protocol (MCP) 服务与 Ollama 之间的集成,让 AI 模型能够通过统一接口与各种工具交互。

✨ 功能特性

  • 支持多个 MCP 服务(uvx 和 npx 均已测试)
  • 内置对文件系统操作和网络研究的支持
  • 通过 mcp-config.json 轻松配置,类似 claude_desktop_config.json
  • 与 Ollama 集成的交互式聊天界面,应支持任何工具
  • 独立演示模式,无需大模型即可测试网络和文件系统工具

🚀 快速开始

  1. 前置条件:

    • Node.js(版本 18 或更高)

    • 已安装并运行 Ollama

    • 全局安装你想使用的 MCP 工具:

      # 用于文件系统操作
      npm install -g @modelcontextprotocol/server-filesystem
      
      # 用于网络研究
      npm install -g @mzxrai/mcp-webresearch
      
  2. 克隆并安装:

    git clone https://github.com/ausboss/mcp-ollama-agent.git
    cd mcp-ollama-agent
    npm install
    
    
  3. 在 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"
      }
    }
    
  4. 运行演示,无需大模型即可测试文件系统和网络研究工具:

    npx tsx ./src/demo.ts
    
  5. 或者启动与 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

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。