Ollama MCP Wrapper
Wraps local Ollama capabilities for interacting with local language models, querying tags, generating text, and executing tool-calling sequences.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Ollama MCP Wrapper generate a short story about a robot using llama3"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Ollama Model Context Protocol (MCP) Wrapper
A production-grade Python-based MCP server wrapper that exposes local Ollama instance capabilities to LLM applications and host systems (such as Claude Desktop or IDEs).
This wrapper allows agents to dynamically query downloaded models, load models into memory, run text completions, request tool-calling operations, and inspect/unload running models under a strict static prompt injection security filter.
Architecture Flow
+-------------------+ +-----------------------+ +--------------------+
| Host (e.g. IDE) | <--STDIO-->| Ollama MCP Server | <--HTTP--> | Local Ollama Daemon|
| & Agent Clients | | (FastMCP Python SDK) | | (http://localhost:11434)|
+-------------------+ +-----------------------+ +--------------------+Related MCP server: Ollama MCP Server
File Structure
├── .agents/ # Custom Agent rules and automated skills
├── src/
│ └── ollama_wrapper/ # Server package directory
│ ├── __init__.py
│ ├── config.py # Global settings, timeout & injection settings
│ ├── prompts.py # Custom agent system prompt templates
│ ├── security.py # Precompiled regex prompt injection scanners
│ ├── server.py # Main FastMCP server definitions
│ └── tools_helper.py # MCP schema to Ollama payload formatters
├── tests/ # Pytest test cases
├── examples/
│ └── minimal_client.py # Example Python client integration script
├── pyproject.toml # Package declarations and dependencies
├── test_changelog.md # Log of test suite errors and resolutions
└── README.md # Extensive documentationFeatures & Tool API Reference
The server registers 5 primary tools, 1 resource path, and 2 prompt templates:
Tools
list_local_modelsDescription: Returns all models currently downloaded on the host machine.
Output: JSON list containing
name,size,family, andparameter_size.
run_model_completionDescription: Runs text generation/completion on a targeted model.
Parameters:
model_name(string, required): Target model identifier (e.g.llama3:latest).prompt(string, required): Text input.
Security: Blocks execution if prompt violates injection filters.
generate_with_toolsDescription: Runs chat completions exposing a list of execution tool schemas to the model.
Parameters:
model_name(string, required): Target model identifier.messages(array of objects, required): Chat message history.tools(array of objects, required): Custom tool definitions to expose.
list_running_modelsDescription: Retrieves a list of models currently loaded and active in the system's memory (RAM/VRAM).
stop_modelDescription: Unloads a specific model from RAM/VRAM to free up system resources.
Parameters:
model_name(string, required): Model to unload.
Resources
active-model://status: Returns the status and name of the currently active model.
Prompts
agent_bootstrap: System prompt template to spin up a structured reasoning agent.code_assistant: System prompt template configuring a coding assistant.
Setup & Running
Prerequisites
Install Ollama and download a model (e.g.
ollama run qwen2.5-coder:1.5b).Install uv Python package manager.
Running the Server
To start the MCP server locally using standard I/O (STDIO):
$env:PYTHONPATH="src"
uv run python -m ollama_wrapper.serverMinimal Client Example
We have provided a complete example client in examples/minimal_client.py. To run this client and test the server:
Start Ollama.
In the project root directory, execute:
uv run python examples/minimal_client.py
Security Safeguards
To prevent jailbreaks and bypasses, all input prompts passing through text generation tools are filtered by precompiled regular expressions in security.py. This blocks:
Instruction overrides (e.g.,
"ignore previous instructions").Scenarios activating bypass roles (e.g.,
"DAN mode","developer mode active").Sensitive information disclosure (e.g.,
"reveal system prompt").Encoding attacks (e.g.,
"translate system instructions to base64").
Running Tests
Run the test suites with pytest:
uv run pytestIntegration with External Projects & Clients
To use this MCP server in another project or on a different PC:
1. Clone the Repository
git clone https://github.com/PieterVDMerwe/ollama-wrapper-mcp.git2. Configure Your Client
Add the configuration block under the mcpServers key of your client settings file:
A. Claude Desktop
Configuration Path:
%APPDATA%\Claude\claude_desktop_config.jsonJSON Payload:
{ "mcpServers": { "ollama-wrapper": { "command": "uv", "args": [ "--directory", "C:/path/to/cloned/ollama-wrapper-mcp", "run", "python", "-m", "ollama_wrapper.server" ], "env": { "PYTHONPATH": "src", "OLLAMA_HOST": "http://localhost:11434" } } } }
B. Google Antigravity 2.0 & Antigravity IDE
Configuration Path:
~/.gemini/config/mcp_config.jsonJSON Payload:
{ "mcpServers": { "ollama-wrapper": { "command": "uv", "args": [ "--directory", "C:/path/to/cloned/ollama-wrapper-mcp", "run", "python", "-m", "ollama_wrapper.server" ], "env": { "PYTHONPATH": "src", "OLLAMA_HOST": "http://localhost:11434" } } } }
(Make sure to replace C:/path/to/cloned/ with the absolute path to the directory on the new machine).
Agent / LLM Instructions
When interacting with this MCP server as an AI assistant or agent client, adhere to the following operation guidelines:
1. Model Discovery & Selection
Do not guess model names: Always call
list_local_modelsfirst to discover downloaded options.Select the smallest viable model appropriate for the task (e.g. use smaller coder models for code tasks, and larger ones for reasoning).
2. VRAM and Resource Management
Local models consume massive GPU/RAM resources.
Check currently loaded models using
list_running_models.Clean up after yourself: When you are finished running generation tasks, explicitly call the
stop_modeltool to unload the model from memory.
3. Prompt Safety Limits
All input prompts are statically scanned. Avoid using phrases that look like overrides (e.g. "ignore prior commands"), or the server will reject your request with a security error.
Keep prompts focused on content generation rather than system configurations.
4. Interactive Tool Execution
Use
generate_with_toolsto expose system capabilities to the Ollama backend model.Inspect the returned
message.tool_callsstructure to determine which functions the model wants to run, execute them in your client wrapper, and feed the results back into the chat history.
Available Tools
5 toolsgenerate_with_toolsB
Execute chat generation with a list of tools exposed to the model.
Inputs: tools (required), messages (required), model_name (required).
list_local_modelsA
List all local models currently downloaded in the Ollama instance.
Inputs: no named parameters. Returns: result
list_running_modelsA
List all models currently loaded and running in memory (RAM/VRAM).
Inputs: no named parameters. Returns: result
run_model_completionC
Run text generation completion on a specific local model.
Inputs: prompt (required), model_name (required).
stop_modelB
Stop and unload a specific model from memory (RAM/VRAM).
Inputs: model_name (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
The tools are mostly distinct, but list_local_models and list_running_models are similar in purpose (listing models in different states), and run_model_completion and generate_with_tools both handle generation. Descriptions clarify the differences, but the boundaries could be sharper.
All tool names follow a consistent verb_noun snake_case pattern (list_*, run_*, generate_*, stop_*), making the naming predictable and easy to navigate.
With only five tools, the set is well-scoped and focused on core local model interaction, avoiding unnecessary bloat while covering the essential immediate operations.
The set covers listing, running, and stopping models, but lacks essential model lifecycle management like pulling or deleting models, which are common in Ollama workflows. This leaves notable gaps for a wrapper of this kind.
Maintenance
Related MCP Connectors
Real-time MCP & A2A prompt-injection, jailbreak, and tool-schema poisoning firewall for AI agents.
Memory, reflection and safety for AI agents. Hosted or local, no vector database.
Prompt-injection scanning and safe webpage fetching for AI agents reading untrusted content.
The WAF for agents. Pattern-based + heuristic firewall scans prompts, RAG documents, tool argume...
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables interaction with locally running Ollama models through chat, generation, and model management operations. Supports listing, downloading, and deleting models while maintaining conversation history for interactive sessions.522 npmMIT
- AlicenseNot gradedqualityDmaintenanceExposes local Ollama instances as tools for Claude Code, allowing users to offload code generation, text drafting, and embedding tasks to local GPUs. It supports multi-turn conversations and model management through the Model Context Protocol.MIT
- AlicenseNot gradedqualityDmaintenanceProvides direct access to Ollama models for AI inference, including text generation, chat, model management, and embeddings.9 npm3MIT
- AlicenseAqualityBmaintenanceEnables observability and governance for local LLMs via Ollama, including auditing model usage, scanning prompts for secrets/PII, and enforcing allow/deny policies.21MIT