Artificial Intelligence is quickly moving beyond simple chat interfaces. Today, developers want AI systems that can read files, query databases, call APIs, and automate workflows. This is where Model Context Protocol (MCP) comes in.
In this article, you’ll learn:
What MCP is (in simple terms)
Why it matters
How it works
A practical example
How to use MCP with Ollama
What is MCP?
MCP (Model Context Protocol) is a standard that allows AI models to interact with external tools and data sources.
Without MCP:
AI only knows what’s in the prompt
With MCP:
AI can fetch real-time data
Access databases
Read/write files
Execute actions
Why MCP is Important
Traditional AI:
Static
Limited to conversation
MCP-enabled AI:
Dynamic
Action-driven
Context-aware
Lets understand with basic example
Without MCP:
“Show my latest orders”
AI: “I don’t have access to your system.”
With MCP:
AI:
Connects to your database
Fetches orders
Analyzes them
Returns insights
How MCP Works
MCP systems typically have three components:
1. Model
The AI model (e.g., CodeGemma, DeepSeek)
2. MCP Server
Provides tools like:
File system access
Database queries
APIs
3. Client / Interface
Connects the model with MCP tools
Flow Diagram (Conceptual)
User → AI Model → MCP Server → Tool/Data → Response → User
Example: MCP in Action
Let’s say you build a system where AI can read local files.
User Prompt:
“Summarize my project README file”
What happens:
AI understands intent
MCP triggers file access tool
Reads README.md
AI summarizes content
Returns response
This is not possible with plain LLM alone.
Using MCP with Ollama
Now let’s get practical.
Step 1: Run Ollama
ollama run deepseek-coder:6.7bThis starts your local AI model.
Step 2: Create a Simple MCP Server (Python Example)
Here’s a basic example of exposing a tool (file reader):
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/read-file', methods=['POST'])
def read_file():
data = request.json
file_path = data.get("path")
try:
with open(file_path, "r") as f:
content = f.read()
return jsonify({"content": content})
except Exception as e:
return jsonify({"error": str(e)})
app.run(port=5001)This acts as your MCP tool server
Step 3: Connect Ollama via API
Ollama provides a local API:
http://localhost:11434/api/generateExample request:
curl http://localhost:11434/api/generate -d '{
"model": "deepseek-coder:6.7b",
"prompt": "Summarize file at /path/to/file",
"stream": false
}'Step 4: Add Tool Logic (MCP Layer)
You create a middleware that:
Detects intent (e.g., “read file”)
Calls MCP server (
/read-file)Sends result back to model
Model generates final answer
Real-World Use Cases
With MCP + Ollama, you can build:
AI Business Dashboard
Connect to MySQL/PostgreSQL
Ask: “Show revenue this month”
AI Coding Assistant
Read your project files
Suggest improvements
File Automation Agent
Organize files
Summarize documents
API Automation Bot
Call external APIs
Combine responses intelligently