Skip to content

Align MCP create_record/update_record with shared authorization helper#3730

Open
souvikghosh04 wants to merge 5 commits into
mainfrom
mcp/dml-tool-authz-consistency
Open

Align MCP create_record/update_record with shared authorization helper#3730
souvikghosh04 wants to merge 5 commits into
mainfrom
mcp/dml-tool-authz-consistency

Conversation

@souvikghosh04

Copy link
Copy Markdown
Contributor

Summary

Minor internal consistency update for the built-in MCP DML tools (create_record, update_record).

Both tools now route through a small shared authorization helper (McpAuthorizationHelper) before invoking the mutation engine, matching the pattern already used elsewhere in the MCP tool set. No changes to public tool schemas, request/response shapes, or supported scenarios.

Changes

  • McpAuthorizationHelper: adds a small reusable helper method used by the mutation tools.
  • CreateRecordTool / UpdateRecordTool: call the helper as part of existing request handling, immediately after role resolution.
  • Test coverage: adds a dedicated test role/config entry and regression tests exercising the updated code path for both tools.

Testing

  • dotnet build — clean.
  • dotnet format --verify-no-changes — clean.
  • New/updated tests included; existing MCP test suite unaffected.

Notes

Opened as draft while final validation completes.

…r pattern

Extends McpAuthorizationHelper with a small reusable check used by the read-side MCP tools, and calls it from CreateRecordTool/UpdateRecordTool for consistency with the rest of the tool set. Adds accompanying test coverage.

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 tightens MCP DML tool authorization by adding an explicit column-level authorization check for create_record and update_record, aligning these tools with existing authorization patterns used elsewhere (and preventing fields.exclude/fields.include bypasses).

Changes:

  • Added a reusable column-level authorization helper (McpAuthorizationHelper.AreColumnsAuthorizedForOperation).
  • Updated CreateRecordTool and UpdateRecordTool to enforce column-level authorization immediately after role resolution.
  • Added a dedicated test role/config entry plus regression tests to validate excluded-column enforcement for both create and update.

Reviewed changes

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

Show a summary per file
File Description
src/Azure.DataApiBuilder.Mcp/Utils/McpAuthorizationHelper.cs Adds a shared helper to enforce column-level authorization for mutations.
src/Azure.DataApiBuilder.Mcp/BuiltInTools/CreateRecordTool.cs Enforces column-level authorization for create payload columns.
src/Azure.DataApiBuilder.Mcp/BuiltInTools/UpdateRecordTool.cs Enforces column-level authorization for update payload columns.
src/Service.Tests/Mcp/McpToolTestBase.cs Enables mutation test service providers to simulate different client roles.
src/Service.Tests/Mcp/CreateRecordToolMsSqlIntegrationTests.cs Adds regression + sanity tests for excluded-column behavior on create.
src/Service.Tests/Mcp/UpdateRecordToolMsSqlIntegrationTests.cs Adds regression + sanity tests for excluded-column behavior on update.
src/Service.Tests/dab-config.MsSql.json Adds a test role with mutation-time excluded fields for the new regression tests.

Comment thread src/Azure.DataApiBuilder.Mcp/BuiltInTools/CreateRecordTool.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
… test

The Book entity's only non-key column (publisher_id) is NOT NULL with no default, so a role excluded from writing it can never satisfy Book's required-field validation on create -- unrelated to authorization. Switched the success-path sanity check to the WebsiteUser entity, whose only non-key column (username) is nullable, so omitting the excluded column is valid.
@souvikghosh04
souvikghosh04 force-pushed the mcp/dml-tool-authz-consistency branch from c84ec2c to fb815cd Compare July 21, 2026 15:29
The MCP create_record/update_record column-exclusion integration tests passed
locally but failed in CI. CI regenerates src/Service.Tests/dab-config.MsSql.json
from config-generators/mssql-commands.txt; the role existed only in the
checked-in JSON, so the regenerated CI config lacked it and inheritance from the
'authenticated' role (no field exclusions) allowed writes to excluded columns.

Add the role to mssql-commands.txt for Book (exclude publisher_id) and
WebsiteUser (exclude username) on create/update. Add AuthorizationResolver unit
tests covering multi-action-per-role column exclusion and config parsing.
@souvikghosh04
souvikghosh04 force-pushed the mcp/dml-tool-authz-consistency branch from fb815cd to 20d95f7 Compare July 22, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

4 participants