MCP Server with Ollama Integration
An MCP server that integrates with Ollama to provide tools for file operations, calculations, and text processing. Requires a running Ollama instance.
MCP Server with Ollama Integration
A simple Model Context Protocol (MCP) server that extends AI capabilities with useful tools for file operations, calculations, text processing, and more. This project demonstrates how to create custom tools that AI models can use through Ollama.
šÆ What is This?
This is a tutorial which creates a bridge between AI models (like those running in Ollama) and your computer's functionality using Model Context Protocol, Langchain and Ollama. Think of it as giving the AI hands to do any task which ealier seem to impossible by AI.
š Features
This is a very basic implementation on top of which we can build more.(No external APIs connected yet)
Available Tools
| Tool | Description | Example Usage |
|---|---|---|
| Calculator | Basic math operations | "Calculate 15 + 25" |
| File Checker | Check if files exist | "Does 'document.txt' exist?" |
| Directory Listing | List folder contents | "What's in my home folder?" |
| Text Transform | Change text case, reverse, etc. | "Make 'hello world' uppercase" |
| Temperature Converter | Convert between °C, °F, K | "Convert 25°C to Fahrenheit" |
| Password Generator | Generate secure passwords | "Create a 16-character password" |
| Random Numbers | Generate random numbers | "Give me a number between 1-100" |
| Text Statistics | Analyze text (word count, etc.) | "Analyze this paragraph" |
| Greeting | Personalized greetings | "Say hello to Alice" |
š Prerequisites
- Python 3.10 or higher
- Ollama installed and running
- Basic familiarity with terminal/command line
- Langchain models
- API basics
š ļø Installation
Step 1: Clone or Download
# Download files
wget https://github.com/Mudit7715/MCP.git
cd MCP
# Create virtual environment
python -m venv mcp_env
# Activate it
source mcp_env/bin/activate # Linux/Mac
# OR
mcp_env\Scripts\activate # Windows
Step 2: Install ollama and required libraries.
# Install required packages
pip install fastmcp
pip install langchain-mcp-adapters langgraph langchain-ollama langchain
# Check if Ollama is running
curl http://localhost:11434/api/tags
# If not installed, visit: https://ollama.com/library
# Pull a model (if you don't have one)
ollama pull llama3.1
Project Structure
mcp-ollama-server/
āāā server.py # MCP server with all tools
āāā client.py # Client that connects server to Ollama
āāā config.json # Server configuration
āāā README.md # This file
Step 3: Running the server and client.
source mcp_env/bin/activate
python server.py
# Open another terminal and the run:
python client.py
Step 4: Using the tools
Enter your question: Calculate 50 * 3 + 10
Answer: I will calculate that for you. 50 * 3 + 10 = 160
Enter your question: Check if file 'test.txt' exists in current directory
Answer: The file 'test.txt' was not found in the current directory.
Enter your question: Generate a secure password
Answer: Here is a generated 12-character password: K9#mX2$vB8pQ
š§ Configuration
š ļø Modify Server Tools
To add new tools, edit server.py:
@mcp.tool()
def your_new_tool(parameter: str) -> str:
"""Description of what your tool does."""
# Your tool logic here
return f"Result: {parameter}"
š¤ Change Ollama Model
Edit client.py and change the model:
agent = create_react_agent("ollama:llama3.2", tools) # Change model here
š ļø Server Configuration
Edit config.json to change server parameters:
{
"mcpServers": {
"my-simple-assistant": {
"command": "python",
"args": ["/full/path/to/your/server.py"],
"cwd": "/full/path/to/your/project"
}
}
}
š¤ Contributing
Want to add more tools? Here's how:
@mcp.tool()
def my_awesome_tool(input_param: str) -> str:
"""What this tool does."""
# Your logic here
return f"Result: {input_param}"
Test it by asking the AI to use your tool
Update documentation with your new tool
Related Servers
Scout Monitoring MCP
sponsorPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
sponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
refactor-mcp
Refactor code using regex-based search and replace.
Postman MCP Server
Interact with the Postman API via an MCP server. Requires a Postman API key.
ClipToWSL
Enables AI coding agents to read Windows clipboard contents, including text and images, from within the Windows Subsystem for Linux (WSL).
Biel.ai MCP Server
Connect AI tools like Cursor and VS Code to your product documentation using the Biel.ai platform.
Windsor
Windsor MCP enables your LLM to query, explore, and analyze your full-stack business data integrated into Windsor.ai with zero SQL writing or custom scripting.
Chart
A Model Context Protocol server for generating visual charts using AntV.
Deepseek Thinking & Claude 3.5 Sonnet
Combines DeepSeek's reasoning capabilities with Claude 3.5 Sonnet's response generation through OpenRouter.
Lifecycle MCP Server
An MCP server for managing the software development lifecycle, with support for an optional external SQLite database.
Metasploit MCP Server
An MCP server for integrating with the Metasploit Framework. Requires Metasploit Framework to be installed and msfrpcd to be running.
Angreal
An MCP server providing AI assistants with discovery capabilities for angreal projects.