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
- func AcquireLocks(consumers []Consumer) (func(), error)
- func Check(ctx context.Context, dir string, options Options) error
- func DeclaredTargets(dir string) ([]string, error)
- func Generate(ctx context.Context, consumers []Consumer, options Options) error
- func InstalledRuntime(root, pkg string) (string, error)
- func Resolve(ctx context.Context, source Source, options Options) (*mcpcontract.Metadata, error)
- type Client
- type Consumer
- type Descriptor
- type HTTPError
- type HolonMetadata
- type Options
- type Package
- type Prepared
- func (p *Prepared) CheckConfig(consumer string) (map[string]any, bool)
- func (p *Prepared) Close() error
- func (p *Prepared) Metadata() map[string]*mcpcontract.Metadata
- func (p *Prepared) Targets(consumer string) []string
- func (p *Prepared) WriteBrowserSlot(consumer, pkgDir string) error
- func (p *Prepared) WriteGoSlot(consumer, root string) error
- func (p *Prepared) WriteNodeSlot(consumer, pkgDir string) error
- func (p *Prepared) WritePythonSlot(consumer, root string) error
- type Reference
- type Source
- type Transport
Constants ¶
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.
const MaxDescriptorBytes = 1 << 20
const PublisherMetadata = "io.modelcontextprotocol.registry/publisher-provided"
const RegistryOrigin = "https://registry.modelcontextprotocol.io"
Variables ¶
This section is empty.
Functions ¶
func AcquireLocks ¶
AcquireLocks locks each consumer directory and its installed Node slots until the returned release function is called. A failure releases every acquired lock.
func DeclaredTargets ¶
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 ¶
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 ¶
InstalledRuntime resolves a Node runtime package from root and verifies its generated-slot contract.
Types ¶
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 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 Prepared ¶
type Prepared struct {
// contains filtered or unexported fields
}
Prepared owns temporary source snapshots. Close releases them; preparation never modifies consumers.
func Prepare ¶
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 ¶
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) 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 ¶
Targets reports the prepared targets of a consumer, in the order given; none for an unknown one.
func (*Prepared) WriteBrowserSlot ¶
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 ¶
WriteGoSlot writes the consumer's holon/ Go client package under root. It replaces only an absent or Holon-marked holon/ directory.
func (*Prepared) WriteNodeSlot ¶
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 ¶
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 ¶
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.