feat: introduce CustomMcpServer class that handles JSONSchema #47
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.
🤔 What
🤷 Why
The official SDK requires us to define tools' input with Zod, which causes a few problems:
I opened a PR on the official SDK repository, but I'm not sure if or when it will be merged (it's already full of conflicts because of refactorings happening on the main branch).
So I decided to do it in user land instead!
🔍 How
I'm leveraging the lower level
Server
class to implement my ownMcpServer
. I mirrored the base implementation except I modified theinputSchema
to accept a json schema instead. Tool arguments are now validated against this schema by usingajv
.I also had to modify the base openapi specs because the way it combined
allOf
andadditionalProperties: false
resulted in the validation rejecting actually valid inputs. I had to leverageunevaluatedProperties
instead. I'll work on backporting these changes to the specs source of truth in https://github.com/algolia/api-clients-automation/tree/main/specs🧪 Testing
I added a ton of integration tests around tool arguments validation
I have a test that makes sure that non of the tools can crash the server
I also tested manually with Claude desktop that calls are still working