Ollama MCP server

Bridges AI assistants with locally-hosted Ollama models for complex reasoning tasks, providing tools for task decomposition and result evaluation without relying on cloud services.
Back to servers
Setup instructions
Provider
Kai Kogure
Release date
Mar 02, 2025
Language
Python
Stats
6 stars

The Ollama MCP Server enables seamless integration between local Ollama LLM instances and MCP-compatible applications, providing features like task decomposition, result evaluation, and workflow management through a standardized protocol.

Installation

Prerequisites

Before installing the Ollama MCP Server, ensure you have Ollama set up:

# Install Ollama (if not already installed)
curl -fsSL https://ollama.com/install.sh | sh

# Download recommended models
ollama pull llama3
ollama pull mistral
ollama pull qwen2

Installing the Server

Install the Ollama MCP Server using pip:

pip install ollama-mcp-server

Configuration

Environment Variables

You can configure the server using environment variables:

  • OLLAMA_HOST: The Ollama server address (default: http://localhost:11434)
  • DEFAULT_MODEL: The default model to use (default: llama3)
  • LOG_LEVEL: Log level (options: debug, info, warning, error, critical)

Performance Settings

The server supports various performance-related settings in config.py:

# Performance-related settings
cache_size: int = 100                 # Maximum number of entries to store in cache
max_connections: int = 10             # Maximum number of simultaneous connections
max_connections_per_host: int = 10    # Maximum connections per host
request_timeout: int = 60             # Request timeout in seconds

Configuring with Claude Desktop

For MacOS

Edit the configuration file at: ~/Library/Application\ Support/Claude/claude_desktop_config.json

For Windows

Edit the configuration file at: %APPDATA%/Claude/claude_desktop_config.json

Configuration Example

For the published server:

"mcpServers": {
  "ollama-MCP-server": {
    "command": "uvx",
    "args": [
      "ollama-mcp-server"
    ]
  }
}

With model specification:

"mcpServers": {
  "ollama-MCP-server": {
    "command": "python",
    "args": [
      "-m",
      "ollama_mcp_server"
    ],
    "env": [
      {"model": "llama3:latest"}
    ]
  }
}

Using the Server

Model Specification

The Ollama MCP Server allows specifying models in several ways, with the following priority:

  1. Tool invocation parameter (model parameter)
  2. MCP configuration file's env section
  3. Environment variable (OLLAMA_DEFAULT_MODEL)
  4. Default value (llama3)

When the server starts, it checks if the configured model exists and logs a warning if it cannot be found.

Task Decomposition

To break down complex tasks into manageable subtasks:

result = await mcp.use_mcp_tool({
    "server_name": "ollama-MCP-server",
    "tool_name": "decompose-task",
    "arguments": {
        "task_id": "task://123",
        "granularity": "medium",
        "max_subtasks": 5
    }
})

Result Evaluation

To evaluate results against specific criteria:

evaluation = await mcp.use_mcp_tool({
    "server_name": "ollama-MCP-server",
    "tool_name": "evaluate-result",
    "arguments": {
        "result_id": "result://456",
        "criteria": {
            "accuracy": 0.4,
            "completeness": 0.3,
            "clarity": 0.3
        },
        "detailed": true
    }
})

Running Ollama Models Directly

You can directly run Ollama models using the run-model tool. This allows you to:

  • Specify which model to use
  • Set parameters like temperature and max tokens
  • Send custom prompts to the model

Available Tools

add-task

Creates a new task in the system.

  • Required parameters: name (string), description (string)
  • Optional parameters: priority (number), deadline (string), tags (array)
  • Returns: Task identifier

decompose-task

Breaks down complex tasks into manageable subtasks.

  • Required parameters: task_id (string), granularity (string: "high"|"medium"|"low")
  • Optional parameters: max_subtasks (number)
  • Returns: Structured breakdown with dependencies and estimated complexity

evaluate-result

Analyzes task results against specified criteria.

  • Required parameters: result_id (string), criteria (object)
  • Optional parameters: detailed (boolean)
  • Returns: Detailed evaluation with scores and improvement suggestions

run-model

Runs an Ollama model with specified parameters.

  • Required parameters: model (string), prompt (string)
  • Optional parameters: temperature (number), max_tokens (number)
  • Returns: Model response

Debugging

Since the MCP server runs via stdio, debugging can be challenging. For an optimal debugging experience, it's strongly recommended to use the MCP Inspector.

To start the MCP Inspector using npm:

npx @modelcontextprotocol/inspector

Upon startup, the Inspector will display a URL that you can access in your browser to begin debugging.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "ollama-MCP-server" '{"command":"uvx","args":["ollama-mcp-server"]}'

See the official Claude Code MCP documentation for more details.

For 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 > Tools & Integrations and click "New MCP Server".

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

{
    "mcpServers": {
        "ollama-MCP-server": {
            "command": "uvx",
            "args": [
                "ollama-mcp-server"
            ]
        }
    }
}

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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "ollama-MCP-server": {
            "command": "uvx",
            "args": [
                "ollama-mcp-server"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

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