Skip to main content
Glama
robdodson

Ollama MCP Database Assistant

by robdodson

Ollama MCP 数据库助手

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

特征

  • PostgreSQL 数据库的自然语言接口

  • 自动 SQL 查询生成

  • 模式感知响应

  • 交互式聊天界面

  • 安全的只读数据库访问

Related MCP server: PostgreSQL MCP Server

先决条件

  • 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. 打开拉取请求

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    A Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.
    18
    1,631 npm
    201
    AGPL 3.0
  • A
    license
    Not graded
    quality
    F
    maintenance
    A Model Context Protocol server providing dual transport (HTTP and Stdio) access to PostgreSQL databases, allowing AI assistants to query databases and fetch schema information through natural language.
    49 npm
    31
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides a natural language interface for querying and managing PostgreSQL, MySQL, MariaDB, MSSQL, and SQLite databases using the Model Context Protocol. Users can explore database schemas and visualize query results through an integrated web dashboard.
    27 npm
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that enables natural language data exploration and visualization for PostgreSQL databases. It allows users to convert questions into SQL queries and interact with data through a Streamlit web interface featuring automated chart generation.
    -