Ollama MCP Database Assistant

by robdodson

Integrations

  • Manages environment variables for database connection strings and model configuration in a secure way.

  • Provides the runtime environment needed for executing the MCP server application.

  • Leverages Ollama's LLM capabilities to interpret natural language questions, generate SQL queries, and provide AI-powered responses based on database results.

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

  1. Clone the repository:
git clone [your-repo-url] cd [your-repo-name]
  1. Install dependencies:
npm install
  1. Pull the required Ollama model:
ollama pull qwen2.5-coder:7b-instruct
  1. Create a .env file 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

  1. Start the chat interface:
npm start
  1. 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]
  1. Type 'exit' to quit the application.

How It Works

  1. The application connects to your PostgreSQL database through the PostgreSQL MCP server
  2. It loads and caches your database schema
  3. 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

VariableDescriptionDefault
DATABASE_URLPostgreSQL connection stringRequired
OLLAMA_MODELOllama model to useqwen2.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

  1. "Failed to connect to database"
    • Check your DATABASE_URL in .env
    • Verify PostgreSQL is running
    • Check network connectivity
  2. "Failed to connect to Ollama"
    • Ensure Ollama is running (ollama serve)
    • Verify the model is installed (ollama list)
  3. "Error executing query"
    • Check database permissions
    • Verify table/column names in the schema

License

MIT

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request
-
security - not tested
F
license - not found
-
quality - not tested

local-only server

The server can only run on the client's local machine because it depends on local resources.

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.

  1. Features
    1. Prerequisites
      1. Setup
        1. Usage
          1. How It Works
            1. Environment Variables
              1. Security
                1. Development
                  1. Troubleshooting
                    1. Common Issues
                  2. License
                    1. Contributing

                      Related MCP Servers

                      • -
                        security
                        A
                        license
                        -
                        quality
                        A simple MCP server for interacting with OpenAI assistants. This server allows other tools (like Claude Desktop) to create and interact with OpenAI assistants through the Model Context Protocol.
                        Last updated -
                        26
                        Python
                        MIT License
                        • Apple
                      • A
                        security
                        A
                        license
                        A
                        quality
                        MCP Ollama server integrates Ollama models with MCP clients, allowing users to list models, get detailed information, and interact with them through questions.
                        Last updated -
                        3
                        12
                        Python
                        MIT License
                        • Apple
                      • -
                        security
                        A
                        license
                        -
                        quality
                        Enables seamless integration between Ollama's local LLM models and MCP-compatible applications, supporting model management and chat interactions.
                        Last updated -
                        165
                        47
                        TypeScript
                        AGPL 3.0
                      • A
                        security
                        F
                        license
                        A
                        quality
                        A bridge that enables seamless integration of Ollama's local LLM capabilities into MCP-powered applications, allowing users to manage and run AI models locally with full API coverage.
                        Last updated -
                        10
                        33
                        JavaScript
                        • Apple

                      View all related MCP servers

                      ID: jgiuuvhhed