Help us shape the future of Go! Take the 2026 Go Developer Survey

mcpspec

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 8 Imported by: 0

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 the mcpconf package 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

View Source
const ManifestFile = "versions.json"

ManifestFile is the vendored revision manifest, relative to the schema dir.

View Source
const SchemaFile = "schema.json"

SchemaFile is the schema document within each revision directory.

Variables

View Source
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

func LoadManifest(dir string) (*Manifest, error)

LoadManifest reads the revision manifest from dir. Versions are returned sorted, which for ISO-8601 revision names is also chronological order.

func (*Manifest) Index

func (m *Manifest) Index(version string) int

Index returns the position of version in the revision list, or -1.

func (*Manifest) Newest

func (m *Manifest) Newest() string

Newest returns the most recent vendored revision.

func (*Manifest) RevisionsBehind

func (m *Manifest) RevisionsBehind(version string) int

RevisionsBehind reports how many released revisions newer than version exist. It returns -1 when version is not a known revision.

type MissingDefError

type MissingDefError struct {
	Version string
	Def     string
}

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 Load

func Load(dir, version string) (*Spec, error)

Load reads dir/<version>/schema.json.

func Parse

func Parse(version string, raw []byte) (*Spec, error)

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) DefCount

func (s *Spec) DefCount() int

DefCount returns the number of definitions in the revision.

func (*Spec) Draft

func (s *Spec) Draft() string

Draft reports the JSON Schema dialect the revision declares.

func (*Spec) FirstPresent

func (s *Spec) FirstPresent(names ...string) (string, bool)

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) Has

func (s *Spec) Has(def string) bool

Has reports whether the revision declares the named definition.

func (*Spec) ServerCapabilityKeys

func (s *Spec) ServerCapabilityKeys() []string

ServerCapabilityKeys returns the capability keys the revision defines on ServerCapabilities.

func (*Spec) ServerMethods

func (s *Spec) ServerMethods() []string

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.

func (*Spec) Validate

func (s *Spec) Validate(def string, instance any) error

Validate checks a decoded JSON instance against the named definition.

func (*Spec) ValidateJSON

func (s *Spec) ValidateJSON(def string, raw []byte) error

ValidateJSON checks raw wire JSON against the named definition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL