Skip to content

Emit required array in tool schema based on @Nullable#148

Open
christophercolumbusdog wants to merge 2 commits intohelidon-io:mainfrom
christophercolumbusdog:tool-required-params
Open

Emit required array in tool schema based on @Nullable#148
christophercolumbusdog wants to merge 2 commits intohelidon-io:mainfrom
christophercolumbusdog:tool-required-params

Conversation

@christophercolumbusdog
Copy link
Contributor

@christophercolumbusdog christophercolumbusdog commented Feb 24, 2026

Summary

  • Tool annotation processor now checks @Nullable on parameters (both element and TYPE_USE annotations) and emits a "required" array in the generated JSON schema for non-nullable parameters
  • MCP clients can now distinguish mandatory from optional tool inputs

Fixes #146

Changes

  • McpCodegenUtil — add isNullable helper that checks both annotations() and elementTypeAnnotations() for any annotation named Nullable
  • McpJsonSchemaCodegen — add overload of addSchemaMethodBody that accepts required field names and emits "required": [...] between the properties close and root object close
  • McpToolCodegen — collect non-nullable parameter names during schema generation and pass them through

Example

Given:

@Mcp.Tool("Abandon a change")
public List<McpToolContent> abandonChange(
        @Mcp.Description("Change ID") String changeId,
        @Mcp.Description("Reason") @Nullable String message) { ... }

Before:

{"type": "object", "properties": {"changeId": {...}, "message": {...}}}

After:

{"type": "object", "properties": {"changeId": {...}, "message": {...}}, "required": ["changeId"]}

@oracle-contributor-agreement
Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Feb 24, 2026
The tool annotation processor now checks parameter annotations
and type-use annotations for @nullable. Parameters without it
are collected into a JSON Schema "required" array, letting MCP
clients distinguish mandatory from optional tool inputs.

Fixes helidon-io#146
@oracle-contributor-agreement
Copy link

Thank you for signing the OCA.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Verified All contributors have signed the Oracle Contributor Agreement. and removed OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. labels Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool codegen should emit required array based on @Nullable

1 participant