KS

kk-src/azure-postgresql-mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

0 stars 9 forks 质量 67 趋势 0MIT

Azure Database for PostgreSQL MCP Server

概览

A Model Context Protocol (MCP) Server that let’s your AI models talk to data hosted in Azure Database for PostgreSQL according to the MCP standard! By utilizing this server, you can effortlessly connect any AI application that supports MCP to your PostgreSQL flexible server (using either PostgreSQL password-based authentication or Microsoft Entra authentication methods), enabling you to provide your business data as meaningful context in a standardized and secure manner. This server exposes the following tools, which can be invoked by MCP Clients in your AI agents, AI applications or tools like Claude Desktop and Visual Studio Code: - in your Azure Database for PostgreSQL flexible server instance. - in a database along with their schema information. - to retrieve data from your database. - in your database. - in your database. - , including its PostgreSQL version, and compute and storage configurations.

README

以下为原文 README 节选,完整内容请查看原文。

Azure Database for PostgreSQL MCP Server (Preview)

A Model Context Protocol (MCP) Server that let’s your AI models talk to data hosted in Azure Database for PostgreSQL according to the MCP standard!

By utilizing this server, you can effortlessly connect any AI application that supports MCP to your PostgreSQL flexible server (using either PostgreSQL password-based authentication or Microsoft Entra authentication methods), enabling you to provide your business data as meaningful context in a standardized and secure manner.

This server exposes the following tools, which can be invoked by MCP Clients in your AI agents, AI applications or tools like Claude Desktop and Visual Studio Code:

  • List all databases in your Azure Database for PostgreSQL flexible server instance.
  • List all tables in a database along with their schema information.
  • Execute read queries to retrieve data from your database.
  • Insert or update records in your database.
  • Create a new table or drop an existing table in your database.
  • List Azure Database for PostgreSQL flexible server configuration, including its PostgreSQL version, and compute and storage configurations. *
  • Retrieve specific server parameter values. *

*Available when using Microsoft Entra authentication method

Getting Started

Prerequisites

  • Python 3.10 or above
  • An Azure Database for PostgreSQL flexible server instance with a database containing your business data. For instructions on creating a flexible instance, setting up a database, and connecting to it, please refer to this quickstart guide.
  • An MCP Client application or tool such as Claude Desktop or Visual Studio Code.

Installation

  1. Clone the azure-postgresql-mcp repository:

    git clone https://github.com/Azure-Samples/azure-postgresql-mcp.git
    cd azure-postgresql-mcp
    

    Alternatively, you can download only the azure_postgresql_mcp.py file to your working folder.

  2. Create a virtual environment:

    Windows cmd.exe:

    python -m venv azure-postgresql-mcp-venv
    .\azure-postgresql-mcp-venv\Scripts\activate.bat
    

    Windows Powershell:

    python -m venv azure-postgresql-mcp-venv
    .\azure-postgresql-mcp-venv\Scripts\Activate.ps1
    

    Linux and MacOS:

    python -m venv azure-postgresql-mcp-venv
    source ./azure-postgresql-mcp-venv/bin/activate 
    
  3. Install the dependencies:

    pip install mcp[cli]
    pip install psycopg[binary]
    pip install azure-mgmt-postgresqlflexibleservers
    pip install azure-identity
    

Use the MCP Server with Claude Desktop

Watch the following demo video or read on for detailed instructions.

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "azure-postgresql-mcp": { "command": "<path to the virtual environment>\\azure-postgresql-mcp-venv\\Scripts\\python", "args": [ "<path to azure_postgresql_mcp.py file>\\azure_postgresql_mcp.py" ], "env": { "PGHOST": "<Fully qualified name of your Azure Database for PostgreSQL instance>", "PGUSER": "<Your Azure Database for PostgreSQL username>", "PGPASSWORD": "<Your password>", "PGDATABASE": "<Your database name>" } } } }