Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
morisil opened this issue Jan 7, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@morisil
Copy link
Contributor

morisil commented Jan 7, 2025

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.

@morisil morisil added the enhancement New feature or request label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant