Enhanced server.json validation (phase 1) #636
+1,992
−135
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.
Added schema validation and support for exhaustive and more detailed validation to existing validators. Added new
mcp-publisher validate
command. No change to any existing tests or behavior other than the new command.Motivation and Context
Many currently published servers fail schema validation. Of those that pass, many have semantic/logical errors or other errors that make them impossible to configure, or their configuration when applied doesn't generate correct MCP server configuration (per their own documentation).
To address this, we need better tooling to validate servers and to inform server publishers of errors, issues, and best practices in a way that is clear and actionable, both during server development and at time of publishing.
I have started a discussion about the broader topic: #635
There is also a fairly detailed document describing the design, architecture, implementation, future plans, etc. See Enhanced Validation Design
This PR is the first step in the process of improving validation. It adds schema validation and updates all existing validators to use a new model that allows them to track context and return rich and exhaustive results. This has been done in a way that is backward compatible (ValidateServerJSON is unchanged as are all existing validation unit tests).
There is a new
mcp-publisher
command calledvalidate
that is currenty the only place that schema validation and enhanced (exhaustive/rich) validation results are exposed.Changes
Internal Validation improvements
A new
validate
command has been added tomcp-publisher
so publishers can evaluate their server.json before publishingUsage
Given a server.json that looks like this:
Run the command:
mcp-publisher validate server.json
Which will produce the output:
Note in the results above:
Reference
provided contains an absolute path to the schema rule that was violated, followed by the full schema path that enforced that rule (with $ref redirect values substited and enclosed in square brackets).In the final solution we would remove semantic validators that are redundant to schema validation (as in number 5 above). We have the option to use the structured data produced by schema validation to replace the generic schema validation message with a more descriptive message if that is an issue (in particular, if the only argument for an ad-hoc validator is that is produces a better/cleaner message, we would just move that message creation code to the schema error result formatter and special case it as opposed to having a redundant validator).
What's Next
If this general direction is supported and this PR is accepted, a fast follow would include:
Issues
Schema validation requires embedding the
server.schema.json
file into the validators package viago:embed
, which is restricted from embedding files outside of the package. For this reason we copy the schema file into a schema subdir (via a prep target in the makefile) and we .gitignore it. I tried cleaning up the copy in the make clean target, but then the linter would complain about the embed target being missing if it wasn't there during development. I also considered just checking in the schema file and assuming a separate workflow for updating the embedded schema file, but it's not clear what that workflow would be or how it would be maintained. I'm open to a different approach, but the schema file does need to be embedded somehow for schema validation to work.How Has This Been Tested?
All existing validation tests pass, new tests implemented and all pass.
Breaking Changes
No breaking changes, no behavior change except new
validate
commandTypes of changes
Checklist