Documentation
¶
Overview ¶
Package typegen turns MCP server sources into typed client slots.
A Consumer is a project directory that receives clients for the servers it names as Sources. Sources can be supplied explicitly or read from sh.holon.requires with DeclaredSources. The caller chooses which SDK slots receive them; unresolved sources are errors.
Index ¶
- Constants
- Variables
- 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 GeneratedSource(root, path string) bool
- func IgnoredSource(root, path string, matcher *patternmatcher.PatternMatcher) (bool, error)
- func Install(ctx context.Context, consumers []Consumer, options Options) error
- func InstalledRuntime(root, pkg string) (string, error)
- func ParseDescriptor(data []byte) (*descriptor, error)
- func SnapshotSource(name, dir, destination string) (string, error)
- func SourceEntry(root string) (string, error)
- func SourceMatcher(root string) (*patternmatcher.PatternMatcher, error)
- type Client
- type Consumer
- type Document
- func FetchDocument(ctx context.Context, blobs registry.BlobStore, reference string) (*Document, error)
- func NewDocument(ctx context.Context, metadata *mcpcontract.Metadata) (*Document, error)
- func ParseDocument(ctx context.Context, data []byte) (*Document, error)
- func ReadDocument(ctx context.Context, repository *remote.Repository, ...) (*Document, error)
- func ResolveDocument(ctx context.Context, source Source, options Options) (*Document, error)
- type Options
- type Prepared
- func (p *Prepared) CheckConfig(consumer string) (map[string]any, bool)
- func (p *Prepared) Close() error
- func (p *Prepared) Documents() map[string]*Document
- func (p *Prepared) Metadata() map[string]*mcpcontract.Metadata
- func (p *Prepared) Servers() map[string]Server
- func (p *Prepared) Targets(consumer string) []string
- func (p *Prepared) Write() error
- 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 RunnerError
- type Server
- type Source
Constants ¶
const ( TargetTS = "ts" // node_modules/holon-sh/generated, resolved upward from the consumer TargetUI = "ui" 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 ContractFile = "holon-contract.json"
ContractFile is a server's committed contract document, beside its server.json: what holon types generate --contract prints for it. It stands in for running the server when a package the server imports is not installed.
const RegistryOrigin = "https://registry.modelcontextprotocol.io"
Variables ¶
var ErrNoRuntime = errors.New("declares no runtime: depend on holon-sh or holon-ui in package.json, on holon-sh in pyproject.toml, or on github.com/holon-sh/sdk-go in go.mod")
ErrNoRuntime identifies a project without a declared Holon SDK runtime.
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's SDK dependencies declare. None is an error.
func Generate ¶
Generate installs declared runtimes, prepares clients, and writes the project slots.
func GeneratedSource ¶
GeneratedSource reports dependency directories and marked client slots excluded from source snapshots.
func IgnoredSource ¶
func IgnoredSource(root, path string, matcher *patternmatcher.PatternMatcher) (bool, error)
IgnoredSource applies the snapshot exclusions to path, including generated slots and dependency directories. The root and .dockerignore remain observable so watchers can refresh their rules.
func Install ¶
Install installs missing declared SDK runtimes with the project's package manager. Call it before snapshotting sources: package installation can create or update lockfiles.
func InstalledRuntime ¶
InstalledRuntime resolves pkg from root and verifies its generated-slot contract.
func ParseDescriptor ¶
func SnapshotSource ¶
SnapshotSource copies dir into destination (or only fingerprints it when destination is empty), honouring .dockerignore and skipping generated and dependency directories.
func SourceEntry ¶
SourceEntry returns the one server entry relative to root, or "" when there is none. More than one entry is an error.
func SourceMatcher ¶
func SourceMatcher(root string) (*patternmatcher.PatternMatcher, error)
SourceMatcher reads the project's .dockerignore rules, or returns an empty matcher when absent.
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. It supplies the
// consumer's identity, contract (Metadata) and check configuration. Browser clients call it
// under its derived name; an Alias replaces that name and adds the client to every other slot.
Server *Source
// Targets are the slots to write.
// A server can have no targets when only its contract is needed.
Targets []string
// Sources are the servers that become apps.<alias> clients.
Sources []Source
}
Consumer is a project directory that receives typed clients.
func AppConsumer ¶
AppConsumer is the consumer for the app kept in dir, without its dependencies: the slots its SDK dependencies declare and its OwnServer. It returns nil for an app with neither, which has nothing to generate or check.
type Document ¶
type Document struct {
*mcpcontract.Metadata
Data []byte
Digest string
}
Document retains the bytes a registry digest names. Copy Data when publishing; marshaling Metadata again would give a different digest for some valid documents.
func FetchDocument ¶
func FetchDocument(ctx context.Context, blobs registry.BlobStore, reference string) (*Document, error)
FetchDocument reads a blob by digest, bounds its size and verifies its bytes. The same reader serves an image's own document and its pinned dependencies.
func NewDocument ¶
NewDocument serializes a newly observed contract. Schema numbers retain their precision.
func ParseDocument ¶
ParseDocument validates a document and retains its exact bytes.
func ReadDocument ¶
func ReadDocument(ctx context.Context, repository *remote.Repository, descriptor ocispec.Descriptor) (*Document, error)
ReadDocument reads an image index's contract annotation, then the named blob. The contract manifest remains in the index for copying and garbage collection; it is not part of the read path.
func ResolveDocument ¶
ResolveDocument returns one source's contract document without writing anything: a path source is extracted by running its server, a registry or endpoint source is fetched, and a supplied document is validated and returned with its bytes.
type Options ¶
type Options struct {
Env []string
HTTPClient *http.Client
Stdout, Stderr io.Writer
// Run runs one server through its language's contract runner, toolingDir/<language>/runner.mjs or
// extract.py, with args (contract ROOT ENTRY), copying the runner's stdout to stdout. A failure the
// runner reports is a *RunnerError. It defaults to the host's Node.js or Python interpreter, which
// runs the server in its own directory and stops it after 30 seconds.
Run func(ctx context.Context, language, toolingDir string, args []string, stdout io.Writer) error
// GoModule is the runtime module that generated Go clients import; it defaults to github.com/holon-sh/sdk-go.
GoModule string
}
type Prepared ¶
type Prepared struct {
// contains filtered or unexported fields
}
Prepared owns a temporary directory for tooling and documents. Close releases it; preparation never modifies consumers.
func Prepare ¶
Prepare fingerprints 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) Documents ¶
Documents returns the own and dependency documents by digest, preserving fetched bytes.
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) Servers ¶
Servers returns how each consumer's own server describes itself, by consumer name.
func (*Prepared) Targets ¶
Targets reports the prepared targets of a consumer, in the order given; none for an unknown one.
func (*Prepared) Write ¶
Write validates all consumer slots before writing any of them. Callers hold AcquireLocks and install dependencies before Prepare. Repeating Write repairs slots replaced by an install.
func (*Prepared) WriteBrowserSlot ¶
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. Only a marked generated module is replaced.
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 RunnerError ¶
RunnerError is a contract runner's failure: the status it exited with and what it wrote to stderr. Status 2 is a diagnostic; status 3 means the server stopped on an uninstalled package, named on the last line.
func (*RunnerError) Error ¶
func (e *RunnerError) Error() string
type Server ¶
type Server struct {
Name string `json:"name"`
Version string `json:"version"`
Title string `json:"title"`
Description string `json:"description"`
WebsiteURL string `json:"websiteUrl"`
Repository struct {
URL string `json:"url"`
} `json:"repository"`
}
Server is how a server describes itself, in its server.json or the serverInfo it answers.
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.
Path string
// Registry is an MCP registry server version. Resolve its OCI package's document,
// falling back to its streamable-http remote when the image has no contract.
Registry *Reference
// Endpoint is a live MCP endpoint; initialize and tools/list supply identity and contract. With an
// Alias, the environment variable <ALIAS>_MCP_TOKEN supplies a bearer token for its origin.
Endpoint string
// Document is an already resolved contract document, with the exact bytes its digest names.
Document *Document
}
Source is one MCP server whose contract becomes a client, supplied explicitly or declared in sh.holon.requires. Exactly one of Path, Registry, Endpoint or Document is set.
func DeclaredSources ¶
DeclaredSources returns one registry source per sh.holon.requires entry, sorted by alias.
func OwnServer ¶
OwnServer finds the MCP server a project keeps in dir or dir/server, as the directory holding its entry, or returns nil when there is none. Only an entry that mentions MCP counts, since a project can keep a plain web server under the same file name. More than one is an error.
func ParseSource ¶
ParseSource reads one [ALIAS=]PATH or URL argument. Paths are resolved against the working directory.