Skip to content

feat: migrate tool schemas to kotlinx.schema - #917

Open
Stream29 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Stream29:feat/kotlinx-schema
Open

feat: migrate tool schemas to kotlinx.schema#917
Stream29 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Stream29:feat/kotlinx-schema

Conversation

@Stream29

Copy link
Copy Markdown
Contributor

Summary

Replace the SDK-specific ToolSchema model with kotlinx.schema.json.ObjectPropertyDefinition.

Fixes #300

Motivation and Context

The old ToolSchema models only a small subset of JSON Schema and requires callers to construct nested JsonObject values manually. Using kotlinx.schema provides a structured, serializable JSON Schema model that can be shared directly by MCP tool APIs.

How Has This Been Tested?

  • npm ci in integration-test/src/jvmTest/typescript with Node.js 22.
  • ./gradlew build --max-workers 3 --continue --rerun-tasks --no-configuration-cache on Linux (665 tasks).
  • ./gradlew knit docs:classes docs:knitCheck --max-workers 3 --continue --rerun-tasks --no-configuration-cache on Linux (29 tasks).
  • ./gradlew iosSimulatorArm64Test --max-workers 2 --continue --rerun-tasks --no-configuration-cache on macOS (49 tasks).
  • MCP conformance v0.1.16 server, client, and auth workflows (275 checks passed, 0 failed).

Breaking Changes

Tool.inputSchema and Tool.outputSchema now use ObjectPropertyDefinition, and the SDK-specific ToolSchema type is removed. Callers constructing ToolSchema values must migrate to the corresponding kotlinx.schema.json property definitions.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

This removes the duplicate partial schema DTO from the SDK and delegates JSON Schema modeling and serialization to kotlinx.schema.

Copilot AI review requested due to automatic review settings July 27, 2026 07:39
@Stream29

Stream29 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@devcrocod @kpavlov This PR contains API breaking change. But I think it's reasonable.

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 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 ToolSchema with ObjectPropertyDefinition across core/server APIs, tests, samples, and conformance tooling.
  • Updated tool schema construction to use kotlinx.schema.json property definitions (e.g., StringPropertyDefinition, NumericPropertyDefinition, $defs via defs).
  • Added the kotlinx-schema-json dependency 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.

@Stream29

Copy link
Copy Markdown
Contributor Author

Some CIs are failing because the API breaking change. It's expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support a strongly typed InputSchema

2 participants