mcptype

package
v0.0.1-dev.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcptype compares MCP typed contracts and generates typed client packages. It is a Go port of the mcptype compiler (hughhan1/mcptype 0.0.6) and produces the same bytes: canonical forms, digests, change texts and package files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(ctx context.Context, request GenerateRequest) (map[string][]byte, error)

Generate returns the package files by relative path.

Types

type CanonicalForm

type CanonicalForm struct {
	Canonical json.RawMessage `json:"canonical"`
	Digest    string          `json:"digest"`
}

CanonicalForm is a document with annotations removed and unordered keywords sorted. Both fields are empty for metadata without a contract.

func Canonical

func Canonical(ctx context.Context, document any) (CanonicalForm, error)

Canonical validates document, one of {"contract"}, {"schema"} or {"metadata"}, and returns its canonical form and digest.

type Change

type Change struct {
	Kind string
	Name string
	Text string
}

Change is one way a published contract breaks an expectation. Name is the tool name or resource URI, if any.

func Changes

func Changes(ctx context.Context, expected mcpcontract.Expectation, published *mcpcontract.Metadata) ([]Change, error)

Changes lists what breaks expected if published is deployed. Empty means compatible.

type Contract

type Contract struct {
	Tools     map[string]Tool
	Resources map[string]Resource
}

Contract holds tools keyed by name and resources keyed by URI. The wire format is v1's arrays, written in key order.

type Expectation

type Expectation struct {
	Identity Identity
	Contract Contract
}

Expectation is the contract a caller was built against.

type GenerateRequest

type GenerateRequest struct {
	Target                  string                           `json:"target"`
	Identity                mcpcontract.Identity             `json:"identity"`
	Requires                map[string]mcpcontract.Identity  `json:"requires,omitempty"`
	Contracts               map[string]*mcpcontract.Contract `json:"contracts,omitempty"`
	Runtime                 map[string][]byte                `json:"runtime,omitempty"`
	Protocol                string                           `json:"protocol,omitempty"`
	PackageFields           map[string]any                   `json:"package_fields,omitempty"`
	RuntimeSpecifier        string                           `json:"runtime_specifier,omitempty"`
	BrowserRuntimeSpecifier string                           `json:"browser_runtime_specifier,omitempty"`
	ProtocolSpecifier       string                           `json:"protocol_specifier,omitempty"`
	PythonModule            string                           `json:"python_module,omitempty"`
	PythonRuntimeModule     string                           `json:"python_runtime_module,omitempty"`
	Banner                  string                           `json:"banner,omitempty"`
	GoModule                string                           `json:"go_module,omitempty"`
	// Entry names the TypeScript entry point files: "index" gives index.js, index.d.ts and resources.d.ts.
	// Empty means index for node and browser for browser.
	Entry string `json:"entry,omitempty"`
	// Own, for browser targets, is the contracts key of the app's own server. The module then exports
	// App: the ext-apps App with that server's tools and resources typed, called through the host.
	Own string `json:"own,omitempty"`
}

GenerateRequest asks for one target's typed client package: node, browser, python or go. Runtime files are copied into the package verbatim.

type Identity

type Identity struct {
	Name, Version string
}

Identity names a published app.

type Metadata

type Metadata struct {
	Version  uint32
	Identity Identity
	Contract *Contract
	Requires map[string]Expectation
}

Metadata is the document an image publishes.

type Number

type Number struct {
	// contains filtered or unexported fields
}

Number keeps serde_json's three representations apart: 1 and 1.0 are different values.

func (Number) String

func (n Number) String() string

String formats the number as serde_json writes it: integers in decimal, floats in ryu's shortest form.

type Object

type Object map[string]Value

Object is a JSON object.

type Resource

type Resource struct {
	Output Object
}

Resource is one resource's contents schema.

type Tool

type Tool struct {
	Input  Object
	Output Object
}

Tool is one tool's schemas. Output is nil when the tool declares no outputSchema.

type Value

type Value = any

Value is a JSON value with serde_json's semantics: nil, bool, Number, string, []Value or Object. Objects are unordered and written with sorted keys, as serde_json's default map does.

Jump to

Keyboard shortcuts

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