Test project for Data API Builder (DAB) SQL MCP Server with an Azure AI Foundry agent.
Azure AI Foundry Agent (GPT-4o)
↓ MCP protocol
SQL MCP Server (DAB v1.7)
↓ T-SQL (deterministic)
Azure SQL Database (OrdersDB)
| Table | Description | Rows |
|---|---|---|
dbo.Categories |
Product categories (Electronics, Books, Clothing) | 3 |
dbo.Products |
Products with prices, linked to categories | 10 |
dbo.Customers |
Registered customers | 5 |
dbo.Orders |
Orders with status and totals | 8 |
dbo.OrderItems |
Line items linking orders to products | 20 |
- Category 1:M Products
- Customer 1:M Orders
- Order 1:M OrderItems
- Product 1:M OrderItems
- .NET 8 SDK
- Azure CLI (
az logincompleted) - Python 3.10+
- Azure AI Foundry project with GPT-4o deployed
dotnet tool install --global Microsoft.DataApiBuilder --prerelease
dab --version # should be >= 1.7.x-rcdab start --verboseThis starts:
- REST:
http://localhost:5000/api/{entity} - GraphQL:
http://localhost:5000/graphql - MCP:
http://localhost:5000/mcp
curl http://localhost:5000/api/Productcp .env.template .env
# Edit .env with your Azure AI Foundry project detailspip install -r requirements.txt
python test_agent.pyAutomated scripts are provided in scripts/ to create the full Azure environment.
- Azure CLI logged in (
az login) - Python 3.10+ with
pyodbcinstalled (for database seeding) - ODBC Driver 17 for SQL Server
Creates resource group, Azure SQL Server (Azure AD-only auth), database, and firewall rules.
scripts/01-create-azure-resources.shRuns sql/setup.sql to create tables and insert sample data. Enables Query Store.
scripts/02-seed-database.shBuilds the Docker image in ACR and deploys to Azure Container Apps.
scripts/03-deploy-container-app.shAfter deployment, update .env with the MCP URL printed by the script.
Creates an Azure AI Foundry hub, project, and deploys GPT-4o.
scripts/04-create-foundry-project.shAfter creation, update .env with the PROJECT_ENDPOINT and MODEL_DEPLOYMENT_NAME printed by the script.
Builds and deploys the Query Tracer UI to Azure Container Apps.
scripts/05-deploy-streamlit.shAfter deployment, grant SQL read access to the container's managed identity (T-SQL printed by the script).
Override defaults with environment variables:
RESOURCE_GROUP=my-rg \
LOCATION=westeurope \
SQL_SERVER_NAME=my-sql-server \
scripts/01-create-azure-resources.shDelete all Azure resources:
scripts/99-teardown.shThe dab-config.json file controls everything:
- Database connection: Azure SQL with Azure AD authentication
- Entities: 5 entities with semantic descriptions for AI agent understanding
- Relationships: Cross-entity navigation (e.g., Order → Customer)
- MCP: Enabled at
/mcpwith all DML tools active - Permissions:
anonymous:*for testing (restrict in production)
The SQL MCP Server exposes 6 DML tools:
| Tool | Description |
|---|---|
describe_entities |
List available entities and their fields |
create_record |
Insert a new record |
read_records |
Read records with filters, pagination, sorting |
update_record |
Update an existing record |
delete_record |
Delete a record |
execute_entity |
Execute stored procedures |
The agent never generates raw SQL. Instead, it calls structured MCP tools → DAB's Query Builder generates deterministic T-SQL internally. This eliminates the risks of AI-generated SQL.
A Streamlit-based UI to visualize the SQL queries that DAB generates when the AI agent calls MCP tools.
- Real-time SQL tracing via Azure SQL Query Store
- Query classification — maps each SQL statement back to the probable MCP tool (
read_records,create_record, etc.) - Performance metrics — duration, CPU, IO reads, row count per query
- Timeline chart — visual bar chart of query durations over time
- Built-in agent launcher — run
test_agent.pydirectly from the UI - Filters — by query type (SELECT/INSERT/UPDATE/DELETE), table, time window
streamlit run query_tracer.py| Resource | Name |
|---|---|
| Resource Group | rg-sql-mcp |
| Azure SQL Server | sql-mcp-pietrobr.database.windows.net |
| Database | OrdersDB |
| Auth | Azure AD-only (no SQL auth) |
scripts/99-teardown.sh
# or manually:
az group delete --name rg-sql-mcp --yes --no-wait