Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2d96151
Initial plan
Copilot Feb 28, 2026
eaaa522
Changes before error encountered
Copilot Feb 28, 2026
f855e96
Add first/after pagination support to aggregate_records tool
Copilot Mar 2, 2026
3573321
Add exhaustive tool instructions and all 13 spec example tests
Copilot Mar 2, 2026
f66bf3f
Changes before error encountered
Copilot Mar 2, 2026
829a630
Changes before error encountered
Copilot Mar 2, 2026
3ccc748
Update query-timeout default to 30s, add converter support, apply tim…
Copilot Mar 2, 2026
381899d
Fix group key collision using \\0 delimiter, add #nullable enable to …
Copilot Mar 2, 2026
fde4d65
Fix nullable warnings in AggregateRecordsToolTests.cs
Copilot Mar 2, 2026
ba371d5
Add null check for errorType in AggregateRecordsToolTests
Copilot Mar 2, 2026
d340cb4
Apply validation fixes and additional tests from copilot/update-aggre…
Mar 2, 2026
41ccb2f
Refactor using directives in AggregateRecordsTool.cs to improve code …
Mar 2, 2026
eb99aba
Enhance AggregateRecordsTool to build SQL aggregate queries, improvin…
Mar 3, 2026
006f17a
Rewrite aggregate tests for SQL-level aggregation
Mar 3, 2026
d35088c
Fix negative cursor offset and add first max validation
Mar 3, 2026
ef7fd0d
Refactor AggregateRecordsTool to use engine query builder pattern
Mar 3, 2026
c5920c7
Fix SQL generation bugs in AggregateRecordsTool
Mar 3, 2026
203fde1
Add comprehensive blog scenario tests from DAB MCP blog
Mar 3, 2026
fab587f
Tighten tool description and parameter docs to remove duplication
Mar 3, 2026
5c93f92
Add early field validation and FieldNotFound error helper
Mar 3, 2026
d1268f2
Rename truncated variables to descriptive names
Mar 3, 2026
5390471
Remove hallucinated first > 100000 validation
Mar 3, 2026
b55cdde
Clean up extra blank line from validation removal
Mar 3, 2026
7f4e259
Add AggregateRecordsTool documentation for SQL-level aggregations
Mar 3, 2026
d83ded2
Simplify sequence diagram and expand design decisions
Mar 3, 2026
1327150
Merge branch 'main' into copilot/add-aggregate-records-tool
souvikghosh04 Mar 3, 2026
6815b65
Changes before error encountered
Copilot Mar 3, 2026
c7010ff
Removing duplicate registration from stdio which is failing runs
souvikghosh04 Mar 3, 2026
5038cc7
update snapshot test files
souvikghosh04 Mar 3, 2026
ecbb2fa
Merge branch 'main' into copilot/add-aggregate-records-tool
souvikghosh04 Mar 5, 2026
88968f6
Initial plan
Copilot Feb 28, 2026
b87be6f
Fixes from code reviews
souvikghosh04 Mar 5, 2026
38c773d
Snapshot files and test fixes
souvikghosh04 Mar 5, 2026
7b85658
Add AggregateRecords and query-timeout properties to Service.Tests sn…
souvikghosh04 Mar 5, 2026
46134de
Fix initial Github Copilot AI reviews
souvikghosh04 Mar 6, 2026
70fb36b
Merge branch 'main' into Usr/sogh/aggregate_records
souvikghosh04 Mar 6, 2026
e3ee238
Refactor core tool logic and tests
souvikghosh04 Mar 6, 2026
987294e
Additional self review fixes
souvikghosh04 Mar 6, 2026
d5de2b4
Format and consistency fixing
souvikghosh04 Mar 6, 2026
f951685
Merge branch 'main' into Usr/sogh/aggregate_records
Aniruddh25 Mar 8, 2026
388e231
Merge branch 'main' into Usr/sogh/aggregate_records
Aniruddh25 Mar 8, 2026
a08da11
Review comments fixes
souvikghosh04 Mar 9, 2026
d4b527c
Merge branch 'Usr/sogh/aggregate_records' of https://github.com/Azure…
souvikghosh04 Mar 9, 2026
3add20a
Revert unwanted changes
souvikghosh04 Mar 9, 2026
c5ceded
Fix failing tests
souvikghosh04 Mar 9, 2026
bf50a39
Merge branch 'main' into Usr/sogh/aggregate_records
Aniruddh25 Mar 9, 2026
8520d53
use query-timeout only for aggregate_records
souvikghosh04 Mar 10, 2026
7511146
Fix failing test MsSQL snapshot
souvikghosh04 Mar 10, 2026
9e1b735
Remove redundant test for default timeout
Aniruddh25 Mar 10, 2026
a5d2310
Merge branch 'main' into Usr/sogh/aggregate_records
Aniruddh25 Mar 10, 2026
dfe3ae8
Review comment and refactoring fixes
souvikghosh04 Mar 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions schemas/dab.draft.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,34 @@
"type": "boolean",
"description": "Enable/disable the execute-entity tool.",
"default": false
},
"aggregate-records": {
"oneOf": [
{
"type": "boolean",
"description": "Enable/disable the aggregate-records tool."
},
{
"type": "object",
"description": "Aggregate records tool configuration",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"description": "Enable/disable the aggregate-records tool.",
"default": true
},
"query-timeout": {
"type": "integer",
"description": "Execution timeout in seconds for aggregate queries. Range: 1-600.",
"default": 30,
"minimum": 1,
"maximum": 600
}
}
}
],
"default": false
}
}
}
Expand Down
1,087 changes: 1,087 additions & 0 deletions src/Azure.DataApiBuilder.Mcp/BuiltInTools/AggregateRecordsTool.cs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/Azure.DataApiBuilder.Mcp/Utils/McpErrorHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,16 @@ public static CallToolResult ToolDisabled(string toolName, ILogger? logger, stri
string message = customMessage ?? $"The {toolName} tool is disabled in the configuration.";
return McpResponseBuilder.BuildErrorResult(toolName, Model.McpErrorCode.ToolDisabled.ToString(), message, logger);
}

