O

Ollama桥

@NightTrek/Ollama-mcp
0 Stars 408 次浏览 NightTrek 更新于 2026-08-23

一座桥梁,能够将Ollama的本地LLM能力无缝集成到由MCP驱动的应用程序中,使用户能够在本地管理和运行AI模型,并实现完整的API覆盖。

该服务暂未提供标准配置,请参考 README 手动接入

可用工具 (10 个)

该服务在 MCP 协议中暴露的工具,AI 可按需调用

serve

Start Ollama server

该工具无需必填参数,直接调用即可

create 2 个参数 需填 2 项

Create a model from a Modelfile

必填参数:name、modelfile

show 1 个参数 需填 1 项

Show information for a model

必填参数:name

run 3 个参数 需填 2 项

Run a model

必填参数:name、prompt

pull 1 个参数 需填 1 项

Pull a model from a registry

必填参数:name

push 1 个参数 需填 1 项

Push a model to a registry

必填参数:name

list

List models

该工具无需必填参数,直接调用即可

cp 2 个参数 需填 2 项

Copy a model

必填参数:source、destination

rm 1 个参数 需填 1 项

Remove a model

必填参数:name

chat_completion 4 个参数 需填 2 项

OpenAI-compatible chat completion API

必填参数:model、messages

服务介绍

Ollama MCP 服务器

🚀 一个强大的桥梁,连接 Ollama 和 Model Context Protocol (MCP),使您能够将 Ollama 的本地 LLM 功能无缝集成到您的 MCP 驱动的应用程序中。

🌟 特性

完整的 Ollama 集成

  • 全面的 API 覆盖:通过简洁的 MCP 接口访问所有重要的 Ollama 功能
  • 兼容 OpenAI 的聊天:可作为 OpenAI 聊天完成 API 的即插即用替代品
  • 本地 LLM 动力:在本地运行 AI 模型,完全控制和隐私保护

核心功能

  • 🔄 模型管理

    • 从注册表拉取模型
    • 将模型推送到注册表
    • 列出可用模型
    • 从 Modelfiles 创建自定义模型
    • 复制和删除模型
  • 🤖 模型执行

    • 使用可定制的提示运行模型
    • 具有系统/用户/助手角色的聊天完成 API
    • 可配置参数(温度、超时)
    • 支持直接响应的原始模式
  • 🛠 服务器控制

    • 启动和管理 Ollama 服务器
    • 查看详细的模型信息
    • 错误处理和超时管理

🚀 快速开始

前提条件

  • Ollama 已安装在您的系统上
  • Node.js 和 npm/pnpm

安装

  1. 安装依赖项:
pnpm install
  1. 构建服务器:
pnpm run build

配置

将服务器添加到您的 MCP 配置中:

对于 Claude Desktop:

MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "ollama": {
      "command": "node",
      "args": ["/path/to/ollama-server/build/index.js"],
      "env": {
        "OLLAMA_HOST": "http://127.0.0.1:11434"  // Optional: customize Ollama API endpoint
      }
    }
  }
}

🛠 使用示例

拉取并运行模型

// Pull a model
await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "pull",
  arguments: {
    name: "llama2"
  }
});

// Run the model
await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "run",
  arguments: {
    name: "llama2",
    prompt: "Explain quantum computing in simple terms"
  }
});

聊天完成(兼容 OpenAI)

await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "chat_completion",
  arguments: {
    model: "llama2",
    messages: [
      {
        role: "system",
        content: "You are a helpful assistant."
      },
      {
        role: "user",
        content: "What is the meaning of life?"
      }
    ],
    temperature: 0.7
  }
});

创建自定义模型

await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "create",
  arguments: {
    name: "custom-model",
    modelfile: "./path/to/Modelfile"
  }
});

🔧 高级配置

  • OLLAMA_HOST:配置自定义的 Ollama API 端点(默认:http://127.0.0.1:11434)
  • 模型执行的超时设置(默认:60 秒)
  • 控制响应随机性的温度设置(范围:0-2)

🤝 贡献

欢迎贡献!请随时:

  • 报告错误
  • 提出新功能建议
  • 提交拉取请求

📝 许可证

MIT 许可证 - 欢迎在您的项目中自由使用!


为 MCP 生态系统而建❤️

相关 MCP 服务