Skip to content

Cherry pick PR to allow create_record tool for views and supporting tests.#3251

Open
anushakolan wants to merge 2 commits intorelease/1.7from
dev/backport-mcp-entity-level-config
Open

Cherry pick PR to allow create_record tool for views and supporting tests.#3251
anushakolan wants to merge 2 commits intorelease/1.7from
dev/backport-mcp-entity-level-config

Conversation

@anushakolan
Copy link
Contributor

@anushakolan anushakolan commented Mar 13, 2026

Why make this change?

This backport fixes MCP behavior where create_record incorrectly rejected view-backed entities with the error that the tool is only available for tables.

Views are a required workaround for unsupported SQL data types in some scenarios (e.g., vector columns), so this fix restores expected INSERT behavior for those entities.

What is this change?

Cherry-picked PR:

  1. fix(mcp): allow create_record for views and add tests to verify behavior fix(mcp): allow create_record for views and added tests to verify the same. #3196

How was this tested?

  1. Existing and newly added tests in the source PR.
  2. Manual verification of create_record against view-backed entities.

Sample Request(s)

N/A

@anushakolan anushakolan marked this pull request as ready for review March 13, 2026 19:45
Copilot AI review requested due to automatic review settings March 13, 2026 19:45
@anushakolan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Backports MCP entity-level configuration support into release/1.7, adds CLI/schema support for the new entities.<name>.mcp settings, and fixes MCP DML tooling behavior so create_record supports view-backed entities (plus associated tests).

Changes:

  • Add entity-level MCP config model + JSON (de)serialization support and expose it through CLI add/update flags.
  • Enforce entity-level enablement checks in MCP tools (DML + custom tools), and allow create_record for view entities.
  • Add/extend unit tests and JSON schema updates covering entity-level MCP config and tool behavior.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Service.Tests/ModuleInitializer.cs Updates snapshot verification settings to ignore new MCP user-provided flags.
src/Service.Tests/Mcp/EntityLevelDmlToolConfigurationTests.cs Adds MCP tool execution tests for entity-level enablement and view/table support.
src/Service.Tests/Configuration/EntityMcpConfigurationTests.cs Adds config deserialization/validation tests for entity-level mcp formats.
src/Config/RuntimeConfigLoader.cs Registers the new entity-level MCP converter for config JSON parsing/serialization.
src/Config/ObjectModel/EntityMcpOptions.cs Introduces the entity-level MCP options model and user-provided flags.
src/Config/ObjectModel/Entity.cs Adds Entity.Mcp to the object model and wires converter usage.
src/Config/Converters/EntityMcpOptionsConverterFactory.cs Implements boolean/object JSON forms for entities.<name>.mcp.
src/Cli/Utils.cs Adds CLI parsing/validation helper for MCP entity options.
src/Cli/ConfigGenerator.cs Plumbs MCP options through dab add/dab update entity generation.
src/Cli/Commands/UpdateOptions.cs Adds MCP CLI parameters to update options plumbing.
src/Cli/Commands/EntityOptions.cs Adds --mcp.dml-tools and --mcp.custom-tool options.
src/Cli/Commands/AddOptions.cs Adds MCP CLI parameters to add options plumbing.
src/Cli.Tests/UpdateEntityTests.cs Adds CLI update tests covering MCP entity option behavior/validation.
src/Cli.Tests/ModuleInitializer.cs Updates snapshot verification settings to ignore new MCP user-provided flags.
src/Cli.Tests/AddEntityTests.cs Adds CLI add tests covering MCP entity option behavior/validation.
src/Azure.DataApiBuilder.Mcp/Utils/McpErrorHelpers.cs Extends ToolDisabled helper to optionally use a custom message.
src/Azure.DataApiBuilder.Mcp/Core/DynamicCustomTool.cs Adds runtime entity-level enablement validation for custom tools (hot-reload scenario).
src/Azure.DataApiBuilder.Mcp/BuiltInTools/UpdateRecordTool.cs Adds entity-level DML enablement checks + validates table/view targets.
src/Azure.DataApiBuilder.Mcp/BuiltInTools/ReadRecordsTool.cs Adds entity-level DML enablement checks + validates table/view targets.
src/Azure.DataApiBuilder.Mcp/BuiltInTools/ExecuteEntityTool.cs Adds entity-level DML enablement check and hardens null entity map handling.
src/Azure.DataApiBuilder.Mcp/BuiltInTools/DeleteRecordTool.cs Adds entity-level DML enablement checks.
src/Azure.DataApiBuilder.Mcp/BuiltInTools/CreateRecordTool.cs Allows view targets (skips table-only validation) + adds entity-level DML checks.
schemas/dab.draft.schema.json Documents/defines entity-level mcp schema and adds stored-proc constraint for custom tools.