/// <summary>
/// Returns a model-friendly error when a field name is not found for an entity.
/// Guides the model to call describe_entities to discover valid field names.
/// </summary>
public static CallToolResult FieldNotFound(string toolName, string entityName, string fieldName, string parameterName, ILogger? logger)
{
string message = $"Field '{fieldName}' in '{parameterName}' was not found for entity '{entityName}'. "
+ $"Call describe_entities to get valid field names for '{entityName}'.";
return McpResponseBuilder.BuildErrorResult(toolName, "FieldNotFound", message, logger);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ internal static class McpTelemetryErrorCodes
/// Operation cancelled error code.
/// </summary>
public const string OPERATION_CANCELLED = "OperationCancelled";

/// <summary>
/// Operation timed out error code.
/// </summary>
public const string OPERATION_TIMEOUT = "OperationTimeout";
}
}
3 changes: 2 additions & 1 deletion src/Azure.DataApiBuilder.Mcp/Utils/McpTelemetryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static async Task<CallToolResult> ExecuteWithTelemetryAsync(
operation: operation,
dbProcedure: dbProcedure);

// Execute the tool
CallToolResult result = await tool.ExecuteAsync(arguments, serviceProvider, cancellationToken);

// Check if the tool returned an error result (tools catch exceptions internally
Expand Down Expand Up @@ -124,6 +123,7 @@ public static string InferOperationFromTool(IMcpTool tool, string toolName)
"delete_record" => "delete",
"describe_entities" => "describe",
"execute_entity" => "execute",
"aggregate_records" => "aggregate",
_ => "execute" // Fallback for any unknown built-in tools
};
}
Expand Down Expand Up @@ -188,6 +188,7 @@ public static string MapExceptionToErrorCode(Exception ex)
return ex switch
{
OperationCanceledException => McpTelemetryErrorCodes.OPERATION_CANCELLED,
TimeoutException => McpTelemetryErrorCodes.OPERATION_TIMEOUT,
DataApiBuilderException dabEx when dabEx.SubStatusCode == DataApiBuilderException.SubStatusCodes.AuthenticationChallenge
=> McpTelemetryErrorCodes.AUTHENTICATION_FAILED,
DataApiBuilderException dabEx when dabEx.SubStatusCode == DataApiBuilderException.SubStatusCodes.AuthorizationCheckFailed
Expand Down
68 changes: 68 additions & 0 deletions src/Cli.Tests/InitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,74 @@ public Task VerifyCorrectConfigGenerationWithMultipleMutationOptions(DatabaseTyp
return ExecuteVerifyTest(options, verifySettings);
}

/// <summary>
/// Test that init with/without --mcp.aggregate-records.query-timeout produces a config
/// with the correct aggregate-records query-timeout in the DmlTools section.
/// When null (not specified), defaults to 30 seconds. When provided, the config reflects the value.
/// </summary>
[DataTestMethod]
[DataRow(null, false, DmlToolsConfig.DEFAULT_QUERY_TIMEOUT_SECONDS, DisplayName = "Init without query-timeout uses default 30s")]
[DataRow(1, true, 1, DisplayName = "Init with query-timeout 1s (minimum)")]
[DataRow(120, true, 120, DisplayName = "Init with query-timeout 120s")]
[DataRow(600, true, 600, DisplayName = "Init with query-timeout 600s (maximum)")]
public void InitWithAggregateRecordsQueryTimeout_SetsOrDefaultsTimeout(int? inputTimeout, bool expectedUserProvided, int expectedEffectiveTimeout)
{
InitOptions options = new(
databaseType: DatabaseType.MSSQL,
connectionString: "testconnectionstring",
cosmosNoSqlDatabase: null,
cosmosNoSqlContainer: null,
graphQLSchemaPath: null,
setSessionContext: false,
hostMode: HostMode.Development,
corsOrigin: null,
authenticationProvider: EasyAuthType.AppService.ToString(),
mcpAggregateRecordsQueryTimeout: inputTimeout,
config: TEST_RUNTIME_CONFIG_FILE);

Assert.IsTrue(TryCreateRuntimeConfig(options, _runtimeConfigLoader!, _fileSystem!, out RuntimeConfig? runtimeConfig));
Assert.IsNotNull(runtimeConfig?.Runtime?.Mcp?.DmlTools);
Assert.AreEqual(inputTimeout, runtimeConfig.Runtime.Mcp.DmlTools.AggregateRecordsQueryTimeout);
Assert.AreEqual(expectedUserProvided, runtimeConfig.Runtime.Mcp.DmlTools.UserProvidedAggregateRecordsQueryTimeout);
Assert.AreEqual(expectedEffectiveTimeout, runtimeConfig.Runtime.Mcp.DmlTools.EffectiveAggregateRecordsQueryTimeoutSeconds);
}

/// <summary>
/// Test that init with --mcp.aggregate-records.query-timeout produces valid JSON
/// that round-trips correctly through serialization/deserialization.
/// </summary>
[TestMethod]
public void InitWithAggregateRecordsQueryTimeout_RoundTripsCorrectly()
{
InitOptions options = new(
databaseType: DatabaseType.MSSQL,
connectionString: "testconnectionstring",
cosmosNoSqlDatabase: null,
cosmosNoSqlContainer: null,
graphQLSchemaPath: null,
setSessionContext: false,
hostMode: HostMode.Development,
corsOrigin: null,
authenticationProvider: EasyAuthType.AppService.ToString(),
mcpAggregateRecordsQueryTimeout: 90,
config: TEST_RUNTIME_CONFIG_FILE);

Assert.IsTrue(TryCreateRuntimeConfig(options, _runtimeConfigLoader!, _fileSystem!, out RuntimeConfig? runtimeConfig));

// Serialize to JSON and deserialize back
JsonSerializerOptions serializerOptions = RuntimeConfigLoader.GetSerializationOptions();
string json = JsonSerializer.Serialize(runtimeConfig, serializerOptions);
RuntimeConfig? deserialized = JsonSerializer.Deserialize<RuntimeConfig>(json, serializerOptions);

Assert.IsNotNull(deserialized?.Runtime?.Mcp?.DmlTools);
Assert.AreEqual(90, deserialized.Runtime.Mcp.DmlTools.AggregateRecordsQueryTimeout);
Assert.AreEqual(90, deserialized.Runtime.Mcp.DmlTools.EffectiveAggregateRecordsQueryTimeoutSeconds);

// Verify the JSON contains the object format for aggregate-records
Assert.IsTrue(json.Contains("\"query-timeout\""), $"Expected 'query-timeout' in serialized JSON. Got: {json}");
Assert.IsTrue(json.Contains("90"), $"Expected timeout value 90 in serialized JSON. Got: {json}");
}

private Task ExecuteVerifyTest(InitOptions options, VerifySettings? settings = null)
{
Assert.IsTrue(TryCreateRuntimeConfig(options, _runtimeConfigLoader!, _fileSystem!, out RuntimeConfig? runtimeConfig));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
DataSource: {
DatabaseType: MSSQL,
Options: {
Expand Down Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
UpdateRecord: true,
DeleteRecord: true,
ExecuteEntity: true,
AggregateRecords: true,
UserProvidedAllTools: false,
UserProvidedDescribeEntities: false,
UserProvidedCreateRecord: false,
UserProvidedReadRecords: false,
UserProvidedUpdateRecord: false,
UserProvidedDeleteRecord: false,
UserProvidedExecuteEntity: false
UserProvidedExecuteEntity: false,
UserProvidedAggregateRecords: false,
UserProvidedAggregateRecordsQueryTimeout: false,
EffectiveAggregateRecordsQueryTimeoutSeconds: 30
}
},
Host: {
Expand Down
Loading
Loading