MCP-Python

local-only server

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

Integrations

  • Enables natural language interaction with MariaDB databases, providing conversational access to data querying and management functions.

  • Supports conversational interaction with MySQL databases, allowing users to query and manage data using natural language.

  • Allows direct interaction with PostgreSQL databases through natural language queries, enabling conversational data exploration and manipulation.

使用 MCP 与您的数据库对话

本指南讲解如何设置并运行 MCP 服务器,以便使用 Claude Desktop 与 PostgreSQL 数据库进行交互。由于其底层使用了 sqlalchemy,因此它也兼容 MySQL、MariaDB 和 SQLite。本项目基于https://github.com/runekaagaard/mcp-alchemy构建。

**注意:**本指南假设您对 Docker、环境变量和 CLI 使用有基本的了解。


先决条件

  • Docker Compose安装说明
  • Claude 桌面点击此处下载
  • uv :一款现代、高性能的 Python 包管理器。如果尚未安装,请按照以下说明操作。

1.设置环境变量

  1. 复制并重命名环境文件
    复制提供的.env.example文件并将其重命名为.env
    cp .env.example .env

2. 设置 Claude 桌面

  1. 下载并安装 Claude Desktop
    访问Claude Desktop 下载页面并安装该应用程序。

3. 使用虚拟数据启动 PostgreSQL 数据库

  1. 运行 Docker Compose
    确保 Docker Compose 已安装并运行:
    docker-compose up -d
    • 此命令将在localhost:5432上启动 PostgreSQL 数据库并用虚拟数据填充它。

4.安装uv (如果尚未安装)

  1. 安装uv
    执行以下命令安装uv
    curl -LsSf https://astral.sh/uv/install.sh | sh

5. 配置并启动 MCP 服务器

  1. 创建/更新 MCP 服务器配置
    将以下 JSON 配置保存在您的 MCP 服务器配置文件中(如有必要,调整路径):
    { "mcpServers": { "my_database": { "command": "uv", "args": [ "--directory", "/directory/where/this/app/is/located/app/", "run", "server.py" ], "env": { "DB_URL": "postgresql://postgres:password@localhost:5432/mydatabase" } } } }
    • **提示:**如果uv安装在非标准位置,请更新"command"值以反映可执行文件的完整路径。
  2. 启动 MCP 服务器
    配置完成后,每次启动 Claude Desktop 时,MCP 服务器都会自动启动。

6. 享受你的设置

  • 打开Claude 桌面
  • 该工具将自动调用您的 MCP 服务器,使您能够无缝地与数据库交互。

概括

  1. 设置环境变量:将.env.example复制到.env
  2. 安装并运行 Claude Desktop :从Claude Desktop下载。
  3. 使用 Docker Compose 启动 PostgreSQL :运行docker-compose up以使用虚拟数据启动数据库。
  4. 安装uv :如有必要,运行提供的安装命令。
  5. 配置 MCP 服务器:更新配置文件并确保路径和环境变量正确。
  6. 启动并享受:启动 Claude Desktop 开始通过 MCP 与您的数据库进行交互。

如果您遇到任何问题或需要进一步帮助,请参阅相关文档或联系您的支持团队。

编码愉快!

-
security - not tested
F
license - not found
-
quality - not tested

一种使用自然语言查询通过 Claude Desktop 与 PostgreSQL、MySQL、MariaDB 或 SQLite 数据库进行交互的服务器。

  1. Prerequisites
    1. 1. Set Up Environment Variables
      1. 2. Set Up Claude Desktop
        1. 3. Launch the PostgreSQL Database with Dummy Data
          1. 4. Install uv (if not already installed)
            1. 5. Configure and Launch the MCP Server
              1. 6. Enjoy Your Setup
                1. Summary
                  ID: 0mn8h83361