Ollama MCP server

Bridges Ollama's local large language model runner, enabling low-latency access to the LLM while maintaining data privacy and control.
Back to servers
Provider
NightTrek
Release date
Jan 08, 2025
Language
TypeScript
Stats
46 stars

The Ollama MCP Server acts as a bridge between Ollama and the Model Context Protocol (MCP), allowing you to integrate Ollama's local large language model capabilities into MCP-powered applications. This server gives you a clean MCP interface to access Ollama's functionality while maintaining local control and privacy of your AI models.

Prerequisites

Before installing the Ollama MCP Server, you'll need:

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

Installation

Follow these steps to install and build the server:

  1. Install dependencies:

    pnpm install
    
  2. Build the server:

    pnpm run build
    

Configuration

To use the server with MCP applications, you need to add it to your MCP configuration:

For Claude Desktop

MacOS:

~/Library/Application Support/Claude/claude_desktop_config.json

Windows:

%APPDATA%/Claude/claude_desktop_config.json

Add the following configuration:

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

Working with Models

Pull a Model

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

Run a Model with a Prompt

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

Chat Completion (OpenAI-compatible)

The server provides an OpenAI-compatible chat completion API:

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

Creating Custom Models

You can create custom models from Modelfiles:

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

Advanced Configuration

The server supports several advanced configuration options:

  • Custom API Endpoint: Set OLLAMA_HOST environment variable to change the default Ollama API endpoint (default: http://127.0.0.1:11434)
  • Timeout Settings: Configure timeout duration for model execution (default: 60 seconds)
  • Temperature Control: Adjust temperature (0-2 range) to control response randomness

Model Management Options

The server supports additional model management operations:

  • List available models
  • Copy models
  • Remove models
  • Push models to registries

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later