Azure Database for PostgreSQL MCP Server (Preview)

Azure Database for PostgreSQL MCP Server (Preview)

By Azure-Samples GitHub

Azure Database for PostgreSQL MCP Server

azure postgresql
Overview

What is Azure Database for PostgreSQL MCP Server?

Azure Database for PostgreSQL MCP Server is a Model Context Protocol (MCP) server that allows AI applications to interact with data hosted in Azure Database for PostgreSQL, enabling seamless data queries and updates.

How to use Azure Database for PostgreSQL MCP Server?

To use the MCP server, set up an Azure Database for PostgreSQL instance, clone the repository, create a virtual environment, install dependencies, and configure your MCP client application (like Claude Desktop or Visual Studio Code) to connect to the server.

Key features of Azure Database for PostgreSQL MCP Server?

  • Execute read queries to retrieve data from PostgreSQL databases.
  • Insert or update records in the database.
  • Create and delete tables in the database.
  • Provides schema information and metadata for each table.

Use cases of Azure Database for PostgreSQL MCP Server?

  1. Integrating AI applications with business data for natural language queries.
  2. Automating data retrieval and updates in PostgreSQL databases.
  3. Enhancing AI tools with database capabilities for better decision-making.

FAQ from Azure Database for PostgreSQL MCP Server?

  • What is MCP?
    MCP stands for Model Context Protocol, which standardizes communication between AI applications and data sources.

  • Is the MCP server free to use?
    Yes, the MCP server is free to use, but you will incur costs for the Azure Database for PostgreSQL instance.

  • What programming language is used?
    The server is implemented in Python.

Content

Azure Database for PostgreSQL MCP Server (Preview)

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

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

  • Tools:
    • query_data: Execute read queries to retrieve data from your Azure Database for PostgreSQL databases.
    • update_values: Insert or update records in your database.
    • create_table: Create a new table in your database.
    • drop_table: Delete a table in your database.
  • Resources:
    • Tables: Provides schema information and metadata for each table in the database, including column names and data types.

By integrating with this MCP server, you can effortlessly connect any AI application that supports MCP to your business data in Azure Database for PostgreSQL, providing meaningful context in a standardized, scalable and secure manner.

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]
    

Use the MCP Server with Claude Desktop

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

https://github.com/user-attachments/assets/327157ef-9c75-414f-8e08-8bbb2b83208c

  1. In the Claude Desktop app, navigate to the “Settings” pane, select the “Developer” tab and click on “Edit Config”.

  2. Open the claude_desktop_config.json file and add the following configuration to the "mcpServers" section to configure the Azure Database for PostgreSQL MCP server:

    {
        "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>"
                }
            }        
        }
    }
    
  3. Restart the Claude Desktop app.

  4. Upon restarting, you should see a hammer icon and an attach icon at the bottom of the input box. Selecting these icons will display the tools and resources provided by the MCP Server.

You are now all set to start interacting with your data using natural language queries!

Use the MCP Server with Visual Studio Code

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

https://github.com/user-attachments/assets/ed02b4ea-3b76-429a-9558-aef32f1dee68

  1. In Visual Studio Code, navigate to “File”, select “Preferences” and then choose “Settings”.

  2. Search for “MCP” and select “Edit in settings.json”.

  3. Add the following configuration to the “mcp” section of the settings.json file:

    {
        "mcp": {
            "inputs": [],
            "servers": {
                "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>"
                    }
                }
            }
        }
    }
    
  4. Select the “Copilot” status icon in the upper-right corner to open the GitHub Copilot Chat window.

  5. Choose “Agent mode” from the dropdown at the bottom of the chat input box.

  6. Click on “Select Tools” (hammer icon) to view the Tools exposed by the MCP Server.

You are now all set to start interacting with your data using natural language queries!

Contributing

The Azure Database for PostgreSQL MCP Server is currently in Preview. As we continue to develop and enhance its features, we welcome all contributions! For more details, see the CONTRIBUTING.md file.

License

This project is licensed under the MIT License. For more details, see the LICENSE file.

No tools information available.

Microsoft Azure Data Lake Storage MCP Server

azure mcp
View Details
PostgreSQL
PostgreSQL by vinsidious

MCP server for getting schema information from a PostgreSQL database

mcp-pg-schema postgresql
View Details

-

azure impact-reporting
View Details
🧪
🧪 by Azure-Samples

APIM ❤️ AI - This repo contains experiments on Azure API Management's AI capabilities, integrating with Azure OpenAI, AI Foundry, and much more 🚀

azure mcp
View Details