typegen

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: 42 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 typegen prepares portable typed MCP clients without a Holon installation.

Index

Constants

View Source
const MaxDescriptorBytes = 1 << 20
View Source
const PublisherMetadata = "io.modelcontextprotocol.registry/publisher-provided"
View Source
const RegistryOrigin = "https://registry.modelcontextprotocol.io"

Variables

This section is empty.

Functions

func AcquireLocks

func AcquireLocks(m Manifest) (func(), error)

AcquireLocks locks app source directories and installed runtime slots until the returned release function is called. A failure releases every acquired lock.

func Check

func Check(ctx context.Context, m Manifest, o Options) error

Check verifies generated contracts exclusively in temporary copies.

func Contract

func Contract(ctx context.Context, manifest Manifest, name string, options Options) (*mcpcontract.Metadata, error)

Contract retrieves one provider's contract without resolving its callers or generating clients.

func Generate

func Generate(ctx context.Context, m Manifest, options Options) error

Generate installs missing public runtimes and writes only marked generation slots.

func InstalledRuntime

func InstalledRuntime(root, pkg string) (string, error)

InstalledRuntime resolves a Node runtime package from root and verifies its generated-slot contract.

func LiveContract

func LiveContract(ctx context.Context, location string, identity mcpcontract.Identity, client *http.Client) (*mcpcontract.Metadata, error)

LiveContract initializes an MCP session and retrieves its advertised schemas. Identity must be supplied by the caller because MCP serverInfo is not a registry identity.

Types

type App

