Skip to main content

MCP Client for Ollama

Python 3.10+ PyPI - Python Version PyPI - Python Version License: MIT Build, Publish and Release CI

A simple yet powerful Python client for interacting with Model Context Protocol (MCP) servers using Ollama, allowing local LLMs to use tools.

ollmpc usage demo gif

Overview

This project provides a robust Python-based client that connects to one or more Model Context Protocol (MCP) servers and uses Ollama to process queries with tool use capabilities. The client establishes connections to MCP servers, sends queries to Ollama models, and handles the tool calls the model makes.

This implementation was adapted from the Model Context Protocol quickstart guide and customized to work with Ollama, providing a user-friendly interface for interacting with LLMs that support function calling.

Features

  • 🌐 Multi-Server Support: Connect to multiple MCP servers simultaneously
  • 🎨 Rich Terminal Interface: Interactive console UI
  • 🛠️ Tool Management: Enable/disable specific tools or entire servers during chat sessions
  • 🧠 Context Management: Control conversation memory with configurable retention settings
  • 🔄 Cross-Language Support: Seamlessly work with both Python and JavaScript MCP servers
  • 🔍 Auto-Discovery: Automatically find and use Claude's existing MCP server configurations
  • 🚀 Dynamic Model Switching: Switch between any installed Ollama model without restarting
  • 💾 Configuration Persistence: Save and load tool preferences between sessions
  • 📊 Usage Analytics: Track token consumption and conversation history metrics
  • 🔌 Plug-and-Play: Works immediately with standard MCP-compliant tool servers
  • 🔔 Update Notifications: Automatically detects when a new version is available

Requirements

Quick Start

Option 1: Install with pip and run

pip install ollmcp
ollmcp

Option 2: One-step install and run

uvx ollmcp

Option 3: Install from source and run using virtual environment

git clone https://github.com/jonigl/mcp-client-for-ollama.git
cd mcp-client-for-ollama
uv venv && source .venv/bin/activate
uv pip install .
uv run -m mcp_client_for_ollama.client

Usage

Run with default settings:

ollmcp

If you don't provide any options, the client will use auto-discovery mode to find MCP servers from Claude's configuration.

Command-line Arguments

Server Options:

  • --mcp-server: Path to one or more MCP server scripts (.py or .js). Can be specified multiple times.
  • --servers-json: Path to a JSON file with server configurations.
  • --auto-discovery: Auto-discover servers from Claude's default config file (default behavior if no other options provided).

Model Options:

  • --model: Ollama model to use (default: "qwen2.5:7b")

Usage Examples

Connect to a single server:

ollmcp --mcp-server /path/to/weather.py --model llama3.2:3b

Connect to multiple servers:

ollmcp --mcp-server /path/to/weather.py --mcp-server /path/to/filesystem.js --model qwen2.5:latest

Use a JSON configuration file:

ollmcp --servers-json /path/to/servers.json --model llama3.2:1b

Interactive Commands

During chat, use these commands:

ollmcp main interface

Command Shortcut Description
help h Display help and available commands
tools t Open the tool selection interface
model m List and select a different Ollama model
context c Toggle context retention (on/off)
clear cc Clear conversation history and context
context-info ci Display context statistics
cls clear-screen Clear the terminal screen
save-config sc Save current tool and model configuration to a file
load-config lc Load tool and model configuration from a file
reset-config rc Reset configuration to defaults (all tools enabled)
quit q Exit the client

Tool and Server Selection

The tool and server selection interface allows you to enable or disable specific tools:

ollmcp model selection interface

  • Enter numbers separated by commas (e.g. 1,3,5) to toggle specific tools
  • Enter ranges of numbers (e.g. 5-8) to toggle multiple consecutive tools
  • Enter S + number (e.g. S1) to toggle all tools in a specific server
  • a or all - Enable all tools
  • n or none - Disable all tools
  • d or desc - Show/hide tool descriptions
  • s or save - Save changes and return to chat
  • q or quit - Cancel changes and return to chat

Model Selection

The model selection interface shows all available models in your Ollama installation:

ollmcp tool and server selection interface

  • Enter the number of the model you want to use
  • s or save - Save the model selection and return to chat
  • q or quit - Cancel the model selection and return to chat

Configuration Management

The client supports saving and loading tool configurations between sessions:

  • When using save-config, you can provide a name for the configuration or use the default
  • Configurations are stored in ~/.config/ollmcp/ directory
  • The default configuration is saved as ~/.config/ollmcp/config.json
  • Named configurations are saved as ~/.config/ollmcp/{name}.json

The configuration saves:

  • Current model selection
  • Enabled/disabled status of all tools
  • Context retention settings

Server Configuration Format

The JSON configuration file should follow this format:

{
  "mcpServers": {
    "server-name": {
      "command": "command-to-run",
      "args": ["arg1", "arg2", "..."],
      "env": {
        "ENV_VAR1": "value1",
        "ENV_VAR2": "value2"
      },
      "disabled": false
    }
  }
}

Claude's configuration file is typically located at: ~/Library/Application Support/Claude/claude_desktop_config.json

Compatible Models

The following Ollama models work well with tool use:

  • qwen2.5
  • llama3.3
  • llama3.2
  • llama3.1
  • mistral

For a complete list of Ollama models with tool use capabilities, visit the official Ollama models page.

How Tool Calls Work

  1. The client sends your query to Ollama with a list of available tools
  2. If Ollama decides to use a tool, the client:
    • Extracts the tool name and arguments
    • Calls the appropriate MCP server with these arguments
    • Sends the tool result back to Ollama
    • Shows the final response

Where Can I Find More MCP Servers?

You can explore a collection of MCP servers in the official MCP Servers repository.

This repository contains reference implementations for the Model Context Protocol, community-built servers, and additional resources to enhance your LLM tool capabilities.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments


Made with ❤️ by jonigl

Metadata

Release files for mcp-client-for-ollama 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-client-for-ollama 0.3.0
File Size Uploaded
mcp_client_for_ollama-0.3.0.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-client-for-ollama 0.3.0
File Interpreter ABI Platform
mcp_client_for_ollama-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.6 kB

Release files / mcp_client_for_ollama-0.3.0.tar.gz

Download URL mcp_client_for_ollama-0.3.0.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
351f2296f719de3cd937b8828b35fd7a9fddcd189e293da6acee3b549e0bf238
BLAKE2b-256 checksum
How to use checksums
127f7aae653f5ba2dfa1616b7833dac4a08d206fb22aaafede938c329a5ae04d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / mcp_client_for_ollama-0.3.0-py3-none-any.whl

Download URL mcp_client_for_ollama-0.3.0-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f3cddd82f12a8a3fcd4864dcd5a2923005abfda3bda7eab6242933f03228e81
BLAKE2b-256 checksum
How to use checksums
cbf8c15aaca9fda8694b5496f46cb3f98c71e650a77ff49d4b8a332c595b51ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

0.35.1

2 release files

0.35.0

2 release files

0.33.3

2 release files

0.33.2

2 release files

0.33.1

2 release files

0.33.0

2 release files

0.32.1

2 release files

0.31.0

2 release files

0.30.0

2 release files

0.29.1

2 release files

0.29.0

2 release files

0.28.0

2 release files

0.27.0

2 release files

0.26.0

2 release files

0.23.0

2 release files

0.22.0

2 release files

0.20.1

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.3

2 release files

0.18.1

2 release files

0.18.0

2 release files

0.16.0

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.5

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page