[MCP] Fix for inconsistent MCP enabled check#3303
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes inconsistent MCP enablement behavior so the /mcp endpoint is registered by default when the runtime.mcp block is omitted, aligning runtime behavior with mcp.enabled defaulting to true in config/model layers (closes #3284).
Changes:
- Default MCP options resolution now falls back to
new McpRuntimeOptions()whenruntime.mcpis absent, enabling endpoint registration by default. - REST routing guard now throws
GlobalMcpEndpointDisabledonly when MCP is actually disabled. - Added unit tests covering MCP enabled/disabled routing guard behavior and config defaulting of
IsMcpEnabled/McpPath.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Azure.DataApiBuilder.Mcp/Core/McpEndpointRouteBuilderExtensions.cs | Ensures MCP endpoints are mapped by default when runtime.mcp is omitted. |
| src/Core/Services/RestService.cs | Gates the MCP-disabled 404 guard behind IsMcpEnabled. |
| src/Service.Tests/UnitTests/RestServiceUnitTests.cs | Adds unit tests for MCP path guard behavior in GetRouteAfterPathBase. |
| src/Service.Tests/Configuration/McpRuntimeOptionsSerializationTests.cs | Adds tests verifying IsMcpEnabled/McpPath defaults when runtime/mcp blocks are omitted. |
|
|
aaronburtle
left a comment
There was a problem hiding this comment.
Looks good, just needs the same fix in Cli.ConfigGenerator
…a-api-builder into Usr/sogh/mcpenabledfix
Added a fix. |
RubenCerna2079
left a comment
There was a problem hiding this comment.
LGTM! Just needs a few comments to be addressed.
Cherry-picks MCP bug fixes from main to release/2.0: - f6dd0df [MCP] Bug-fix- aggregate_records always requires groupby (#3294) - 2811fba [MCP] Fix for inconsistent MCP enabled check (#3303) --------- Co-authored-by: Aniruddh Munde <anmunde@microsoft.com> Co-authored-by: RubenCerna2079 <32799214+RubenCerna2079@users.noreply.github.com>
Why make this change?
mcp.enableddefaults are not working #3284MCP endpoint returns 404 when the mcp config block is omitted, despite mcp.enabled defaulting to true across schema, CLI, and model layers.
What is this change?
McpEndpointRouteBuilderExtensions.TryGetMcpOptions: Falls back to newMcpRuntimeOptions()whenRuntime.Mcpisnull, so the/mcpendpoint is registered by default.RestService.GetRouteAfterPathBase: Guards theGlobalMcpEndpointDisabledexception with anIsMcpEnabledcheck so MCP path requests are not unconditionally rejected.How was this tested?
Sample Request(s)
/mcp
/health