Skip to content

Fix whitespace handling in MCP read_records select lists - #3786

Open
aaronburtle wants to merge 1 commit into
mainfrom
dev/aaronburtle/fix-mcp-read-comma-whitespace-bug
Open

Fix whitespace handling in MCP read_records select lists#3786
aaronburtle wants to merge 1 commit into
mainfrom
dev/aaronburtle/fix-mcp-read-comma-whitespace-bug

Conversation

@aaronburtle

Copy link
Copy Markdown
Contributor

Why make this change?

Closes #3771

What is this change?

  • Trim whitespace from each field after splitting the comma-separated select value.
  • Add a regression integration test covering a space after the comma.

How was this tested?

  • Integration Tests
    • Added ReadRecords_WithWhitespaceAfterSelectComma_ReturnsSelectedFields.
  • Unit Tests
    • All 309 non-database MCP tests passed.
    • The service test project builds successfully.

Sample Request(s)

Example MCP read_records arguments:

{
  "entity": "Book",
  "select": "id, title"
}

The request now succeeds and returns the selected id and title fields.

CLI, REST, and GraphQL samples are not applicable because this change affects the MCP read_records tool only.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes MCP read_records parsing of the select argument by tolerating whitespace around comma-separated field names, aligning the tool’s behavior with its “Comma-separated field names” contract and preventing false “invalid field” errors.

Changes:

  • Trim whitespace around each field name after splitting the comma-separated select value in ReadRecordsTool.
  • Add an MsSql MCP integration test that exercises select: "id, title" (space after comma).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Azure.DataApiBuilder.Mcp/BuiltInTools/ReadRecordsTool.cs Trims split select entries before updating return fields for request validation/execution.
src/Service.Tests/Mcp/ReadRecordsToolMsSqlIntegrationTests.cs Adds a regression integration test ensuring whitespace after the select comma succeeds.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

{
// Update the context to specify which fields will be returned from the entity.
IEnumerable<string> fieldsReturnedForFind = select.Split(",").ToList();
IEnumerable<string> fieldsReturnedForFind = select.Split(',').Select(field => field.Trim()).ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working mcp-server

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP read_records tool's "select" parameter fails on comma-separated field lists with a space after the comma (missing .Trim())

4 participants