Skip to content

Expose required array in custom MCP tool input schema#3688

Open
souvikghosh04 with Copilot wants to merge 7 commits into
mainfrom
copilot/fix-custom-tool-input-schema
Open

Expose required array in custom MCP tool input schema#3688
souvikghosh04 with Copilot wants to merge 7 commits into
mainfrom
copilot/fix-custom-tool-input-schema

Conversation

Copilot AI commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Why make this change?

  • Closes [Bug]: Custom tool inputSchema has empty properties #3399
  • Custom MCP tools (DynamicCustomTool) build an inputSchema with typed properties from stored procedure metadata, but never emitted a JSON Schema required array. AI agents had no way to tell which parameters are mandatory and had to fall back to description text or describe_entities.

What is this change?

  • DynamicCustomTool.BuildInputSchemaFromDbMetadata: collects parameter names while iterating SP parameters and adds a top-level required array when non-empty.
  • DynamicCustomTool.BuildInputSchemaFromConfig (fallback path): same treatment for config-declared parameters.
  • IsParameterRequired(bool? configuredRequired, bool hasDefault) helper centralizes the rule: a parameter is required unless config explicitly marks it optional (required: false) or supplies a default the engine applies when the caller omits it. Consistent with the execution-time default-application logic and describe_entities semantics.

Resulting schema:

"inputSchema": {
  "type": "object",
  "properties": { "productId": { "type": "integer" } },
  "required": [ "productId" ]
}

How was this tested?

  • Integration Tests
  • Unit Tests

DynamicCustomToolTests: required params listed, params with defaults / required:false excluded, zero-param SP omits the array, config-fallback path. DynamicCustomToolMsSqlIntegrationTests: validates required against live DB metadata (GetBook.id required; InsertBook defaulted params excluded; zero-param GetBooks omits the array).

Sample Request(s)

MCP tools/list response for a custom tool over get_book_by_id(@id int):

{
  "name": "get_book",
  "description": "Executes the get_book stored procedure",
  "inputSchema": {
    "type": "object",
    "properties": { "id": { "type": "integer", "description": "Parameter id" } },
    "required": [ "id" ]
  }
}

Copilot AI changed the title [WIP] Fix empty properties in custom tool inputSchema Expose required array in custom MCP tool input schema Jun 26, 2026
Copilot AI requested a review from souvikghosh04 June 26, 2026 08:31
@souvikghosh04 souvikghosh04 marked this pull request as ready for review July 7, 2026 10:25
Copilot AI review requested due to automatic review settings July 7, 2026 10:25

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 pull request enhances MCP custom tool discoverability by emitting a JSON Schema required array in DynamicCustomTool input schemas, allowing agents/clients to distinguish mandatory parameters from optional/defaulted ones.

Changes:

  • Add top-level required array emission to the DB-metadata schema path (BuildInputSchema) when at least one parameter is required.
  • Add the same required array emission to the config-fallback schema path (BuildInputSchemaFromConfig).
  • Add unit and MSSQL integration tests to validate required/optional/defaulted parameter behavior and the zero-parameter omission case.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Azure.DataApiBuilder.Mcp/Core/DynamicCustomTool.cs Builds MCP tool inputSchema.required based on parameter requirement/default rules for both DB and config-fallback paths.
src/Service.Tests/Mcp/DynamicCustomToolTests.cs Adds unit tests asserting required array inclusion/exclusion and omission for zero-parameter procedures, including config-fallback validation.
src/Service.Tests/Mcp/DynamicCustomToolMsSqlIntegrationTests.cs Adds MSSQL integration coverage validating required against live stored procedure metadata and config defaults.

Comment thread src/Azure.DataApiBuilder.Mcp/Core/DynamicCustomTool.cs
Comment thread src/Service.Tests/Mcp/DynamicCustomToolTests.cs

properties[paramName] = paramSchema;

// A parameter is required unless config marks it optional or supplies a default

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here, this call to IsParameterRequired is not for config. the comment conveys config. Should be fixed to mention db metadata

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.

@copilot please apply the suggesstion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied in 64cd204.

/// When falling back to config-based schema, parameters without a default are required.
/// </summary>
[TestMethod]
public void GetToolMetadata_ConfigFallback_MarksParamsWithoutDefaultsRequired()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There should be a test for config defining defaults and also having the parameter specified as required. In this case, the parameter should still be present in the required array.

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.

@copilot check if this is covered already or add this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added explicit config-fallback coverage in 0c38640. The new test verifies that a parameter with Required = true and a config default is excluded from inputSchema.required, matching the current default-application behavior.

@Aniruddh25 Aniruddh25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Needs 1 more test for combination of required and default

souvikghosh04 and others added 2 commits July 9, 2026 16:01
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

[Bug]: Custom tool inputSchema has empty properties

5 participants