Discover how AI models and apps work with Azure Database for PostgreSQL using MCP for standardized, scalable, and secure integrations.
by: Shreya R. Aithal, Product Manager II; Krishnakumar Ravi, Principal Group Engineering Manager; Maxim Lukiyanov, PhD, Principal PM Manager
Large language models (LLMs) are revolutionizing AI, serving as the backbone of intelligent systems that drive business innovation and efficiency. These models, while powerful, are trained on public data and often lack the specific context of your unique datasets. Bridging the gap between AI models and external tools, data sources, or APIs is crucial for developing advanced and accurate AI applications, but each new integration often requires a custom solution, which is neither scalable nor easy to maintain. This is where the Model Context Protocol (MCP) comes into play - a new and emerging open protocol designed to integrate AI models with the environments where your data and tools reside in a scalable, standardized, and secure manner.
Today, we are thrilled to introduce the public preview of an MCP Server that let’s your AI applications and models talk to your data hosted in Azure Database for PostgreSQL according to the MCP standard! In this blog, we will delve into the intricacies of MCP and demonstrate how you can enhance your AI models using this new MCP Server.
What is MCP?
Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to AI models, particularly LLMs. Think of it as a common language that enables AI assistants to establish two-way connections with external data sources and services. It promotes interoperability by allowing diverse systems to work together seamlessly, supports scalable and secure integration with enterprise applications and data, and future-proofs these integrations, ensuring smooth transitions between different models or platforms.
General architecture and key components
The following image describes MCP’s client-server architecture and key components:
- MCP Host: AI applications, agents, programs, or tools like Copilot Studio and Claude Desktop that seek to access data through MCP.
- MCP Client: An MCP Host includes an MCP client component responsible for connecting to one or more MCP servers and relaying information between the application’s AI models and those servers.
- MCP Server: A lightweight program that interfaces with data sources, services or APIs and exposes the following standardized capabilities or actions to the MCP clients:
- Tools: Functions that can be invoked by AI models to fetch information or perform actions like sending a message or updating database records.
- Resources: Data, files or documents that a server exposes to the AI applications, providing a rich interface for applications and MCP servers to interact, beyond using text.
- Prompts: Pre-defined templates that an application user can request for effective AI interactions to accomplish specific tasks.
- Data sources, services and APIs: External systems with the data context required to enhance the AI models, which MCP servers can securely access.
An MCP client can connect to multiple MCP Servers, each dedicated to a specific data source. Each MCP server is capable of fetching data or performing actions on its respective service and communicates using MCP’s standardized message format. Here is an open-source repository of MCP Servers that you can use to get started with integrating your data sources: modelcontextprotocol/servers: Model Context Protocol Servers.
Azure Database for PostgreSQL MCP Server
To leverage the advantages of MCP for integrating your AI models with data hosted in Azure Database for PostgreSQL – Flexible Server, we are excited to bring to you the new Azure Database for PostgreSQL MCP Server in Public Preview. 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 fashion.
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
In this section, we’ll show you how to use the MCP server with Claude Desktop and Visual Studio Code to gain valuable insights and visualizations from your databases through natural language queries!
Before diving in, please refer to our GitHub repository: Azure-Samples/azure-postgresql-mcp: Azure Database for PostgreSQL MCP server to ensure all the prerequisites are in place. You'll also find detailed onboarding guidance, demo videos and the MCP server code available there.
Install the Azure Database for PostgreSQL MCP Server
1. Clone the azure-postgresql-mcp repository:
git clone https://github.com/Azure-Samples/azure-postgresql-mcp.git
cd azure-postgresql-mcp
2. Create a virtual environment:
python -m venv azure-postgresql-mcp-venv
.\azure-postgresql-mcp-venv\Scripts\activate
Note: The above commands are applicable to Windows OS. For users of other operating systems, please refer to the full guide in the GitHub repository.
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 this demo video or read on for detailed instructions.
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>"
}
}
}
}
Note: In this example, we use password-based authentication to connect the MCP Server to Azure Database for PostgreSQL for testing purposes only. However, we recommend using Microsoft Entra authentication. Please refer to these instructions for guidance.
3. Restart the Claude Desktop app.
4. Upon restarting, you should see a hammer icon at the bottom of the input box, as shown in the following screenshot. Selecting this icon will display the tools exposed by the MCP Server.
You are now all set to start interacting with your data using natural language queries through Claude Desktop!
Use the MCP Server with Visual Studio Code
Watch this demo video or read on for detailed instructions.
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>"
}
}
}
}
}
Note: In this example, we use password-based authentication to connect the MCP Server to Azure Database for PostgreSQL for testing purposes only. However, we recommend using Microsoft Entra authentication. Please refer to these instructions for guidance.
4. Select the “Copilot” icon in the upper-right corner to open the GitHub Copilot Chat window.
5. Next, choose “Agent mode” from the dropdown at the bottom of the chat input box.
6. Click on “Select Tools” to view the Tools exposed by the MCP Server.
You are now all set to start interacting with your data using natural language queries through Visual Studio Code!
What’s next?
Start using Model Context Protocol (MCP) today, to integrate your AI apps and agents with your data sources and services. We hope that the new Azure Database for PostgreSQL MCP Server eases your MCP integration journey and helps you unlock the full combined potential of AI and your data stored in Azure Database for PostgreSQL!
Stay tuned for updates as we further enhance the capabilities of the MCP Server to introduce new ways for AI models to interact with your business data. Meanwhile we look forward to your feedback and learning more about how this functionality benefits you. Feel free to comment below or write to us with your feedback and queries at AskAzureDBforPostgreSQL@service.microsoft.com.
Updated Apr 18, 2025
Version 5.0ShreyaAithal
Microsoft
Joined May 24, 2021
Azure Database for PostgreSQL Blog
Follow this blog board to get notified when there's new activity