Skip to content

Commit 686ec1e

Browse files
authored
Merge branch 'main' into copilot/support-xml-data-type-mssql
2 parents f4b9b5f + a62cb9e commit 686ec1e

196 files changed

Lines changed: 4560 additions & 374 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ The file `dab-config.json` is automatically created through this process. These
169169
"allow-credentials": false
170170
},
171171
"authentication": {
172-
"provider": "StaticWebApps"
172+
"provider": "AppService"
173173
},
174174
"mode": "development"
175175
}
1.12 MB
Loading
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
# Deploying SQL MCP Server implemented in Data API builder and Integrating with Azure AI Foundry
2+
3+
This document provides an end‑to‑end guide to stand up a **SQL MCP Server** with **Model Context Protocol (MCP)** tools implemented in **Data API builder (DAB)** container that also exposes **REST** and **GraphQL** endpoints, and to integrate those MCP tools with an **Azure AI Foundry Agent**.
4+
5+
<img alt="Architecture diagram showing SQL MCP Server integration with Azure AI Foundry" src="../media/dab-aifoundry-architecture.png" />
6+
7+
## 1. Architecture Overview
8+
9+
**Components**
10+
- **Azure SQL Database** hosting domain tables and stored procedures.
11+
- **DAB container** (Azure Container Instances in this guide) that:
12+
- reads `dab-config.json` from an **Azure Files** share at startup,
13+
- exposes **REST**, **GraphQL**, and **MCP** endpoints.
14+
- **Azure Storage (Files)** to store and version `dab-config.json`.
15+
- **Azure AI Foundry Agent** configured with an **MCP tool** pointing to the SQL MCP Server endpoint.
16+
17+
**Flow**
18+
1. DAB starts in ACI → reads `dab-config.json` from the mounted Azure Files share.
19+
2. DAB exposes `/api` (REST), `/graphql` (GraphQL), and `/mcp` (MCP).
20+
3. Azure AI Foundry Agent invokes MCP tools to read/update data via DAB’s surface (tables, views and stored procedures).
21+
22+
23+
## 2. Prerequisites
24+
- Azure Subscription with permissions for Resource Groups, Storage, ACI, and Azure SQL.
25+
- Azure SQL Database provisioned and reachable from ACI.
26+
- Azure CLI (`az`) and .NET SDK installed locally.
27+
- DAB CLI version **1.7.81 or later**.
28+
- Outbound network access from ACI to your Azure SQL server.
29+
30+
31+
## 3. Prepare the Database
32+
33+
You need to create the necessary tables and stored procedures in your Azure SQL Database. Below is an example of how to create a simple `Products` table and a stored procedure to retrieve products by category.
34+
35+
**Example:**
36+
37+
1. Connect to your Azure SQL Database using Azure Data Studio, SQL Server Management Studio, or the Azure Portal's Query Editor.
38+
39+
2. Run the following SQL script to create a sample table and stored procedure:
40+
41+
```sql
42+
-- Create Products table
43+
CREATE TABLE Products (
44+
ProductID INT IDENTITY(1,1) PRIMARY KEY,
45+
Name NVARCHAR(100) NOT NULL,
46+
Category NVARCHAR(50) NOT NULL,
47+
Price DECIMAL(10,2) NOT NULL
48+
);
49+
50+
-- Create stored procedure to get products by category
51+
CREATE PROCEDURE GetProductsByCategory
52+
@Category NVARCHAR(50)
53+
AS
54+
BEGIN
55+
SET NOCOUNT ON;
56+
SELECT ProductID, Name, Category, Price
57+
FROM Products
58+
WHERE Category = @Category;
59+
END;
60+
```
61+
62+
## 4. Install DAB CLI and Bootstrap Configuration
63+
64+
```
65+
dotnet tool install --global Microsoft.DataApiBuilder --version 1.7.81
66+
export DATABASE_CONNECTION_STRING="Server=<server>.database.windows.net;Database=<db>;User ID=<user>;Password=<pwd>;Encrypt=True;"
67+
68+
dab init \
69+
--database-type "mssql" \
70+
--connection-string "@env('DATABASE_CONNECTION_STRING')" \
71+
--host-mode "Development" \
72+
--rest.enabled true \
73+
--graphql.enabled true \
74+
--mcp.enabled true \
75+
--mcp.path "/mcp"
76+
77+
```
78+
79+
## 5. Add all required entities (tables and stored procedures) to `dab-config.json` and enable MCP tools in the config
80+
81+
Here is how to add a table entity and a stored procedure to your `dab-config.json`, and ensure MCP tools are enabled:
82+
83+
1. **Open your `dab-config.json` file.**
84+
85+
2. **Add an entity (table) definition** under the `"entities"` section. For example, to expose a `Customers` table:
86+
```
87+
"entities": {
88+
"Customers": {
89+
"source": "Customers",
90+
"rest": true,
91+
"graphql": true,
92+
"mcp": true,
93+
"permissions": [
94+
{
95+
"role": "anonymous",
96+
"actions": [ "read", "create", "update", "delete" ]
97+
}
98+
]
99+
}
100+
}
101+
```
102+
103+
3. **Add a stored procedure** under the "entities" section. For example, to expose a stored procedure called GetCustomerOrders:
104+
105+
```
106+
"GetCustomerOrders": {
107+
"source": {
108+
"object": "GetCustomerOrders",
109+
"type": "stored-procedure"
110+
},
111+
"rest": true,
112+
"graphql": true,
113+
"mcp": true,
114+
"permissions": [
115+
{
116+
"role": "anonymous",
117+
"actions": [ "execute" ]
118+
}
119+
]
120+
}
121+
```
122+
123+
Note: Make sure the "entities" section is a valid JSON object. If you have multiple entities, separate them with commas.
124+
125+
4. **Ensure MCP is enabled in the "runtime" section:**
126+
127+
```
128+
"runtime": {
129+
"rest": { "enabled": true },
130+
"graphql": { "enabled": true },
131+
"mcp": {
132+
"enabled": true,
133+
"path": "/mcp"
134+
}
135+
}
136+
```
137+
138+
5. **Example dab-config.json structure:**
139+
140+
```
141+
{
142+
"data-source": {
143+
"database-type": "mssql",
144+
"connection-string": "@env('DATABASE_CONNECTION_STRING')"
145+
},
146+
"runtime": {
147+
"rest": { "enabled": true },
148+
"graphql": { "enabled": true },
149+
"mcp": {
150+
"enabled": true,
151+
"path": "/mcp"
152+
}
153+
},
154+
"entities": {
155+
"Customers": {
156+
"source": "Customers",
157+
"rest": true,
158+
"graphql": true,
159+
"mcp": true,
160+
"permissions": [
161+
{
162+
"role": "anonymous",
163+
"actions": [ "read", "create", "update", "delete" ]
164+
}
165+
]
166+
},
167+
"GetCustomerOrders": {
168+
"source": {
169+
"object": "GetCustomerOrders",
170+
"type": "stored-procedure"
171+
},
172+
"rest": true,
173+
"graphql": true,
174+
"mcp": true,
175+
"permissions": [
176+
{
177+
"role": "anonymous",
178+
"actions": [ "execute" ]
179+
}
180+
]
181+
}
182+
}
183+
}
184+
```
185+
186+
6. **Save the file.**
187+
188+
## 6. Store dab-config.json in Azure Files
189+
190+
1. **Create a Storage Account** (if you don't have one):
191+
az storage account create
192+
--name
193+
--resource-group
194+
--location
195+
--sku Standard_LRS
196+
197+
198+
2. **Create a File Share**:
199+
az storage share create
200+
--name
201+
--account-name
202+
203+
204+
3. **Upload `dab-config.json` to the File Share**:
205+
az storage file upload
206+
--account-name
207+
--share-name
208+
--source ./dab-config.json
209+
--path dab-config.json
210+
211+
212+
4. **Retrieve the Storage Account key** (needed for mounting in ACI):
213+
az storage account keys list
214+
--account-name
215+
--resource-group
216+
217+
Use the value of `key1` or `key2` as `<StorageAccountKey>` in the next step.
218+
219+
220+
## 7. Deploy DAB to Azure Container Instances
221+
222+
```
223+
az container create \
224+
--resource-group <RG> \
225+
--name dab-mcp-demo \
226+
--image mcr.microsoft.com/azure-databases/data-api-builder:1.7.81-rc \
227+
--dns-name-label <globally-unique-label> \
228+
--ports 5000 \
229+
--location <location> \
230+
--environment-variables DAB_CONFIG_PATH="/aci/dab-config.json" \
231+
--azure-file-volume-share-name <FileShareName> \
232+
--azure-file-volume-account-name <StorageAccountName> \
233+
--azure-file-volume-account-key <StorageAccountKey> \
234+
--azure-file-volume-mount-path "/aci" \
235+
--os-type Linux \
236+
--cpu 1 \
237+
--memory 1.5 \
238+
--command-line "dotnet Azure.DataApiBuilder.Service.dll --ConfigFileName $DAB_CONFIG_PATH --LogLevel Debug"
239+
```
240+
241+
## 8. Integrate with Azure AI Foundry
242+
243+
Follow these steps to connect your SQL MCP endpoint deployed in DAB to Azure AI Foundry and test the integration:
244+
245+
1. **Create or Open a Project**
246+
- Navigate to the [Azure AI Foundry portal](https://ai.azure.com/foundry) and sign in.
247+
- On the dashboard, click **Projects** in the left navigation pane.
248+
- To create a new project, click **New Project**, enter a name (e.g., `DAB-MCP-Demo`), and click **Create**.
249+
- To use an existing project, select it from the list.
250+
251+
2. **Add an Agent**
252+
- Within your project, go to the **Agents** tab.
253+
- Click **Add Agent**.
254+
- Enter an agent name (e.g., `DAB-MCP-Agent`).
255+
- (Optional) Add a description.
256+
- Click **Create**.
257+
258+
3. **Configure the MCP Tool**
259+
- In the agent's configuration page, go to the **Tools** section.
260+
- Click **Add Tool** and select **MCP** from the tool type dropdown.
261+
- In the **MCP Endpoint URL** field, enter your SQL MCP endpoint in DAB, e.g., `http://<fqdn>/mcp`.
262+
- (Optional) Configure authentication if your endpoint requires it.
263+
- Click **Save** to add the tool.
264+
265+
4. **Test in Playground**
266+
- Go to the **Playground** tab in your project.
267+
- Select the agent you created from the agent dropdown.
268+
- In the input box, enter a prompt that will trigger the MCP tool, such as:
269+
```
270+
Get all records from the Customers entity.
271+
```
272+
- Click **Run**.
273+
- The agent should invoke the MCP tool, which will call your DAB MCP endpoint and return the results.
274+
- **Expected Result:** You should see the data returned from your DAB instance displayed in the Playground output panel.
275+
- If there are errors, check the DAB container logs and ensure the MCP endpoint is reachable from Azure AI Foundry.
File renamed without changes.

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.415",
3+
"version": "8.0.417",
44
"rollForward": "latestFeature"
55
}
66
}

0 commit comments

Comments
 (0)