Skip to content

lostspace003/copilot-studio-mcp-agent-sql

Repository files navigation

Azure SQL MCP Server

CI PyPI License: MIT

A Model Context Protocol (MCP) server that lets AI agents query and explore Azure SQL databases. It exposes five tools for executing SQL, listing tables, inspecting schemas, retrieving paginated data, and fetching database metadata.

Designed for use with Microsoft Copilot Studio, Claude Desktop, VS Code, and any other MCP-compatible client.

Tools

Tool Description Read-only
azure_sql_execute_query Execute arbitrary SQL (SELECT, INSERT, UPDATE, DELETE) with parameterized queries No
azure_sql_list_tables List all tables with schemas and row counts, or get info for a specific table Yes
azure_sql_get_table_schema Get column names, data types, nullable status, defaults, and primary key info Yes
azure_sql_get_table_data Retrieve rows with pagination (limit/offset) Yes
azure_sql_get_database_info Get database name, SQL Server version, creation date, and object counts Yes

All tools return either Markdown (human-readable) or JSON (machine-readable) output.

Prerequisites

Install the ODBC Driver

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

Windows: Download from Microsoft ODBC Driver 18.

Quick Start

Using uvx (recommended)

uvx mcp-server-azure-sql

Using pip

pip install mcp-server-azure-sql
mcp-server-azure-sql

From source

git clone https://github.com/Microsoft-Course-Content/copilot-studio-mcp-agent-sql.git
cd copilot-studio-mcp-agent-sql
pip install -e .
mcp-server-azure-sql

Configuration

Set these environment variables (or create a .env file):

Variable Required Description
AZURE_SQL_SERVER Yes Server hostname (e.g., myserver.database.windows.net)
AZURE_SQL_DATABASE Yes Database name
AZURE_SQL_USERNAME Yes Database username
AZURE_SQL_PASSWORD Yes Database password
AZURE_SQL_DRIVER No ODBC driver (default: ODBC Driver 18 for SQL Server)
MCP_API_KEY No API key for HTTP mode authentication
PORT No HTTP server port (default: 8000)

Copy the example file to get started:

cp .env.example .env
# Edit .env with your Azure SQL credentials

Usage with MCP Clients

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "azure-sql": {
      "command": "uvx",
      "args": ["mcp-server-azure-sql"],
      "env": {
        "AZURE_SQL_SERVER": "your-server.database.windows.net",
        "AZURE_SQL_DATABASE": "your-database",
        "AZURE_SQL_USERNAME": "your-username",
        "AZURE_SQL_PASSWORD": "your-password"
      }
    }
  }
}

VS Code

Add to your .vscode/mcp.json:

{
  "servers": {
    "azure-sql": {
      "command": "uvx",
      "args": ["mcp-server-azure-sql"],
      "env": {
        "AZURE_SQL_SERVER": "your-server.database.windows.net",
        "AZURE_SQL_DATABASE": "your-database",
        "AZURE_SQL_USERNAME": "your-username",
        "AZURE_SQL_PASSWORD": "your-password"
      }
    }
  }
}

Microsoft Copilot Studio

For Copilot Studio integration, use HTTP transport mode for deployment:

mcp-server-azure-sql --transport http

See COPILOT_STUDIO_SETUP.md for the complete step-by-step deployment and integration guide.

MCP Inspector (debugging)

npx @modelcontextprotocol/inspector uvx mcp-server-azure-sql

Transport Modes

Mode Command Use Case
stdio (default) mcp-server-azure-sql Local clients: Claude Desktop, VS Code, MCP Inspector
HTTP mcp-server-azure-sql --transport http Remote deployment: Copilot Studio, Azure App Service, Docker

Docker

docker build -t mcp-server-azure-sql .
docker run -p 8000:8000 \
  -e AZURE_SQL_SERVER="your-server.database.windows.net" \
  -e AZURE_SQL_DATABASE="your-database" \
  -e AZURE_SQL_USERNAME="your-username" \
  -e AZURE_SQL_PASSWORD="your-password" \
  mcp-server-azure-sql

Development

git clone https://github.com/Microsoft-Course-Content/copilot-studio-mcp-agent-sql.git
cd copilot-studio-mcp-agent-sql
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Lint
ruff check src/ tests/
ruff format src/ tests/

Security

  • All user input uses parameterized queries (? placeholders) to prevent SQL injection
  • Multiple SQL statements in a single query are rejected
  • Credentials are loaded from environment variables, never hardcoded
  • HTTP mode supports API key authentication via MCP_API_KEY
  • Connections use TLS encryption by default (Encrypt=yes)
  • Use a least-privilege database account in production

License

MIT - see LICENSE.

About

A production-ready Model Context Protocol (MCP) server that enables Microsoft Copilot Studio agents to interact with Azure SQL databases using natural language. Query tables, inspect schemas, and retrieve data - all through conversational AI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors