- Explore MCP Servers
- ollama-mcp-db
Ollama Mcp Db
What is Ollama Mcp Db
ollama-mcp-db is an interactive chat interface that integrates Ollama’s LLM capabilities with PostgreSQL database access via the Model Context Protocol (MCP), allowing users to query their data using natural language.
Use cases
Use cases for ollama-mcp-db include generating reports from database queries, answering business-related questions, providing insights from data without needing SQL knowledge, and facilitating user interactions with databases in a conversational manner.
How to use
To use ollama-mcp-db, clone the repository, install dependencies, pull the required Ollama model, set up your database connection in a .env file, and start the chat interface. You can then ask questions about your data in natural language.
Key features
Key features include a natural language interface for PostgreSQL, automatic SQL query generation, schema-aware responses, an interactive chat interface, and secure, read-only database access.
Where to use
ollama-mcp-db can be used in various fields such as data analysis, business intelligence, customer support, and any application requiring easy access to database information through natural language queries.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Ollama Mcp Db
ollama-mcp-db is an interactive chat interface that integrates Ollama’s LLM capabilities with PostgreSQL database access via the Model Context Protocol (MCP), allowing users to query their data using natural language.
Use cases
Use cases for ollama-mcp-db include generating reports from database queries, answering business-related questions, providing insights from data without needing SQL knowledge, and facilitating user interactions with databases in a conversational manner.
How to use
To use ollama-mcp-db, clone the repository, install dependencies, pull the required Ollama model, set up your database connection in a .env file, and start the chat interface. You can then ask questions about your data in natural language.
Key features
Key features include a natural language interface for PostgreSQL, automatic SQL query generation, schema-aware responses, an interactive chat interface, and secure, read-only database access.
Where to use
ollama-mcp-db can be used in various fields such as data analysis, business intelligence, customer support, and any application requiring easy access to database information through natural language queries.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
Ollama MCP Database Assistant
An interactive chat interface that combines Ollama’s LLM capabilities with PostgreSQL database access through the Model Context Protocol (MCP). Ask questions about your data in natural language and get AI-powered responses backed by real SQL queries.
Features
- Natural language interface to your PostgreSQL database
- Automatic SQL query generation
- Schema-aware responses
- Interactive chat interface
- Secure, read-only database access
Prerequisites
- Node.js 16 or higher
- A running PostgreSQL database
- Ollama installed and running locally
- The qwen2.5-coder:7b-instruct model pulled in Ollama
Setup
- 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
.envfile in the project root:
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
OLLAMA_MODEL=qwen2.5-coder:7b-instruct # Optional - this is the default
Usage
- Start the chat interface:
npm start
- Ask questions about your data in natural language:
Connected to database. You can now ask questions about your data. Type "exit" to quit. What would you like to know about your data? Which products generated the most revenue last month? Analyzing... [AI will generate and execute a SQL query, then explain the results]
- Type ‘exit’ to quit the application.
How It Works
- The application connects to your PostgreSQL database through the PostgreSQL MCP server
- It loads and caches your database schema
- When you ask a question:
- The schema and question are sent to Ollama
- Ollama generates an appropriate SQL query
- The query is executed through MCP
- Results are sent back to Ollama for interpretation
- You receive a natural language response
Environment Variables
| Variable | Description | Default |
|---|---|---|
| DATABASE_URL | PostgreSQL connection string | Required |
| OLLAMA_MODEL | Ollama model to use | qwen2.5-coder:7b-instruct |
Security
- All database access is read-only
- SQL queries are restricted to SELECT statements
- Database credentials are kept secure in your .env file
Development
Built with:
- TypeScript
- Model Context Protocol (MCP)
- Ollama
- PostgreSQL
Troubleshooting
Common Issues
-
“Failed to connect to database”
- Check your DATABASE_URL in .env
- Verify PostgreSQL is running
- Check network connectivity
-
“Failed to connect to Ollama”
- Ensure Ollama is running (
ollama serve) - Verify the model is installed (
ollama list)
- Ensure Ollama is running (
-
“Error executing query”
- Check database permissions
- Verify table/column names in the schema
License
MIT
Contributing
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.










