MCP: Connecting AI to Your Database
Use Model Context Protocol to connect AI agents and tools directly to SQL Server and Fabric databases β giving them schema awareness and the ability to query data safely.
Giving AI tools direct access to your database
Imagine giving a new colleague a tour of the office.
Without a tour, they wander around guessing where things are. With a tour, they know: βCustomer data is in this cabinet, financial reports are over there, and you need a key for the vault.β That is what MCP does for AI tools β it gives them a guided tour of your database so they know what tables exist, what columns they contain, and how to query them properly.
MCP (Model Context Protocol) is an open standard that connects AI tools (like GitHub Copilot or custom agents) to data sources. For SQL, it means Copilot can see your actual schema and write queries that work with your real tables β not generic guesses.
What is MCP?
MCP follows a client-server architecture:
| Component | Role | Examples |
|---|---|---|
| MCP Client | The AI tool that consumes data | GitHub Copilot, VS Code, Copilot Studio, Foundry agents |
| MCP Server | Exposes data and tools via the MCP protocol | SQL MCP Server (via Data API Builder), Fabric MCP Server |
| Transport | How client and server communicate | HTTP/SSE (remote), stdio (local) |
The MCP server tells the client: βHere are the tables I have, here are the columns, and here are the queries you can run.β The client uses this information to generate accurate, schema-aware SQL.
SQL MCP Server (via Data API Builder)
Microsoft provides an MCP server for SQL databases built on Data API Builder (DAB). It exposes your database schema and query capabilities to any MCP-compatible client.
How it works
βββββββββββββββββββ MCP Protocol ββββββββββββββββββββ
β GitHub Copilot β ββββββββββββββββββββΊ β SQL MCP Server β
β (MCP Client) β β (Data API β
β β β Builder) β
βββββββββββββββββββ ββββββββββ¬ββββββββββ
β
ββββββββββΌββββββββββ
β SQL Server / β
β Azure SQL / β
β Fabric SQL DB β
ββββββββββββββββββββ
Connecting to SQL MCP Server endpoints
- Install the SQL MCP Server (part of Data API Builder tooling)
- Configure the connection β specify your SQL Server endpoint and authentication
- Register in your MCP client β add the server endpoint to Copilot or VS Code settings
In VS Code settings (.vscode/mcp.json or user settings):
{
"mcpServers": {
"sql-server": {
"type": "http",
"url": "http://localhost:5000/mcp",
"headers": {
"Authorization": "Bearer ${env:SQL_MCP_TOKEN}"
}
}
}
}
What the SQL MCP Server exposes
| MCP Capability | What It Provides |
|---|---|
| Resources | Database schema β tables, views, columns, data types, relationships |
| Tools | Query execution β run SELECT queries against the database |
| Prompts | Pre-built prompt templates for common SQL tasks |
Connecting to Fabric lakehouse
For Fabric SQL databases and lakehouses, MCP connectivity allows AI tools to understand and query your Fabric data:
- Fabric workspace must have Copilot enabled
- SQL analytics endpoint provides the connection for MCP
- Authentication uses Microsoft Entra ID (Azure AD)
The Fabric MCP endpoint gives AI tools access to:
- Lakehouse tables and views
- SQL database objects
- Data warehouse schemas
Configuring MCP tool options in Copilot
When using MCP with GitHub Copilot Chat, you can:
Select tools
In the chat panel, use @ to reference available MCP tools:
@sql-serverβ query your connected SQL database@fabricβ query your Fabric lakehouse
Configure model options
Switch between available AI models in the chat session:
- Different models have different strengths (speed vs reasoning)
- Some models handle SQL better than others
- Model selection affects token limits and response quality
| Feature | Without MCP | With MCP |
|---|---|---|
| Schema awareness | Copilot guesses table/column names | Copilot knows your exact schema |
| Query accuracy | Generic suggestions, often wrong table names | Schema-accurate queries using real tables |
| Data type awareness | May suggest wrong data types | Knows column types, suggests appropriate functions |
| Relationship awareness | Cannot know foreign key relationships | Understands JOINs between your tables |
| Security | No access control on what Copilot sees | MCP server controls which objects are exposed |
Scenario: Leo's MCP setup at SearchWave
Leo Torres at SearchWave connects the SQL MCP Server to his VS Code instance. Now when he asks Copilot: βWrite a query to find the top 10 products by search frequency this month,β Copilot generates a query using SearchWaveβs actual table names (search_events, products, search_metrics) with correct column names and JOINs.
Without MCP, Copilot would have guessed generic names like Products and Searches β requiring Leo to fix every table and column reference manually.
Leo also connects to the Fabric lakehouse MCP endpoint for analytics queries against the companyβs data warehouse, giving Copilot visibility into both the OLTP database and the analytics layer.
Exam tip: MCP security boundaries
The MCP server controls what the AI client can see and do. Key security principles:
- Least privilege β expose only the tables and views the AI needs, not the entire database
- Read-only by default β MCP servers typically expose SELECT only, not INSERT/UPDATE/DELETE
- Authentication β MCP connections should use managed identity or token-based auth, not embedded credentials
- Audit β log all queries executed through MCP for compliance
The exam may ask about securing MCP endpoints β the answer usually involves restricting which objects are exposed and using proper authentication.
Dev at PixelForge Studios wants GitHub Copilot to generate accurate queries against the company's SQL database. Currently, Copilot suggests generic table names that do not match the actual schema. What should Dev configure?
π¬ Video coming soon
Next up: Encryption: Always Encrypted and Column-Level β protect sensitive data at rest and in transit with SQL Serverβs encryption features.