Skip to content

Data classes exposed in public APIs might cause down-compatibility issues #34

Open
@morisil

Description

@morisil

Is your feature request related to a problem? Please describe.
The official Kotlin guidelines discourage use of data classes in public APIs:

https://kotlinlang.org/docs/api-guidelines-backward-compatibility.html#avoid-using-data-classes-in-your-api

This project is using data classes to express all the types of MCP protocol. This might cause all the down-compatibility issues described in linked document, if the MCP protocol evolves.

Describe the solution you'd like
A possible way to overcome this issues is to stop using data classes in favor of classes with private constructors, and allow to create them only with builders. If the MCP protocol is extended, the new class properties can be put in any order in the private constructor, to follow the protocol evolution. Example of such an approach here:

https://github.com/xemantic/xemantic-ai-tool-schema/blob/main/src/commonMain/kotlin/JsonSchema.kt

(e.g. ObjectSchema class). The tests are here:

https://github.com/xemantic/xemantic-ai-tool-schema/blob/main/src/commonTest/kotlin/JsonSchemaTest.kt

If this is considered a way to go, I would be happy to prepare this PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions