Commit c3515c8
authored
[MCP] Added fields section for entities and backward compatibility to mappings and key-fields. (#2917)
## Why make this change?
This change introduces richer metadata for entity fields and keys in the
Data API Builder configuration. The goal is to enable semantic metadata
for documentation, client generation, and MCP tools, and to begin
deprecating the legacy mappings and source.key-fields properties.
## What is this change?
- Introduces a new `fields` property for entities in the config schema.
- Each field supports:
- `name`: database column name (required)
- `alias`: exposed name for the field (optional)
- `description`: field description (optional)
- `primary-key`: whether the field is a primary key (optional)
- Updates the JSON schema to enforce that `fields` cannot be used with
legacy `mappings` or `source.key-fields`.
- Updates CLI commands (`dab add`, `dab update`) to support specifying
field alias, description, and primary-key.
- Updates `dab validate` to warn if fields are missing and MCP is
enabled.
- Updates OpenAPI, GraphQL, and MCP `describe_entities` responses to
include field descriptions.
- Adds auto-migration logic to convert legacy `mappings` and
`source.key-fields` to the new `fields` format when relevant CLI flags
are used.
- Maintains backward compatibility: legacy properties are still
supported, but validation enforces that `fields` and legacy props are
not mixed.
## How was this tested?
All automated tests have been executed, updated as necessary, and
completed successfully.
Manually tested with following queries:
1. Update Entity with Field Mappings and Key Fields
`dotnet
C:\DAB\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.dll
update BookAuthor --map "BookID:book_id,AuthorID:author_id"
--source.key-fields "BookID,AuthorID" --config
"C:\DAB\data-api-builder\src\Service\dab-config.json"`
------
Validate the Configuration
`dotnet
C:\DAB\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.dll
validate -c "C:\DAB\data-api-builder\src\Service\dab-config.json"`
-----
Update Entity Field Metadata (Primary Key)
`dotnet
C:\DAB\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.dll
update Todo --fields.name owner_id --fields.primary-key True --config
C:\DAB\data-api-builder\src\Service\dab-config.json`
----
Update Entity Key Fields Only
`dotnet
C:\DAB\data-api-builder\src\out\cli\net8.0\Microsoft.DataApiBuilder.dll
update BookAuthor --source.key-fields "BookID"`
----
Sample new format
`"fields": [
{
"name": "id",
"alias": "id",
"description": "The unique identifier for a todo item",
"primary-key": true
},
{
"name": "title",
"alias": "title",
"description": "The title of the todo item",
"primary-key": false
},
{
"name": "completed",
"alias": "completed",
"description": "Indicates whether the todo item is completed",
"primary-key": false
},
{
"name": "owner_id",
"alias": "owner",
"description": "Hello",
"primary-key": true
},
{
"name": "position",
"alias": "position",
"description": "The position of the todo item in the list",
"primary-key": false
}
],`
-----
GraphQL Introspection Example
Query
`{
__type(name: "Todo") {
name
description
fields {
name
description
}
}
}`
Result
`{
"data": {
"__type": {
"name": "Todo",
"description": "Represents a todo item in the system",
"fields": [
{ "name": "id", "description": "The unique identifier for a todo item"
},
{ "name": "title", "description": "The title of the todo item" },
{ "name": "completed", "description": "Indicates whether the todo item
is completed" },
{ "name": "owner", "description": "Hello" },
{ "name": "position", "description": "The position of the todo item in
the list" }
]
}
}
}`
------
OpenAPI Schema Example
`"Todo": {
"type": "object",
"properties": {
"id": { "type": "string", "description": "The unique identifier for a
todo item", "format": "" },
"title": { "type": "string", "description": "The title of the todo
item", "format": "" },
"completed": { "type": "boolean", "description": "Indicates whether the
todo item is completed", "format": "" },
"owner_id": { "type": "string", "description": "Hello", "format": "" },
"position": { "type": "number", "description": "The position of the todo
item in the list", "format": "" }
},
"description": "Represents a todo item in the system"
}`1 parent 4c5038f commit c3515c8
File tree
52 files changed
+1248
-297
lines changed- schemas
- src
- Cli.Tests
- Snapshots
- Cli
- Commands
- Config/ObjectModel
- Core/Services
- MetadataProviders
- OpenAPI
- Service.GraphQLBuilder/Sql
- Service.Tests
- Authorization
- Caching
- Configuration
- HotReload
- CosmosTests
- GraphQLBuilder
- Helpers
- Sql
- OpenApiDocumentor
- Snapshots
- SqlTests/GraphQLQueryTests
- UnitTests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
52 files changed
+1248
-297
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
797 | 797 | | |
798 | 798 | | |
799 | 799 | | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
800 | 815 | | |
801 | 816 | | |
802 | 817 | | |
| |||
1116 | 1131 | | |
1117 | 1132 | | |
1118 | 1133 | | |
1119 | | - | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
1120 | 1150 | | |
1121 | 1151 | | |
1122 | 1152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
85 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
86 | 94 | | |
87 | 95 | | |
88 | 96 | | |
| |||
118 | 126 | | |
119 | 127 | | |
120 | 128 | | |
121 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
122 | 134 | | |
123 | 135 | | |
124 | 136 | | |
| |||
158 | 170 | | |
159 | 171 | | |
160 | 172 | | |
161 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
162 | 178 | | |
163 | 179 | | |
164 | 180 | | |
| |||
193 | 209 | | |
194 | 210 | | |
195 | 211 | | |
196 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
197 | 217 | | |
198 | 218 | | |
199 | 219 | | |
| |||
234 | 254 | | |
235 | 255 | | |
236 | 256 | | |
237 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
238 | 262 | | |
239 | 263 | | |
240 | 264 | | |
| |||
271 | 295 | | |
272 | 296 | | |
273 | 297 | | |
274 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
275 | 303 | | |
276 | 304 | | |
277 | 305 | | |
| |||
307 | 335 | | |
308 | 336 | | |
309 | 337 | | |
310 | | - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
311 | 343 | | |
312 | 344 | | |
313 | 345 | | |
| |||
339 | 371 | | |
340 | 372 | | |
341 | 373 | | |
342 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
343 | 379 | | |
344 | 380 | | |
345 | 381 | | |
| |||
398 | 434 | | |
399 | 435 | | |
400 | 436 | | |
401 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
402 | 442 | | |
403 | 443 | | |
404 | 444 | | |
| |||
462 | 502 | | |
463 | 503 | | |
464 | 504 | | |
465 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
466 | 510 | | |
467 | 511 | | |
468 | 512 | | |
| |||
502 | 546 | | |
503 | 547 | | |
504 | 548 | | |
505 | | - | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
506 | 554 | | |
507 | 555 | | |
508 | 556 | | |
| |||
545 | 593 | | |
546 | 594 | | |
547 | 595 | | |
548 | | - | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
549 | 601 | | |
550 | 602 | | |
551 | 603 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
771 | 771 | | |
772 | 772 | | |
773 | 773 | | |
774 | | - | |
775 | | - | |
776 | | - | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
777 | 779 | | |
778 | 780 | | |
779 | 781 | | |
| |||
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 30 | + | |
35 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 30 | + | |
35 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 30 | + | |
35 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
32 | 42 | | |
33 | 43 | | |
34 | 44 | | |
| |||
Lines changed: 13 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
| |||
53 | 65 | | |
54 | 66 | | |
55 | 67 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 68 | + | |
61 | 69 | | |
62 | 70 | | |
63 | 71 | | |
| |||
Lines changed: 23 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
36 | 58 | | |
37 | 59 | | |
38 | 60 | | |
| |||
53 | 75 | | |
54 | 76 | | |
55 | 77 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 78 | + | |
63 | 79 | | |
64 | 80 | | |
65 | 81 | | |
| |||
0 commit comments