MCP Ollama Server

MCP Ollama Server

Enables natural language database queries by combining Ollama's language models with SQLite database access through an MCP server.

Category
Visit Server

README

MCP Ollama Server

A simple Model Context Protocol (MCP) server that enables natural language database queries by combining Ollama's language models with SQLite database access.

Overview

This project demonstrates how to build an MCP server that exposes SQLite database operations as tools, which can then be called by an AI language model (Ollama) through an agentic loop. Users can ask natural language questions about their database, and the system will automatically determine which SQL queries to execute and return human-readable results.

How It Works

The system consists of two main components:

  1. Server (server.py): An MCP server that provides tools for interacting with a SQLite database
  2. Client (client.py): An MCP client that connects to Ollama and uses the server's tools to answer natural language queries

The flow:

  1. User asks a natural language question
  2. Client sends question to Ollama with available MCP tools
  3. Ollama determines which tools to call and generates tool arguments
  4. Client executes tools via MCP server
  5. Results are fed back to Ollama for response generation
  6. Final answer is displayed to the user

Features

  • MCP Server Tools:

    • list_tables(): Lists all tables in the SQLite database
    • describe_table(table_name): Returns the schema of a specific table
    • execute_query(sql): Executes read-only SQL SELECT statements (write operations are blocked for safety)
  • Natural Language Interface: Ask questions in German or English about your database

  • Agentic Loop: The AI model automatically chains tool calls to answer complex questions

  • Safety: Write operations are blocked; only SELECT queries are allowed

Requirements

  • Python 3.8+
  • Ollama (running locally or accessible remotely)
  • A local SQLite database

Installation

  1. Clone the repository:
git clone https://github.com/ollibeyer/mcp-example.git
cd mcp-example
  1. Create a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Ensure Ollama is running with the required model:
ollama pull qwen2.5:7b-instruct
ollama serve

Usage

Run the client with a natural language query:

python client.py "Welche Tabellen gibt es in der Datenbank?"

Or run with a custom query:

python client.py "Zeige mir alle Kunden aus Berlin."

Some example queries:

  • "Welche Tabellen gibt es in der Datenbank?" (What tables are in the database?)
  • "Zeige mir alle Kunden aus Berlin." (Show me all customers from Berlin.)
  • "Welches Produkt wurde am häufigsten bestellt?" (Which product was ordered most frequently?)

Configuration

Edit the following variables in client.py to customize:

  • MODEL: The Ollama model to use (default: qwen2.5:7b-instruct)
  • SERVER_SCRIPT: Path to the server script
  • PYTHON: Path to the Python executable in the virtual environment

Edit server.py to change:

  • DB_PATH: Path to your SQLite database (default: sample.db in the same directory)

Database

The project includes a sample SQLite database (sample.db) with example tables. You can replace it with your own database or modify the DB_PATH in server.py.

Development

To extend this project:

  1. Add new tools to server.py using the @mcp.tool() decorator
  2. Optionally customize the tool-to-Ollama conversion in client.py
  3. Experiment with different Ollama models

License

This is an example project. Feel free to use, modify, and extend it for your own purposes.

References

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured