Skip to main content
Glama

MCP-Python

by rhabraken

使用 MCP 与您的数据库对话

使用 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

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

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

  1. 先决条件
    1. 1.设置环境变量
      1. 2. 设置 Claude 桌面
        1. 3. 使用虚拟数据启动 PostgreSQL 数据库
          1. 4.安装uv (如果尚未安装)
            1. 5. 配置并启动 MCP 服务器
              1. 6. 享受你的设置
                1. 概括

                  Related MCP Servers

                  • -
                    security
                    F
                    license
                    -
                    quality
                    A natural language interface that allows Claude to execute SQL queries on your local MySQL databases, enabling database interaction using natural language.
                    Last updated -
                    2
                    Python
                    • Linux
                    • Apple
                  • -
                    security
                    F
                    license
                    -
                    quality
                    Provides Claude Desktop with secure access to multiple database connections, allowing users to query MySQL, PostgreSQL, SQLite, and SQL Server databases directly through natural language.
                    Last updated -
                    • Apple
                  • -
                    security
                    A
                    license
                    -
                    quality
                    Provides Claude with direct access to databases including SQLite, SQL Server, PostgreSQL, and MySQL, enabling execution of SQL queries and table management through natural language.
                    Last updated -
                    807
                    1
                    TypeScript
                    MIT License
                    • Apple
                    • Linux
                  • -
                    security
                    A
                    license
                    -
                    quality
                    This server enables Claude to directly interact with SQLite, SQL Server, PostgreSQL, and MySQL databases through the Model Context Protocol, allowing for query execution, table management, and data export capabilities.
                    Last updated -
                    TypeScript
                    MIT License
                    • Apple
                    • Linux

                  View all related MCP servers

                  MCP directory API

                  We provide all the information about MCP servers via our MCP API.

                  curl -X GET 'https://glama.ai/api/mcp/v1/servers/rhabraken/mcp-python'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server