RL-Slave/RL-MCP-Server
If you are the rightful owner of RL-MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The Ollama MCP Server is a comprehensive Model Context Protocol server designed to facilitate the use of Ollama models through the MCP protocol, offering a wide range of tools and features for efficient model management and text generation.
Ollama MCP Server
A complete Model Context Protocol (MCP) Server for Ollama with 28 tools, enabling the use of Ollama models via the MCP protocol.
Features
- ✅ 28 complete tools for all Ollama functions
- ✅ Streaming support for chat and text generation
- ✅ Model management (Pull, Delete, Copy, Create, Update)
- ✅ Embedding generation (Single & Batch)
- ✅ Context management for multi-turn conversations
- ✅ Batch operations for efficient processing
- ✅ System monitoring and health checks
- ✅ Remote access via 0.0.0.0:4838
Installation
Prerequisites
- Python 3.10 or higher
- Ollama installed and running
- At least one Ollama model (e.g.,
ollama pull llama2)
Installation
-
Clone repository or extract files
-
Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Adjust configuration (optional):
cp env.example .env
# Edit .env if needed
Usage
Start Server
# Direct
python -m mcp_server.server
# Or with start script
./start.sh
# Or with uvicorn
uvicorn mcp_server.server:app --host 0.0.0.0 --port 4838
The server runs by default on 0.0.0.0:4838.
API Endpoints
Health Check
curl http://localhost:4838/health
List Tools
curl -X POST http://localhost:4838/mcp/tools/list
Call Tool
curl -X POST http://localhost:4838/mcp/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "ollama_list_models",
"arguments": {}
}'
JSON-RPC 2.0
curl -X POST http://localhost:4838/rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}'
Available Tools
Model Management
ollama_list_models- Lists all modelsollama_show_model- Shows model detailsollama_pull_model- Downloads modelollama_delete_model- Deletes modelollama_copy_model- Copies modelollama_create_model- Creates model from modelfile
Text Generation
ollama_generate- Generates textollama_generate_stream- Streaming generation
Chat Functions
ollama_chat- Chat completionollama_chat_stream- Streaming chat
Embeddings
ollama_embeddings- Generate embeddingsollama_create_embeddings- Batch embeddings
System & Monitoring
ollama_check_health- Health checkollama_get_version- Ollama versionollama_list_processes- Running processesollama_get_models_info- All model info
Additional Tools
ollama_update_model- Update modelollama_get_modelfile- Get modelfileollama_validate_model- Validate modelollama_get_model_size- Model sizeollama_search_models- Search modelsollama_check_blobs- Blob statusollama_save_context- Save contextollama_load_context- Load contextollama_clear_context- Clear contextollama_batch_generate- Batch generationollama_compare_models- Compare models
Configuration
Environment Variables
Create a .env file:
# MCP Server Configuration
MCP_HOST=0.0.0.0
MCP_PORT=4838
# Ollama API Configuration
OLLAMA_HOST=localhost
OLLAMA_PORT=11434
OLLAMA_TIMEOUT=60
# Logging
LOG_LEVEL=INFO
LOG_FORMAT=json
Firewall Configuration
For remote access, port 4838 must be opened:
# UFW (Ubuntu/Debian)
sudo ufw allow 4838/tcp
# firewalld (RHEL/CentOS)
sudo firewall-cmd --add-port=4838/tcp --permanent
sudo firewall-cmd --reload
Example Usage
Python Client
import httpx
# Call tool
async with httpx.AsyncClient() as client:
response = await client.post(
"http://localhost:4838/mcp/tools/call",
json={
"name": "ollama_generate",
"arguments": {
"model": "llama2",
"prompt": "Explain Python in one sentence.",
}
}
)
print(response.json())
cURL Examples
Generate Text
curl -X POST http://localhost:4838/mcp/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "ollama_generate",
"arguments": {
"model": "llama2",
"prompt": "What is Machine Learning?"
}
}'
Chat
curl -X POST http://localhost:4838/mcp/tools/call \
-H "Content-Type: application/json" \
-d '{
"name": "ollama_chat",
"arguments": {
"model": "llama2",
"messages": [
{"role": "user", "content": "Hello!"}
]
}
}'
Project Structure
RL-MCP Server/
├── src/
│ └── mcp_server/
│ ├── __init__.py
│ ├── server.py # Main server
│ ├── client.py # Ollama API client
│ ├── config.py # Configuration
│ ├── handlers.py # Tool handlers
│ ├── exceptions.py # Exceptions
│ └── utils/ # Utilities
├── tests/ # Tests
├── examples/ # Examples
├── requirements.txt # Dependencies
├── pyproject.toml # Project configuration
├── README_DE.md # German version
├── README_EN.md # This file
└── LICENSE # License
Development
Run Tests
pytest
Code Formatting
black src/
ruff check src/
License
See file.
Author
Robin Oliver Lucas
- Website: https://rl-dev.de
- Email: robin@rl-dev.de
Support
For questions or issues, please create an issue or contact the author.