Cover image
Try Now
2025-01-09

通过模型上下文协议(MCP)将Ollama的LLM功能与PostgreSQL数据库访问相结合的交互式聊天界面。

3 years

Works with Finder

1

Github Watches

6

Github Forks

33

Github Stars

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

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

  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

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • appcypher
  • 很棒的MCP服务器 - 模型上下文协议服务器的策划列表

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • chongdashu
  • 使用模型上下文协议(MCP),启用Cursor,Windsurf和Claude Desktop等AI助手客户,以通过自然语言控制虚幻引擎。

    Reviews

    4 (1)
    Avatar
    user_ol8NNruc
    2025-04-17

    As a devoted user of the ollama-mcp-db, I couldn't be more impressed with its performance and versatility. This repository, created by robdodson, has streamlined my data management processes in ways I hadn't imagined possible. The seamless integration and user-friendly structure are simply brilliant. I highly recommend this tool to anyone looking for efficiency and effectiveness in handling databases. Check it out at the provided GitHub link!