Skip to content

Fix Kotlin nullable fields in MCP tool input schema#5997

Closed
qixiangme wants to merge 1 commit into
spring-projects:mainfrom
qixiangme:fix/mcp-kotlin-nullable-schema-5978
Closed

Fix Kotlin nullable fields in MCP tool input schema#5997
qixiangme wants to merge 1 commit into
spring-projects:mainfrom
qixiangme:fix/mcp-kotlin-nullable-schema-5978

Conversation

@qixiangme
Copy link
Copy Markdown
Contributor

@qixiangme qixiangme commented May 11, 2026

Summary

This PR is related to #5978 and fixes the MCP Tools schema generation path for Kotlin nullable fields.

PR #5897 addresses the standard @Tool schema path by registering org.springframework.ai.model.KotlinModule in JsonSchemaGenerator. MCP tools use McpJsonSchemaGenerator for method input schemas, so Kotlin nullable properties inside MCP tool parameter data classes could still be emitted as required in nested JSON Schema objects.

This change applies the same conditional KotlinModule registration pattern to McpJsonSchemaGenerator, keeping the fix narrowly scoped to MCP tool input schema generation.

Tests

The regression test verifies both sides of Kotlin requiredness behavior:

  • nullable Kotlin constructor properties with default null values, such as String? = null and List<String>? = null, are not included in nested required arrays
  • non-null Kotlin constructor properties without defaults remain required

Commands run:

./mvnw -pl mcp/mcp-annotations '-Denforcer.skip=true' 'kotlin:test-compile@test-compile'
./mvnw -pl mcp/mcp-annotations -Dtest=McpJsonSchemaGeneratorKotlinTests '-Denforcer.skip=true' surefire:test
./mvnw -pl mcp/mcp-annotations -Dtest=McpJsonSchemaGeneratorKotlinTests '-Denforcer.skip=true' package

Related issue: Addresses the MCP Tools portion of #5978.

Signed-off-by: LEE CHANGMIN <erang903@khu.ac.kr>
@sdeleuze sdeleuze self-assigned this May 11, 2026
@qixiangme qixiangme force-pushed the fix/mcp-kotlin-nullable-schema-5978 branch 2 times, most recently from 8aca08d to e36c77a Compare May 11, 2026 09:50
@sdeleuze
Copy link
Copy Markdown
Contributor

sdeleuze commented May 11, 2026

FYI The error is caused by a javac behavior described in openjdk/jdk#28018, I will refine to fix it.

@sdeleuze sdeleuze added this to the 2.0.0-RC1 milestone May 11, 2026
@sdeleuze sdeleuze added the bug Something isn't working label May 11, 2026
@qixiangme
Copy link
Copy Markdown
Contributor Author

Thanks for the clarification. I'll keep an eye on the updated fix.

sdeleuze pushed a commit to sdeleuze/spring-ai that referenced this pull request May 11, 2026
See spring-projects#5997
Signed-off-by: LEE CHANGMIN <erang903@khu.ac.kr>
@sdeleuze sdeleuze closed this in 29103b6 May 11, 2026
@sdeleuze sdeleuze changed the title GH-5978: Fix Kotlin nullable fields in MCP tool input schema Fix Kotlin nullable fields in MCP tool input schema May 20, 2026
R3gardless pushed a commit to R3gardless/spring-ai that referenced this pull request May 21, 2026
See spring-projects#5997
Signed-off-by: LEE CHANGMIN <erang903@khu.ac.kr>
Signed-off-by: R3gardless <pidaoh@g.skku.edu>
R3gardless pushed a commit to R3gardless/spring-ai that referenced this pull request May 21, 2026
Closes spring-projects#5997
Signed-off-by: Sébastien Deleuze <sdeleuze@users.noreply.github.com>
Signed-off-by: R3gardless <pidaoh@g.skku.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working kotlin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants