diff --git a/src/Azure.DataApiBuilder.Mcp/BuiltInTools/ReadRecordsTool.cs b/src/Azure.DataApiBuilder.Mcp/BuiltInTools/ReadRecordsTool.cs index 8da3c4856a..26a4e1451f 100644 --- a/src/Azure.DataApiBuilder.Mcp/BuiltInTools/ReadRecordsTool.cs +++ b/src/Azure.DataApiBuilder.Mcp/BuiltInTools/ReadRecordsTool.cs @@ -201,7 +201,7 @@ public async Task ExecuteAsync( if (!string.IsNullOrWhiteSpace(select)) { // Update the context to specify which fields will be returned from the entity. - IEnumerable fieldsReturnedForFind = select.Split(",").ToList(); + IEnumerable fieldsReturnedForFind = select.Split(',').Select(field => field.Trim()).ToList(); context.UpdateReturnFields(fieldsReturnedForFind); } diff --git a/src/Service.Tests/Mcp/ReadRecordsToolMsSqlIntegrationTests.cs b/src/Service.Tests/Mcp/ReadRecordsToolMsSqlIntegrationTests.cs index 26e07b359c..3d919d565e 100644 --- a/src/Service.Tests/Mcp/ReadRecordsToolMsSqlIntegrationTests.cs +++ b/src/Service.Tests/Mcp/ReadRecordsToolMsSqlIntegrationTests.cs @@ -61,6 +61,23 @@ public async Task ReadRecords_WithSelect_ReturnsSelectedFields() Assert.IsTrue(firstRecord.TryGetProperty("title", out _), "Expected 'title' field in result."); } + /// + /// Reads records with whitespace after a comma in the select clause. + /// + [TestMethod] + public async Task ReadRecords_WithWhitespaceAfterSelectComma_ReturnsSelectedFields() + { + CallToolResult result = await ExecuteReadAsync("Book", select: "id, title"); + + AssertSuccess(result, "ReadRecords with whitespace after a select comma should succeed."); + + JsonElement root = ParseResultRoot(result); + JsonElement records = GetRecordsArray(root); + JsonElement firstRecord = records[0]; + Assert.IsTrue(firstRecord.TryGetProperty("id", out _), "Expected 'id' field in result."); + Assert.IsTrue(firstRecord.TryGetProperty("title", out _), "Expected 'title' field in result."); + } + /// /// Reads records with an OData filter expression and verifies filtered results are returned. ///