Ollama MCP Database Assistant

local-only server

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

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 数据库助手

交互式聊天界面,将 Ollama 的 LLM 功能与通过模型上下文协议 (MCP) 访问 PostgreSQL 数据库相结合。您可以使用自然语言提出有关数据的问题,并获得由真实 SQL 查询支持的 AI 响应。

特征

  • PostgreSQL 数据库的自然语言接口
  • 自动 SQL 查询生成
  • 模式感知响应
  • 交互式聊天界面
  • 安全的只读数据库访问

先决条件

  • Node.js 16 或更高版本
  • 正在运行的 PostgreSQL 数据库
  • Ollama已在本地安装并运行
  • Ollama 中引入的 qwen2.5-coder:7b-instruct 模型

设置

  1. 克隆存储库:
git clone [your-repo-url] cd [your-repo-name]
  1. 安装依赖项:
npm install
  1. 拉取需要的Ollama模型:
ollama pull qwen2.5-coder:7b-instruct
  1. 在项目根目录中创建一个.env文件:
DATABASE_URL=postgresql://user:password@localhost:5432/dbname OLLAMA_MODEL=qwen2.5-coder:7b-instruct # Optional - this is the default

用法

  1. 启动聊天界面:
npm start
  1. 使用自然语言询问有关数据的问题:
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. 输入“exit”退出应用程序。

工作原理

  1. 该应用程序通过PostgreSQL MCP 服务器连接到您的 PostgreSQL 数据库
  2. 它加载并缓存你的数据库模式
  3. 当你问一个问题时:
    • 模式和问题已发送给 Ollama
    • Ollama 生成适当的 SQL 查询
    • 通过 MCP 执行查询
    • 结果发回Ollama进行解释
    • 您会收到自然语言回复

环境变量

多变的描述默认
数据库网址PostgreSQL 连接字符串必需的
OLLAMA_模型要使用的 Ollama 模型qwen2.5-coder:7b-指令

安全

  • 所有数据库访问都是只读的
  • SQL 查询仅限于 SELECT 语句
  • 数据库凭证安全地保存在您的 .env 文件中

发展

内置:

  • TypeScript
  • 模型上下文协议(MCP)
  • 奥拉马
  • PostgreSQL

故障排除

常见问题

  1. “无法连接到数据库”
    • 检查 .env 中的 DATABASE_URL
    • 验证 PostgreSQL 是否正在运行
    • 检查网络连接
  2. “无法连接到 Ollama”
    • 确保 Ollama 正在运行( ollama serve
    • 验证模型是否已安装( ollama list
  3. “执行查询时出错”
    • 检查数据库权限
    • 验证架构中的表/列名称

执照

麻省理工学院

贡献

  1. 分叉存储库
  2. 创建你的功能分支
  3. 提交你的更改
  4. 推送到分支
  5. 打开拉取请求
-
security - not tested
F
license - not found
-
quality - not tested

交互式聊天界面,将 Ollama 的 LLM 功能与通过模型上下文协议 (MCP) 访问 PostgreSQL 数据库相结合。您可以使用自然语言提出有关数据的问题,并获得由真实 SQL 查询支持的 AI 响应。

  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
                      ID: jgiuuvhhed