Azure SQL MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
git clone <your-repo-url>
cd azure-sql-mcp-server
python -m venv venv
pip install -r requirements.txt
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add -e "AZURE_SQL_SERVER=${AZURE_SQL_SERVER}" -e "AZURE_SQL_DATABASE=${AZURE_SQL_DATABASE}" -e "AZURE_SQL_USERNAME=${AZURE_SQL_USERNAME}" -e "AZURE_SQL_PASSWORD=${AZURE_SQL_PASSWORD}" -e "AZURE_SQL_DRIVER=${AZURE_SQL_DRIVER}" azure-sql-mcp -- python "<FULL_PATH_TO_COPILOT_STUDIO_AZURE_SQL_MCP>/dist/index.js"

Replace <FULL_PATH_TO_COPILOT_STUDIO_AZURE_SQL_MCP>/dist/index.js with the actual folder you prepared in step 1.

Required:AZURE_SQL_SERVERAZURE_SQL_DATABASEAZURE_SQL_USERNAMEAZURE_SQL_PASSWORDAZURE_SQL_DRIVER
README.md

Connects Microsoft Copilot Studio to your Azure SQL Database.

Azure SQL MCP Server — Complete Guide

A Model Context Protocol (MCP) server that connects Microsoft Copilot Studio to your Azure SQL Database. Supports 12 tools for querying, CRUD operations, schema inspection, search, and chart visualization.


Architecture

alt text

1. Prerequisites

  • Python 3.8+
  • ODBC Driver 18 for SQL ServerDownload here
  • Azure SQL Database with server hostname, database name, username, and password
  • Cloudflare Tunnel (for local testing) — winget install Cloudflare.cloudflared

Install ODBC Driver

Windows: Download and install from the link above.

macOS:

brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
brew install msodbcsql18 mssql-tools18

Linux (Ubuntu/Debian):

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18

2. Installation

git clone <your-repo-url>
cd azure-sql-mcp-server
python -m venv venv
venv\Scripts\activate          # Windows
# source venv/bin/activate     # macOS/Linux
pip install -r requirements.txt

3. Configuration

Create a .env file in the project root:

AZURE_SQL_SERVER=your-server.database.windows.net
AZURE_SQL_DATABASE=your-database-name
AZURE_SQL_USERNAME=your-username
AZURE_SQL_PASSWORD=your-password
AZURE_SQL_DRIVER=ODBC Driver 18 for SQL Server

Never commit .env to version control. Add it to .gitignore.


4. Code Fixes

The MCP SDK requires specific configuration. Apply these 3 fixes to azure_sql_mcp.py:

Fix 1: Lifespan function signature

# ❌ BEFORE
@asynccontextmanager
async def app_lifespan():

# ✅ AFTER — FastMCP passes the server instance
@asynccontextmanager
async def app_lifespan(server: FastMCP):

Fix 2: Host and port on the constructor

# ❌ BEFORE
mcp = FastMCP("azure_sql_mcp", lifespan=app_lifespan)

# ✅ AFTER — host/port go on the constructor, NOT on run()
mcp = FastMCP("azure_sql_mcp", host="0.0.0.0", port=8000, lifespan=app_lifespan)

Fix 3: HTTP transport

# ❌ BEFORE
if __name__ == "__main__":
    mcp.run()

# ✅ AFTER — streamable-http (with hyphen) for Copilot Studio
if __name__ == "__main__":
    mcp.run(transport="streamable-http")

5. Running the Server

cd azure-sql-mcp-server
.\venv\Scripts\Activate.ps1       # Windows
python azure_sql_mcp.py

You should see:

INFO: Initializing Azure SQL MCP server...
INFO: Database connection established
INFO: Database connection verified
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

MCP endpoint: http://localhost:8000/mcp


6. Exposing to the Internet

Copilot Studio needs a public HTTPS URL. Use Cloudflare Tunnel (free, no signup).

Why not ngrok? ngrok's free tier shows a browser warning page (ERR_NGROK_6024) that blocks API clients like Copilot Studio.

Steps

  1. Install (one-time):

    winget install Cloudflare.cloudflared
    

    Close and reopen your terminal after install.

  2. In a new terminal (keep the server running in the first one):

    cloudflared tunnel --url http://localhost:8000
    
  3. Copy the URL from the output:

    https://electronic-annie-jose-spoken.trycloudflare.com
    
  4. Your MCP server URL for Copilot Studio:

    https://electronic-annie-jose-spoken.trycloudflare.com/mcp
    

URLs change on restart. For a permanent URL, deploy to Azure App Service (see Production Deployment).


7. Copilot Studio Setup

Step 1: Add the MCP Server

  1. Go to Copilot Studio
  2. Open your agent → ToolsAdd a toolNew toolModel Context Protocol
  3. Fill in:
Field Value
Server name azure-sql-mcp
Server description `Azure S

Tools (4)

query_databaseExecutes a SQL query against the connected Azure SQL database.
list_tablesLists all tables available in the database schema.
get_table_schemaRetrieves the column definitions for a specific table.
generate_chartGenerates a data visualization chart based on query results.

Environment Variables

AZURE_SQL_SERVERrequiredThe hostname of your Azure SQL server.
AZURE_SQL_DATABASErequiredThe name of the specific database to connect to.
AZURE_SQL_USERNAMErequiredThe username for database authentication.
AZURE_SQL_PASSWORDrequiredThe password for database authentication.
AZURE_SQL_DRIVERrequiredThe ODBC driver name to use for the connection.

Configuration

claude_desktop_config.json
{ "mcpServers": { "azure-sql-mcp": { "command": "python", "args": ["/path/to/azure_sql_mcp.py"], "env": { "AZURE_SQL_SERVER": "your-server.database.windows.net", "AZURE_SQL_DATABASE": "your-database-name", "AZURE_SQL_USERNAME": "your-username", "AZURE_SQL_PASSWORD": "your-password", "AZURE_SQL_DRIVER": "ODBC Driver 18 for SQL Server" } } } }

Try it

List all the tables currently available in my Azure SQL database.
Show me the schema for the 'Customers' table.
Run a query to find the top 5 highest spending customers from the 'Orders' table.
Generate a bar chart showing total sales per month for the last year.

Frequently Asked Questions

What are the key features of Azure SQL MCP Server?

Supports 12 specialized tools for database interaction. Enables natural language querying of SQL databases. Provides schema inspection capabilities. Includes data visualization tools for generating charts. Supports CRUD operations for record management.

What can I use Azure SQL MCP Server for?

Enabling non-technical staff to query business data using natural language. Automating the generation of visual reports from SQL data within Copilot Studio. Streamlining database schema exploration for developers. Performing quick CRUD operations on database records via chat interface.

How do I install Azure SQL MCP Server?

Install Azure SQL MCP Server by running: git clone <your-repo-url> && cd azure-sql-mcp-server && python -m venv venv && pip install -r requirements.txt

What MCP clients work with Azure SQL MCP Server?

Azure SQL MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Azure SQL MCP Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare