A simple yet powerful Python client for interacting with Model Context Protocol (MCP) servers using Ollama, allowing local LLMs to use tools.
MCP Client for Ollama (ollmcp)
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
- 🚀 Multiple Transport Types: Supports STDIO, SSE, and Streamable HTTP server connections
- 🎨 Rich Terminal Interface: Interactive console UI
- 🖥️ Streaming Responses: View model outputs in real-time as they're generated
- 🛠️ Tool Management: Enable/disable specific tools or entire servers during chat sessions
- 🎨 Enhanced Tool Display: Beautiful, structured visualization of tool executions with JSON syntax highlighting
- 🧠 Context Management: Control conversation memory with configurable retention settings
- 🤔 Thinking Mode: Advanced reasoning capabilities with visible thought processes for supported models (deepseek-r1, qwen3)
- 🔄 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
- 🔄 Server Reloading: Hot-reload MCP servers during development without restarting the client
- 📊 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
- Python 3.10+ (Installation guide)
- Ollama running locally (Installation guide)
- UV package manager (Installation guide)
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
Usage
Run with default settings:
ollmcp
If you don't provide any options, the client will use
auto-discoverymode 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 MODEL: Ollama model to use. Default:qwen2.5:7b--host HOST: Ollama host URL. Default:http://localhost:11434
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
Use a custom Ollama host:
ollmcp --host http://localhost:22545 --servers-json /path/to/servers.json --model qwen3:latest
Interactive Commands
During chat, use these commands:
| 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 |
thinking-mode |
tm |
Toggle thinking mode (deepseek-r1, qwen3 only) |
show-thinking |
st |
Toggle thinking text visibility |
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) |
reload-servers |
rs |
Reload all MCP servers with current configuration |
quit, exit |
q or Ctrl+D |
Exit the client |
Tool and Server Selection
The tool and server selection interface allows you to enable or disable specific tools:
- 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 aorall- Enable all toolsnornone- Disable all toolsdordesc- Show/hide tool descriptionssorsave- Save changes and return to chatqorquit- Cancel changes and return to chat
Model Selection
The model selection interface shows all available models in your Ollama installation:
- Enter the number of the model you want to use
sorsave- Save the model selection and return to chatqorquit- Cancel the model selection and return to chat
Server Reloading for Development
The reload-servers command (rs) is particularly useful during MCP server development. It allows you to reload all connected servers without restarting the entire client application.
Key Benefits:
- 🔄 Hot Reload: Instantly apply changes to your MCP server code
- 🛠️ Development Workflow: Perfect for iterative development and testing
- 📝 Configuration Updates: Automatically picks up changes in server JSON configs or Claude configs
- 🎯 State Preservation: Maintains your tool enabled/disabled preferences across reloads
- ⚡️ Time Saving: No need to restart the client and reconfigure everything
When to Use:
- After modifying your MCP server implementation
- When you've updated server configurations in JSON files
- After changing Claude's MCP configuration
- During debugging to ensure you're testing the latest server version
Simply type reload-servers or rs in the chat interface, and the client will:
- Disconnect from all current MCP servers
- Reconnect using the same parameters (server paths, config files, auto-discovery)
- Restore your previous tool enabled/disabled settings
- Display the updated server and tool status
This feature dramatically improves the development experience when building and testing MCP servers.
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
- Thinking mode settings
Server Configuration Format
The JSON configuration file supports STDIO, SSE, and Streamable HTTP server types:
{
"mcpServers": {
"stdio-server": {
"command": "command-to-run",
"args": ["arg1", "arg2", "..."],
"env": {
"ENV_VAR1": "value1",
"ENV_VAR2": "value2"
},
"disabled": false
},
"sse-server": {
"type": "sse",
"url": "http://localhost:8000/sse",
"headers": {
"Authorization": "Bearer your-token-here"
},
"disabled": false
},
"http-server": {
"type": "streamable_http",
"url": "http://localhost:8000/mcp",
"headers": {
"X-API-Key": "your-api-key-here"
},
"disabled": false
}
}
}
Compatible Models
The following Ollama models work well with tool use:
- qwen2.5
- qwen3
- llama3.1
- llama3.2
- mistral
For a complete list of Ollama models with tool use capabilities, visit the official Ollama models page.
How Tool Calls Work
- The client sends your query to Ollama with a list of available tools
- If Ollama decides to use a tool, the client:
- Displays the tool execution with formatted arguments and syntax highlighting
- Extracts the tool name and arguments from the model response
- Calls the appropriate MCP server with these arguments
- Shows the tool response in a structured, easy-to-read format
- Sends the tool result back to Ollama for final processing
- Displays the model's final response incorporating the tool results
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
- Model Context Protocol for the specification and examples
- Ollama for the local LLM runtime
- Rich for the terminal user interface
Made with ❤️ by jonigl
Metadata
Release files for mcp-client-for-ollama 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_client_for_ollama-0.9.0.tar.gz | 35.3 kB | Without provenance | Details for mcp_client_for_ollama-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_client_for_ollama-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for mcp_client_for_ollama-0.9.0-py3-none-any.whl |
Total release size: 72.9 kB
Release files / mcp_client_for_ollama-0.9.0.tar.gz
| Download URL | mcp_client_for_ollama-0.9.0.tar.gz |
|---|---|
| Size | 35.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a55f1fcd17b7febb0697dc8c4029376d2af98f5fafb6f1fb309ede3c7ed8ac84
|
|
BLAKE2b-256 checksum How to use checksums |
99096383d0dab34f83c6e9236d04d90d7746f737052815d0a076054e83ad78e1
|
| 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.9.0-py3-none-any.whl
| Download URL | mcp_client_for_ollama-0.9.0-py3-none-any.whl |
|---|---|
| Size | 37.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4963bc24bb333e967ff5a6512dde6c68aa7f5fd3f317d2b8104ce18390ac0d31
|
|
BLAKE2b-256 checksum How to use checksums |
015dc0d322c363d72b20d6473295af74dd55e1a2c05d0aed2af0928287d22d66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for mcp-client-for-ollama 0.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.