Comment on lines +1175 to +1186
"if": {
"properties": {
"mcp": {
"properties": {
"custom-tool": {
"const": true
}
}
}
},
"required": ["mcp"]
},
Comment on lines +88 to +121
public override void Write(Utf8JsonWriter writer, EntityMcpOptions value, JsonSerializerOptions options)
{
if (value == null)
{
return;
}

// Check if we should write as boolean shorthand
// Write as boolean if: only dml-tools is set (or custom-tool is default false)
bool writeAsBoolean = !value.UserProvidedCustomToolEnabled && value.UserProvidedDmlToolsEnabled;

if (writeAsBoolean)
{
// Write as boolean shorthand
writer.WriteBooleanValue(value.DmlToolEnabled);
}
else if (value.UserProvidedCustomToolEnabled || value.UserProvidedDmlToolsEnabled)
{
// Write as object
writer.WriteStartObject();

if (value.UserProvidedCustomToolEnabled)
{
writer.WriteBoolean("custom-tool", value.CustomToolEnabled);
}

if (value.UserProvidedDmlToolsEnabled)
{
writer.WriteBoolean("dml-tools", value.DmlToolEnabled);
}

writer.WriteEndObject();
}
}
Comment on lines +1670 to +1671
// Keep existing MCP options if no updates provided
updatedMcpOptions = entity.Mcp;
// Assert
Assert.IsTrue(result.IsError == true, "Expected error when entity has DmlToolEnabled=false");

JsonElement content = await RunToolAsync(tool, arguments, serviceProvider);
CancellationToken cancellationToken = default)
{
ILogger<DynamicCustomTool>? logger = serviceProvider.GetService<ILogger<DynamicCustomTool>>();
string toolName = GetToolMetadata().Name;
@Aniruddh25
Copy link
Collaborator

PR title should be accurate.

@anushakolan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@anushakolan anushakolan enabled auto-merge (squash) March 18, 2026 18:10
@anushakolan anushakolan changed the title Dev/backport mcp entity level config Cherry pick entity-level MCP configuration support, entity-level tool enabled check and allow create_record tool for views. Mar 18, 2026
anushakolan and others added 2 commits March 18, 2026 13:53
… same. (#3196)

Closes #3194 - MCP `create_record` tool incorrectly blocks views with
error `"The create_record tool is only available for tables."`
1. Views are the required workaround for unsupported SQL data types
(e.g., vector columns). Users could create views that omit unsupported
columns and perform DML operations against those views.
2. This bug prevents INSERT operations via MCP on view entities,
breaking a critical workflow for vector database scenarios.

1. Modified `CreateRecordTool.cs` to allow both tables and views to pass
source type validation
2. Changed `else` block (which caught views) to`else if
(EntitySourceType.StoredProcedure)` so only stored procedures are
blocked
3. Views now fall through to the mutation engine, which already supports
INSERT on updateable views
4. Updated error message to `"The create_record tool is only available
for tables and views."`
5. Added 8 unit tests validating all DML tools (CreateRecord,
ReadRecords, UpdateRecord, DeleteRecord) work with both Table and View
source types

- [ ] Integration Tests
- [X] Unit Tests
1. `DmlTool_AllowsTablesAndViews` - 8 DataRow test cases verifying no
`InvalidCreateTarget` error for views
2. Existing REST integration tests `InsertOneInViewTest` already
validate view INSERT via same mutation engine

Manually tested via MCP Inspector, to verify `create_record` calls
succeeds on a view.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
(cherry picked from commit e5bf26f)
@anushakolan anushakolan force-pushed the dev/backport-mcp-entity-level-config branch from 9edb825 to e08ced3 Compare March 18, 2026 20:59
@anushakolan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

@anushakolan anushakolan changed the title Cherry pick entity-level MCP configuration support, entity-level tool enabled check and allow create_record tool for views. Cherry pick PR to allow create_record tool for views and supporting tests. Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants