Documentation
¶
Overview ¶
Package mcpspec loads the vendored Model Context Protocol JSON Schemas and validates wire JSON against them.
The authority on conformance is the official suite at github.com/modelcontextprotocol/conformance, run against the server from the compliance workflow; see internal/mcpconf for the reporting side.
Two jobs remain here:
- a fast, offline, pass/fail validation of the served surface against the newest vendored revision, so `go test` still catches a broken tool schema on a machine with no Node installed (see winmcp's capture test); and
- the revision manifest, which the compliance workflow uses to notice that upstream has published a revision newer than the one we run against.
Lookups are driven by what a revision's schema actually defines rather than by hardcoded definition names, because the protocol restructures between revisions: 2026-07-28, for example, removes InitializeRequest/InitializeResult entirely in favour of server/discover. FirstPresent exists for exactly that, so a caller can name the equivalent definitions and let the revision decide.
The package is platform-agnostic (no build tag), so it is testable in isolation.
Index ¶
- Constants
- Variables
- type Manifest
- type MissingDefError
- type Spec
- func (s *Spec) DefCount() int
- func (s *Spec) Draft() string
- func (s *Spec) FirstPresent(names ...string) (string, bool)
- func (s *Spec) Has(def string) bool
- func (s *Spec) ServerCapabilityKeys() []string
- func (s *Spec) ServerMethods() []string
- func (s *Spec) Validate(def string, instance any) error
- func (s *Spec) ValidateJSON(def string, raw []byte) error
Constants ¶
const ManifestFile = "versions.json"
ManifestFile is the vendored revision manifest, relative to the schema dir.
const SchemaFile = "schema.json"
SchemaFile is the schema document within each revision directory.
Variables ¶
var ErrNoDefinitions = errors.New("schema has neither $defs nor definitions")
ErrNoDefinitions is returned for a schema document with neither $defs nor definitions — i.e. not a recognizable MCP schema.
Functions ¶
This section is empty.
Types ¶
type Manifest ¶
type Manifest struct {
Source string `json:"source"`
Note string `json:"note"`
Versions []string `json:"versions"`
}
Manifest is the vendored revision list.
func LoadManifest ¶
LoadManifest reads the revision manifest from dir. Versions are returned sorted, which for ISO-8601 revision names is also chronological order.
func (*Manifest) RevisionsBehind ¶
RevisionsBehind reports how many released revisions newer than version exist. It returns -1 when version is not a known revision.
type MissingDefError ¶
MissingDefError reports a definition the loaded revision does not declare. Callers treat this as "check not applicable to this revision", not a failure.
func (*MissingDefError) Error ¶
func (e *MissingDefError) Error() string
type Spec ¶
type Spec struct {
Version string
// contains filtered or unexported fields
}
Spec is one loaded MCP schema revision, ready to validate instances against.
func Parse ¶
Parse builds a Spec from a raw schema document. Both the draft-07 / "definitions" and the 2020-12 / "$defs" layouts used across MCP revisions are accepted.
func (*Spec) FirstPresent ¶
FirstPresent returns the first of names the revision declares, and whether any matched. It lets a check name the equivalent definitions across revisions (e.g. InitializeResult, then DiscoverResult) instead of hardcoding one.
func (*Spec) ServerCapabilityKeys ¶
ServerCapabilityKeys returns the capability keys the revision defines on ServerCapabilities.
func (*Spec) ServerMethods ¶
ServerMethods returns the JSON-RPC methods the revision expects a *server* to implement. It is derived from the ClientRequest union — the requests a client sends — so it stays correct as revisions add and remove methods, and it excludes client-implemented methods such as sampling/createMessage.