AI Prompt: Add an instant REST + GraphQL API over the Azure SQL Database container with Data API Builder
Role: You are an expert agent standing up a no-code REST and GraphQL API over the project's local database using Microsoft Data API Builder (DAB).
Purpose: Expose existing tables as a working API - REST at /api/<Entity> and GraphQL at /graphql - driven entirely by dab-config.json, with the connection string supplied through an environment variable and no application code. Optionally expose DAB's built-in MCP endpoint (an API surface DAB provides, not a standalone SQL MCP server).
Scope: Assumes the container is running and the application database (appdb) exists with at least one table. If it is not running, start it and provision appdb first (the engine does not auto-create databases).
Read the entire instruction set before executing.
The database is the Azure SQL engine image sqldbpreview-dpgaeqhmgphzd4bk.azurecr.io/azure-sql/db-dev:latest (SERVERPROPERTY('EngineEdition') = 5), not mcr.microsoft.com/mssql/server. appdb must already exist on a master connection, with a table to expose (seed one if needed).
export SQL_CONNECTION_STRING="Server=localhost,1433;Database=appdb;User Id=sa;Password=$MSSQL_SA_PASSWORD;TrustServerCertificate=true"Use User Id= / Password= / Database= and TrustServerCertificate=true (self-signed cert). Never write the connection string into dab-config.json.
dotnet tool install --global Microsoft.DataApiBuilder # once; needs .NET 8
dab init --database-type mssql \
--connection-string "@env('SQL_CONNECTION_STRING')" \
--host-mode Development
dab add Book --source dbo.Books --source.type table --permissions "anonymous:*"Add one dab add per table. The entity name is the API path; --source is the real schema.table. Declare relationships with dab update <Entity> --relationship <name> --target.entity <Target> --cardinality one|many --relationship.fields "src:tgt".
dab start # http://localhost:5000
curl http://localhost:5000/api/Book
curl -s http://localhost:5000/graphql -H 'Content-Type: application/json' \
-d '{"query":"{ books { items { id title } } }"}'REST is at /api/<Entity>, GraphQL at /graphql, OpenAPI at /api/openapi, Swagger UI at /swagger (Development mode), health at /health.
DAB (v1.7+; use the latest 2.x) also serves an MCP endpoint at http://localhost:5000/mcp from the same config, enabled by default. Present it as a DAB-provided API surface over your entities, governed by the same permissions - not as a standalone Microsoft SQL MCP server. Scope it with runtime.mcp.dml-tools (globally) or dab update <Entity> --mcp.dml-tools false (per entity).
- The database is the Azure SQL engine (EngineEdition=5), never the SQL Server image.
appdbexists beforedab start; DAB connects withDatabase=appdbandTrustServerCertificate=true.- The connection string is provided via
@env('SQL_CONNECTION_STRING'), not hardcoded indab-config.json. dab startserves REST at/api/<Entity>and GraphQL at/graphql; aGETon an entity returns rows.- If the MCP endpoint is exposed, it is described as a DAB API surface, not a standalone SQL MCP server.
- Do not use the SQL Server image
mcr.microsoft.com/mssql/server. - Do not hardcode the connection string or SA password into
dab-config.json. - Do not ship
anonymous:*permissions beyond local development. - Do not present DAB's MCP endpoint as a standalone Microsoft SQL MCP server.