typegen

package
v0.0.1-dev.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 41 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 turns explicit MCP server sources into typed client slots.

A Consumer is a project directory that receives clients for the servers it names as Sources. Nothing is discovered: every dependency, where its schema comes from, and which SDK slot receives it is stated by the caller, and whatever cannot be resolved from that is an error.

Index

Constants

View Source
const (
	TargetTS = "ts" // node_modules/holon-sh/generated, resolved upward from the consumer
	TargetUI = "ui" // node_modules/holon-ui/generated; the consumer's own server becomes App
	TargetPy = "py" // holon/apps/__init__.py in the consumer
	TargetGo = "go" // holon/ Go package in the consumer; needs Options.GoModule
)

Targets name the SDK slot a consumer receives clients in.

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(consumers []Consumer) (func(), error)

AcquireLocks locks each consumer directory and its installed Node slots until the returned release function is called. A failure releases every acquired lock.

func Check

func Check(ctx context.Context, dir string, options Options) error

func DeclaredTargets

func DeclaredTargets(dir string) ([]string, error)

DeclaredTargets are the slots a project declares: ts when package.json depends on holon-sh, ui when it depends on holon-ui, py when pyproject.toml or requirements declare holon-sh. None is an error.

func Generate

func Generate(ctx context.Context, consumers []Consumer, options Options) error

Generate writes each consumer's slots: it requires the slot packages to be installed (installing a declared but missing one), prepares, validates the slots, then writes them.

func InstalledRuntime

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

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

func Resolve

func Resolve(ctx context.Context, source Source, options Options) (*mcpcontract.Metadata, error)

Resolve returns one source's contract document without writing anything: a path source is extracted from its snapshot, the others are fetched as Prepare would fetch them.

Types

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 Consumer

type Consumer struct {
	// Name owns the written slots (holon-generated.json, the Python banner) and labels output.
	Name string
	// Dir is the absolute project directory.
	Dir string
	// Server is the consumer's own MCP server, a path source inside Dir. Required for the ui
	// target, where it becomes the App class; otherwise it only supplies the consumer's identity,
	// contract (Metadata) and check configuration.
	Server *Source
	// Targets are the slots to write, from TargetTS, TargetUI, TargetPy and TargetGo.
	Targets []string
	// Sources are the servers that become apps.<alias> clients.
	Sources []Source
}

Consumer is a project directory that receives typed clients.

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 Options

type Options struct {
	Env            []string
	HTTPClient     *http.Client
	Stdout, Stderr io.Writer
	// Credential authenticates OCI registry requests ahead of the Docker credential store.
	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; the go target requires it.
	GoModule string
}

type Package

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

type Prepared

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

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

func Prepare

func Prepare(ctx context.Context, consumers []Consumer, options Options) (_ *Prepared, err error)

Prepare snapshots and extracts every path source once, resolves every other source once, and generates the client files for each consumer and target. Nothing is written to the consumers.

func (*Prepared) CheckConfig

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

CheckConfig is the runner's check configuration ({entry, sources, check}) for the consumer's own server, for a type check inside an image build against the dependencies installed there. Paths are relative to the consumer directory. It reports false for consumers without an extracted server.

func (*Prepared) Close

func (p *Prepared) Close() error

func (*Prepared) Metadata

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

Metadata returns each consumer's own contract document (identity, extracted contract and the expectations it holds of its sources) by consumer name, plus every resolved source by alias.

func (*Prepared) Targets

func (p *Prepared) Targets(consumer string) []string

Targets reports the prepared targets of a consumer, in the order given; none for an unknown one.

func (*Prepared) WriteBrowserSlot

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

WriteBrowserSlot writes the consumer's ui 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(consumer, root string) error

WriteGoSlot writes the consumer's holon/ Go client package under root. It replaces only an absent or Holon-marked holon/ directory.

func (*Prepared) WriteNodeSlot

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

WriteNodeSlot writes the consumer's ts 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 consumer, and leaves an identical slot untouched.

func (*Prepared) WritePythonSlot

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

WritePythonSlot writes the consumer's holon/apps/__init__.py under root, a project 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 Source

type Source struct {
	// Alias names the client (apps.<alias>). Empty derives it: the last segment of the server's
	// name (example.com/orders → orders), or the live server's serverInfo name for an Endpoint.
	Alias string
	// Path is a server entry file (server.py, server.ts, server.js, or the same under src/) or a
	// directory containing exactly one. Its contract is extracted from source; server.json beside
	// the entry supplies the identity.
	Path string
	// Registry is an MCP registry server version. The record's sh.holon.types document is the
	// contract; without one, its streamable-http remote is asked; without either it is an error.
	Registry *Reference
	// Endpoint is a live MCP endpoint; initialize and tools/list supply identity and contract.
	Endpoint string
	// Image is an OCI image carrying a contract artifact (Options.Credential authenticates).
	Image string
}

Source is one MCP server whose contract becomes a client. Exactly one of Path, Registry, Endpoint or Image is set.

func (Source) String

func (s Source) String() string

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