NO

nighttrek/ollama-mcp

API 开发

本页由 AI 翻译,技术细节请以原文为准。 查看原文

75 stars 17 forks 质量 74 趋势 14

nighttrek/ollama-mcp 是从 https://github.com/nighttrek/ollama-mcp. 导入的 MCP 服务器候选服务器。

概览

nighttrek/ollama-mcp 是从 https://github.com/nighttrek/ollama-mcp. 导入的 MCP 服务器候选服务器。

概述(AI 翻译)

🚀 这是 Ollama 与模型上下文协议(MCP)之间的强大桥梁,使 Ollama 的本地大型语言模型能力能够无缝集成到您基于 MCP 的应用中。

🌟 特色

完全的奥拉玛整合

  • 完整的 API 覆盖:通过干净的 MCP 接口访问所有关键的 Ollama 功能
  • OpenAI 兼容聊天:OpenAI 聊天完成 API 的替换
  • 本地LLM能力:本地运行AI模型,拥有完全控制和隐私

核心能力

  • 🔄 模型管理

  • 从注册库拉取模型

  • 推送模型到注册库

  • 可选型号列表

  • 从 Modelfiles 创建自定义模型

  • 复制并移除模型

  • 🤖 模型执行

  • 运行模型并可自定义提示

  • 聊天完成API,包含系统/用户/助理角色

  • 可配置参数(温度、超时)

  • 直接响应的原始模式支持

  • 🛠 服务器控制

  • 启动和管理 Ollama 服务器

  • 查看详细模型信息

  • 错误处理和超时管理

🚀 开始

先决条件

  • 安装在你的系统上的 Ollama
  • Node.js和NPM/PNPM

安装

  1. 安装依赖:

  2. 搭建服务器:

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Ollama MCP Server

🚀 A powerful bridge between Ollama and the Model Context Protocol (MCP), enabling seamless integration of Ollama’s local LLM capabilities into your MCP-powered applications.

🌟 Features

Complete Ollama Integration

  • Full API Coverage: Access all essential Ollama functionality through a clean MCP interface
  • OpenAI-Compatible Chat: Drop-in replacement for OpenAI’s chat completion API
  • Local LLM Power: Run AI models locally with full control and privacy

Core Capabilities

  • 🔄 Model Management

    • Pull models from registries
    • Push models to registries
    • List available models
    • Create custom models from Modelfiles
    • Copy and remove models
  • 🤖 Model Execution

    • Run models with customizable prompts
    • Chat completion API with system/user/assistant roles
    • Configurable parameters (temperature, timeout)
    • Raw mode support for direct responses
  • 🛠 Server Control

    • Start and manage Ollama server
    • View detailed model information
    • Error handling and timeout management

🚀 Getting Started

Prerequisites

  • Ollama installed on your system
  • Node.js and npm/pnpm

Installation

  1. Install dependencies:
pnpm install
  1. Build the server:
pnpm run build

Configuration

Add the server to your MCP configuration:

For 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
      }
    }
  }
}

🛠 Usage Examples

Pull and Run a Model

// 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"
  }
});

The run tool waits for Ollama to finish generation and returns the complete response as MCP text content. It requests stream: false; tokens are not streamed incrementally. Whitespace and empty responses are preserved. Ollama HTTP errors, connection failures, timeouts, and malformed responses are reported as MCP errors.

Chat Completion (OpenAI-compatible)

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
  }
});

Create Custom Model

await mcp.use_mcp_tool({
  server_name: "ollama",
  tool_name: "create",
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "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 } } } }