Back to MCP directory
publicPublicdnsLocal runtime

Ollama-mcp

Ollama MCP Server是一个强大的桥梁,将Ollama与模型上下文协议(MCP)无缝集成,使Ollama的本地LLM能力能够轻松融入MCP驱动的应用程序中。

article

README

🚀 Ollama MCP 服务器

一个强大的桥梁,连接 Ollama 和模型上下文协议(MCP),让你能够无缝地将 Ollama 的本地大语言模型能力集成到你的 MCP 应用程序中。

🚀 快速开始

先决条件

  • 已安装 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"  // 可选:自定义 Ollama API 端点
      }
    }
  }
}

✨ 主要特性

完整的 Ollama 集成

  • 完整的 API 支持:通过简洁的 MCP 接口,访问所有关键的 Ollama 功能。
  • 兼容 OpenAI 的聊天功能:直接替换 OpenAI 的聊天完成 API。
  • 本地模型控制:在本地运行 AI 模型,拥有完全的控制权和隐私保护。

核心能力

  • 🔄 模型管理

    • 从注册表中拉取模型。
    • 推送模型到注册表。
    • 列出可用模型。
    • 使用 Modelfile 创建自定义模型。
    • 复制并删除模型。
  • 🤖 模型执行

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

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

💻 使用示例

基础用法

拉取并运行模型

// 拉取一个模型
await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "pull",
  arguments: {
    name: "llama2"
  }
});

// 运行该模型
await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "run",
  arguments: {
    name: "llama2",
    prompt: "解释量子计算的简单原理"
  }
});

聊天完成(兼容 OpenAI)

await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "chat_completion",
  arguments: {
    messages: [
      { role: "user", content: "解释量子计算的简单原理" }
    ],
    temperature: 0.7
  }
});

高级用法

创建自定义模型

await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "create_model",
  arguments: {
    name: "my_custom_model",
    source: "local://path/to/my/model.bin"
  }
});

📚 详细文档

💡 使用建议

⚠️ 重要提示

确保你的 Ollama 服务器已正确配置并运行。

💡 使用建议

  • 在使用环境变量时,确保它们已正确设置以避免连接问题。
  • 对于高级用例,请参考 MCP 协议的详细文档。

让我们一起探索本地 AI 的强大能力!

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client