DynamicCustomTool: Align tool input schema with DB metadata at runtime#3619
Merged
Conversation
The stdio code path in McpStdioHelper.RunMcpStdioHost registers tools directly without going through McpToolRegistryInitializer, so custom tools were missing the DB-metadata-based schema enrichment.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates MCP DynamicCustomTool registration so the tool input JSON Schema reflects stored procedure parameter metadata discovered from the database at runtime (with a config-based permissive fallback), improving client-side validation and parameter discoverability.
Changes:
- Added post-DI initialization (
InitializeMetadata) to build/cache a DB-metadata-based input schema forDynamicCustomTool. - Initialized metadata before tool registration in both HTTP-hosted (
McpToolRegistryInitializer) and stdio (McpStdioHelper) MCP modes. - Added unit tests covering schema alignment behaviors (typed mapping, fallback behavior, defaults in descriptions, zero-parameter SP).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Azure.DataApiBuilder.Mcp/Core/DynamicCustomTool.cs | Adds DB-metadata-based schema building and caching, plus type mapping and default-in-description support. |
| src/Azure.DataApiBuilder.Mcp/Core/McpToolRegistryInitializer.cs | Ensures custom tools initialize DB-backed schema before being registered (HTTP mode). |
| src/Service/Utilities/McpStdioHelper.cs | Ensures custom tools initialize DB-backed schema before being registered (stdio mode). |
| src/Service.Tests/Mcp/DynamicCustomToolTests.cs | Adds unit tests validating DB-metadata schema enrichment and fallback behaviors. |
aaronburtle
reviewed
May 21, 2026
aaronburtle
reviewed
May 21, 2026
- Use ParameterDefinition.Description with fallback to generic text - Add ArgumentNullException guard to InitializeMetadata - Remove unnecessary JsonDocument allocation in test helper - Extract InitializeAndRegisterTools into McpToolRegistry (shared by McpToolRegistryInitializer and McpStdioHelper)
…com/Azure/data-api-builder into Usr/sogh/cust-tool-schema-alignment
Aniruddh25
reviewed
May 21, 2026
Aniruddh25
approved these changes
May 21, 2026
aaronburtle
approved these changes
May 21, 2026
Contributor
aaronburtle
left a comment
There was a problem hiding this comment.
Looks good, thanks for fixing everything!
This was referenced May 22, 2026
souvikghosh04
added a commit
that referenced
this pull request
May 22, 2026
#3601, #3619) (#3630) Cherry-pick of commits from main to release/2.0: - 5d6faf9 ExecuteEntityTool: DB metadata based parameter support (#3600) - a085d86 DynamicCustomTool: DB metadata based parameter support (#3601) - b84d8d6 DynamicCustomTool: Align tool input schema with DB metadata at runtime (#3619) --------- Co-authored-by: Anusha Kolan <anushakolan10@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why make this change?
Custom MCP tools used a permissive multi-type array for all parameters in the input schema. MCP clients had no type information to guide users or validate inputs before execution.
What is this change?
McpToolRegistry.InitializeAndRegisterToolshelper.(default: value)in parameter descriptions when HasConfigDefault is set.How was this tested?
Sample Request(s)
tools/list response (get_book schema after fix):
{ "name": "get_book", "inputSchema": { "type": "object", "properties": { "id": { "type": "integer", "description": "Parameter id" } } } }