feat: migrate tool schemas to kotlinx.schema - #917
Open
Stream29 wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
@devcrocod @kpavlov This PR contains API breaking change. But I think it's reasonable. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the SDK’s tool schema representation from the SDK-specific ToolSchema DTO to kotlinx.schema.json.ObjectPropertyDefinition, aligning tool input/output schemas with a structured, serializable JSON Schema model used across MCP tool APIs.
Changes:
- Replaced
ToolSchemawithObjectPropertyDefinitionacross core/server APIs, tests, samples, and conformance tooling. - Updated tool schema construction to use
kotlinx.schema.jsonproperty definitions (e.g.,StringPropertyDefinition,NumericPropertyDefinition,$defsviadefs). - Added the
kotlinx-schema-jsondependency and updated public API dumps accordingly.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| samples/weather-stdio-server/src/main/kotlin/io/modelcontextprotocol/sample/server/McpWeatherServer.kt | Updates sample tool schemas to kotlinx.schema.json definitions. |
| samples/simple-streamable-server/src/main/kotlin/io/modelcontextprotocol/sample/server/server.kt | Migrates sample server tool input schema to ObjectPropertyDefinition. |
| samples/kotlinlang-mcp-server/src/main/kotlin/org/kotlinlang/mcp/KotlinlangServer.kt | Migrates Kotlinlang sample tool schemas to ObjectPropertyDefinition. |
| README.md | Updates public documentation example to use ObjectPropertyDefinition/StringPropertyDefinition. |
| kotlin-sdk-server/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransportTest.kt | Adjusts server transport tests for new schema type. |
| kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/Server.kt | Updates Server.addTool overload signature defaults to ObjectPropertyDefinition. |
| kotlin-sdk-server/api/kotlin-sdk-server.api | Reflects server public API change from ToolSchema to ObjectPropertyDefinition. |
| kotlin-sdk-core/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/types/ToolsTest.kt | Updates serialization/deserialization tests to validate kotlinx.schema.json schemas (including $defs). |
| kotlin-sdk-core/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/types/SamplingTest.kt | Updates sampling-related tool fixtures to new schema types. |
| kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types/tools.kt | Replaces ToolSchema model with ObjectPropertyDefinition in the public Tool type and KDoc. |
| kotlin-sdk-core/build.gradle.kts | Adds kotlinx-schema-json as an API dependency for core public types. |
| kotlin-sdk-core/api/kotlin-sdk-core.api | Reflects core public API change (removal of ToolSchema, Tool signature updates). |
| kotlin-sdk-client/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientSamplingValidationTest.kt | Updates client validation test fixtures to ObjectPropertyDefinition. |
| integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerToolsTest.kt | Migrates integration tests to ObjectPropertyDefinition when registering tools. |
| integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerToolsNotificationTest.kt | Updates notification integration tests for new schema type. |
| integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerBulkFeaturesTest.kt | Updates bulk tool registration integration tests for new schema type. |
| integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/SamplingTest.kt | Migrates sampling integration tests to ObjectPropertyDefinition/property definitions. |
| integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/http/KotlinServerForTsClientHttp.kt | Updates Kotlin server used by TS client tests to new schema construction. |
| integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/streamablehttp/StreamableHttpClientTransportIntegrationTest.kt | Migrates streamable-http integration tool schemas to kotlinx.schema.json. |
| integration-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/kotlin/AbstractToolIntegrationTest.kt | Migrates comprehensive tool-schema integration coverage to property-definition builders. |
| integration-test/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/ClientTest.kt | Updates client integration tests to use ObjectPropertyDefinition. |
| gradle/libs.versions.toml | Adds kotlinx-schema version and kotlinx-schema-json library entry. |
| conformance-test/src/main/kotlin/io/modelcontextprotocol/kotlin/sdk/conformance/ConformanceTools.kt | Updates conformance tool schemas to kotlinx.schema.json equivalents. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
Some CIs are failing because the API breaking change. It's expected. |
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.
Summary
Replace the SDK-specific
ToolSchemamodel withkotlinx.schema.json.ObjectPropertyDefinition.Fixes #300
Motivation and Context
The old
ToolSchemamodels only a small subset of JSON Schema and requires callers to construct nestedJsonObjectvalues manually. Usingkotlinx.schemaprovides a structured, serializable JSON Schema model that can be shared directly by MCP tool APIs.How Has This Been Tested?
npm ciinintegration-test/src/jvmTest/typescriptwith Node.js 22../gradlew build --max-workers 3 --continue --rerun-tasks --no-configuration-cacheon Linux (665 tasks)../gradlew knit docs:classes docs:knitCheck --max-workers 3 --continue --rerun-tasks --no-configuration-cacheon Linux (29 tasks)../gradlew iosSimulatorArm64Test --max-workers 2 --continue --rerun-tasks --no-configuration-cacheon macOS (49 tasks).Breaking Changes
Tool.inputSchemaandTool.outputSchemanow useObjectPropertyDefinition, and the SDK-specificToolSchematype is removed. Callers constructingToolSchemavalues must migrate to the correspondingkotlinx.schema.jsonproperty definitions.Types of changes
Checklist
Additional context
This removes the duplicate partial schema DTO from the SDK and delegates JSON Schema modeling and serialization to
kotlinx.schema.