-
Notifications
You must be signed in to change notification settings - Fork 234
Description
As I go through our API for v1.0.0, and in light of a few recent issues in google/jsonschema-go, I wonder if it would be wise to decouple the API of the SDK from the jsonschema-go library. I am loath to change anything at this point, but after experimenting with this, the impact of this breaking change on server authors would be negligible, and the impact on clients would be non-trivial but also beneficial.
Here are my concerns / arguments:
- It's always uncomfortable to put another module's types in our API, even if we maintain that module.
- jsonschema-go has gotten relatively less traction than the SDK, and is therefore less mature. For example, hash of unhashable type main.ID (struct containing slice) google/jsonschema-go#26 revealed an API oversight that would have been painful to live with if we'd cut v1.0.0 of the SDK.
- The meaning of schema fields is under-specified and evolving. For example, consider SEP-834 Support full JSON Schema
2020-12modelcontextprotocol#834. Fortunately, that issue proposes standardising on the 2020-12 schema version, which is also the default for the jsonschema-go library. But what if an alternate proposal were to be approved? - The jsonschema-go library does not support all drafts, and our tight coupling to a particular representation means that our clients can't talk to certain servers (see support http://json-schema.org/draft-07/schema# google/jsonschema-go#6), or Handle incompatible schemas (e.g. required of type []string) from older jsonschema drafts #455.
All of these suggest that going to v1.0.0 with a tight coupling to the google/jsonschema-go library may be a risk.
As an alternative, I tried two experiments, which you can see in draft PRs:
- Use a proxy package for the jsonschema API (jsonschema: experiment with a proxy package #515). This technically broke the dependency, but was horrendously ugly and didn't address concerns 2-4 above.
- Just set schema fields to
any, with the contract that they must be JSON-marshallable (mcp: allow any value for schemas #517). Internally, we need to convert these to ajsonschema.Schemain order to do validation, but that becomes an implementation detail.
After investigating, (2) looks rather attractive. It completely breaks the dependency in the API, and requires effectively no change for server code (observe that almost no tests or examples had to be updated), since custom schemas can still be set on the Tool as before. It will break clients that were inspecting the schema, but were any clients doing that? On the other hand, it means that clients will be able to talk to any server, even if we can't unmarshal its schemas to a jsonschema.Schema.
The downside of this change would be that the schema fields are less self-documenting, with less type safety.