ollama -db
An interactive chat interface that combines Ollama's LLM capabilities with PostgreSQL database access through the Model Context Protocol (MCP).
claude mcp add --transport stdio robdodson-ollama-mcp-db node server.js \ --env DATABASE_URL="PostgreSQL connection string, e.g. postgresql://user:password@host:5432/dbname" \ --env OLLAMA_MODEL="qwen2.5-coder:7b-instruct"
How to use
This MCP server provides a natural language interface to a PostgreSQL database using the Model Context Protocol (MCP). It leverages Ollama to translate user questions into SQL queries that run against your database, then returns AI-assisted explanations and the raw results in a readable format. The system is designed to be read-only: SQL queries are restricted to SELECT statements, and credentials are kept secure via your .env file. Start by ensuring your PostgreSQL database is reachable and that Ollama is running with the qwen2.5-coder:7b-instruct model loaded. Once running, you can ask questions like: “Which products generated the most revenue last month?” or “Show the top customers by order value for the last quarter.” The MCP flow handles schema loading, query generation, execution, and natural-language explanation of results.
How to install
Prerequisites:
- Node.js 16 or higher
- Access to a running PostgreSQL database
- Ollama installed and running locally with the model qwen2.5-coder:7b-instruct
Installation steps:
-
Clone the repository git clone <your-repo-url> cd <your-repo-name>
-
Install dependencies npm install
-
Pull the required Ollama model ollama pull qwen2.5-coder:7b-instruct
-
Create a .env file at the project root with your database connection DATABASE_URL=postgresql://user:password@localhost:5432/dbname OLLAMA_MODEL=qwen2.5-coder:7b-instruct # optional, defaults to this value
-
Run the server npm start
Notes:
- Ensure network access from the server to the PostgreSQL instance.
- The environment variables can be adjusted in the .env file or via your hosting environment.
Additional notes
Tips and common issues:
- If you see “Failed to connect to database,” verify the DATABASE_URL is correct and that PostgreSQL accepts connections from your host.
- If Ollama cannot be reached, ensure Ollama is running locally (ollama serve) and the model is installed (ollama list).
- Since the server operates in read-only mode with SELECT-only queries, ensure your database user has minimal required permissions.
- You can customize the Ollama model via the OLLAMA_MODEL environment variable to switch to a different model if needed.
- For production deployments, consider securing the environment with proper secrets management and restricting network access to the MCP endpoint.
Related MCP Servers
iterm
A Model Context Protocol server that executes commands in the current iTerm session - useful for REPL and CLI assistance
mcp
Octopus Deploy Official MCP Server
furi
CLI & API for MCP management
editor
MCP Server for Phaser Editor
DoorDash
MCP server from JordanDalton/DoorDash-MCP-Server
mcp
MCP сервер для автоматического создания и развертывания приложений в Timeweb Cloud