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

1. Prerequisites
- Python 3.8+
- ODBC Driver 18 for SQL Server — Download 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
.envto 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
Install (one-time):
winget install Cloudflare.cloudflaredClose and reopen your terminal after install.
In a new terminal (keep the server running in the first one):
cloudflared tunnel --url http://localhost:8000Copy the URL from the output:
https://electronic-annie-jose-spoken.trycloudflare.comYour 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
- Go to Copilot Studio
- Open your agent → Tools → Add a tool → New tool → Model Context Protocol
- 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
{ "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" } } } }