type App struct {
	Name      string          `json:"name"`
	Path      string          `json:"path,omitempty"`
	Image     string          `json:"image,omitempty"`
	Registry  *RegistrySource `json:"registry,omitempty"`
	Remote    *Remote         `json:"remote,omitempty"`
	Mount     string          `json:"mount,omitempty"`
	Port      *int            `json:"port,omitempty"`
	Access    json.RawMessage `json:"access,omitempty"`
	OAuth     json.RawMessage `json:"oauth,omitempty"`
	Headers   json.RawMessage `json:"headers,omitempty"`
	Egress    json.RawMessage `json:"egress,omitempty"`
	Run       json.RawMessage `json:"run,omitempty"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
	// contains filtered or unexported fields
}

type Client

type Client struct {
	HTTP   *http.Client
	Origin string
}

func (Client) Get

func (c Client) Get(ctx context.Context, name, version string) (*Descriptor, error)

type Descriptor

type Descriptor struct {
	Name        string                     `json:"name"`
	Version     string                     `json:"version"`
	Description string                     `json:"description"`
	Packages    []Package                  `json:"packages"`
	Remotes     []Transport                `json:"remotes"`
	Meta        map[string]json.RawMessage `json:"_meta"`
	Requires    map[string]Reference       `json:"-"`
	Types       string                     `json:"-"`
	Raw         json.RawMessage            `json:"-"`
}

func ParseDescriptor

func ParseDescriptor(data []byte) (*Descriptor, error)

func (*Descriptor) Identity

func (d *Descriptor) Identity() mcpcontract.Identity

type HTTPError

type HTTPError int

func (HTTPError) Error

func (e HTTPError) Error() string

type HolonMetadata

type HolonMetadata struct {
	Requires map[string]Reference `json:"requires"`
	Types    string               `json:"types,omitempty"`
	Egress   json.RawMessage      `json:"egress,omitempty"`
}

type Manifest

type Manifest struct {
	Apps []App `json:"apps"`
	// contains filtered or unexported fields
}

func Directories

func Directories(dirs []string) (Manifest, []string, error)

Directories builds a standalone manifest from server.json files and returns its local app names for Options.Apps. Preparation infers dependencies and filters provider-only directories.

func LoadManifest

func LoadManifest(arg string) (Manifest, error)

LoadManifest resolves app paths relative to the manifest, never the process working directory.

func ParseManifest

func ParseManifest(data []byte, source string) (Manifest, error)

ParseManifest validates the source declarations while preserving host-specific fields.

type Options

type Options struct {
	Apps           []string
	Env            []string
	HTTPClient     *http.Client
	Stdout, Stderr io.Writer
	NoInstall      bool
	NoPublished    bool
	// Credential authenticates OCI registry requests ahead of the Docker credential store. A registry
	// that rejects a credential it returned (HTTP 401) fails resolution instead of leaving clients untyped.
	Credential auth.CredentialFunc
	// Extract runs one language's extractor: the runner under toolingDir/<language> reads configPath and
	// writes outputPath. It defaults to the host's Node.js or Python interpreter.
	Extract func(ctx context.Context, language, toolingDir, configPath, outputPath string) error
	// GoModule is the runtime module that generated Go clients import. When set, apps with a server.go
	// entrypoint receive a holon/ Go client package for their dependencies; their own contracts are not extracted.
	GoModule string
}

type Package

type Package struct {
	RegistryType string    `json:"registryType"`
	Identifier   string    `json:"identifier"`
	Transport    Transport `json:"transport"`
}

type Prepared

type Prepared struct {
	Manifest Manifest
	// contains filtered or unexported fields
}

Prepared owns temporary source snapshots. Close releases them; preparation never modifies apps.

func Prepare

func Prepare(ctx context.Context, manifest Manifest, options Options) (*Prepared, error)

Prepare snapshots local sources, resolves required contracts and generates portable client files.

func (*Prepared) CheckConfig

func (p *Prepared) CheckConfig(app string) (map[string]any, bool)

CheckConfig is the runner's check configuration ({entry, sources, check}) for app's own language, for a type check inside an image build against the dependencies installed there. Paths are relative to the app directory. It reports false for apps without a runner (Go, unanalysed or unselected apps).

func (*Prepared) CheckPublished

func (p *Prepared) CheckPublished(ctx context.Context) error

CheckPublished reports selected apps whose extracted contracts break their published contracts or the expectations that other published apps hold of them.

func (*Prepared) Close

func (p *Prepared) Close() error

func (*Prepared) Languages

func (p *Prepared) Languages(app string) []string

Languages reports the generated client languages for a selected app, in stable order. It returns no languages for an unknown or unprepared app.

func (*Prepared) Metadata

func (p *Prepared) Metadata() map[string]*mcpcontract.Metadata

Metadata returns contracts by manifest app name: extracted ones for path apps, and the resolved image, registry or remote contracts of the dependencies that selected apps require.

func (*Prepared) Published

func (p *Prepared) Published(ctx context.Context) (map[string]*mcpcontract.Metadata, error)

Published returns the contracts that each selected path app's descriptor last published (sh.holon.types or its OCI package), using Options.Credential; an app without one maps to nil.

func (*Prepared) TypeCheck

func (p *Prepared) TypeCheck(ctx context.Context) error

TypeCheck type-checks each selected app's snapshot against its freshly generated clients, linked beside the app's installed dependencies. Apps and installed slots are never modified. Go callers are not checked.

func (*Prepared) WriteBrowserSlot

func (p *Prepared) WriteBrowserSlot(app, pkgDir string) error

WriteBrowserSlot writes app's browser clients into pkgDir/generated, where pkgDir is an installed holon-ui package or a copy staged for an image. Same refusals as WriteNodeSlot.

func (*Prepared) WriteGoSlot

func (p *Prepared) WriteGoSlot(app, root string) error

WriteGoSlot writes app's holon/ Go client package under root. It requires Options.GoModule and replaces only an absent or Holon-marked holon/ directory.

func (*Prepared) WriteNodeSlot

func (p *Prepared) WriteNodeSlot(app, pkgDir string) error

WriteNodeSlot writes app's TypeScript clients and their holon-generated.json marker into pkgDir/generated, where pkgDir is an installed holon-sh package or a copy staged for an image. It refuses slots that are unmarked, symlinked or owned by another app, and leaves an identical slot untouched.

func (*Prepared) WritePythonSlot

func (p *Prepared) WritePythonSlot(app, root string) error

WritePythonSlot writes app's holon/apps/__init__.py under root, an application directory or its staged copy. A legacy Holon-managed holon/ package is replaced; user files in the namespace are refused.

type Reference

type Reference struct {
	Name     string `json:"name"`
	Version  string `json:"version"`
	Registry string `json:"registry,omitempty"`
}

func (Reference) Identity

func (r Reference) Identity() mcpcontract.Identity

func (Reference) RegistryURL

func (r Reference) RegistryURL() string

func (Reference) Validate

func (r Reference) Validate() error

type RegistrySource

type RegistrySource struct {
	Reference
	Package json.RawMessage `json:"package,omitempty"`
	Remote  json.RawMessage `json:"remote,omitempty"`
}

type Remote

type Remote struct {
	URL string `json:"url"`
}

type Transport

type Transport struct {
	Type string `json:"type"`
	URL  string `json:"url"`
}

Jump to

Keyboard shortcuts

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