mcpgen

package
v0.22.152 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mcpgen — language-agnostic files every scaffolded project gets. .clawtool/mcp.toml is the discovery marker `mcp list` walks for; .claude-plugin/ is the optional manifest from ADR-019.

Package mcpgen — Go adapter (ADR-007: wraps mark3labs/mcp-go).

Package mcpgen implements the `clawtool mcp new` generator (ADR-019). Per ADR-007 each language adapter wraps the canonical SDK in that ecosystem (mcp-go for Go, fastmcp for Python, @modelcontextprotocol/sdk for TypeScript). We never re-implement MCP wire protocol — the templates emit ~50 LoC of glue around each SDK's documented "register a tool" call.

Lifecycle:

  • Spec: the operator's choices captured by the wizard (language, transport, packaging, tool list).
  • Plan: a list of Files the language adapter wants written.
  • Apply: write the files atomically + emit the .clawtool/mcp.toml marker.

Adding a fourth language is one new adapter — every language's surface goes through the Adapter interface so the wizard / install path don't grow per-language switches.

Package mcpgen — Python adapter (ADR-007: wraps fastmcp).

Package mcpgen — TypeScript adapter (ADR-007: wraps @modelcontextprotocol/sdk).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(outputDir string, spec Spec) (string, error)

Generate plans + writes a fresh project rooted at outputDir (which becomes outputDir/spec.Name). Refuses to overwrite an existing directory — operators delete first or pick a new name.

func Languages

func Languages() []string

Languages returns the registered language names, sorted. Used by the wizard's huh.Select to enumerate options.

func Register

func Register(a Adapter)

Register adds an adapter to the registry. Panics on duplicate language to surface programmer error at boot.

Types

type Adapter

type Adapter interface {
	Language() string
	Plan(spec Spec) ([]File, error)
}

Adapter is the per-language template. Each adapter renders a Spec into a Plan; the orchestrator (Generate) writes them.

type File

type File struct {
	Path string
	Body string
	Mode os.FileMode
}

File is a single artifact the adapter wants written. Mode 0o755 for executable scripts, 0o644 for everything else.

type Spec

type Spec struct {
	Name        string // kebab-case project name (also dir name)
	Description string // server self-description string
	Language    string // "go" | "python" | "typescript"
	Transport   string // "stdio" | "streamable-http"
	Packaging   string // "native" | "docker"
	Tools       []ToolSpec
	Plugin      bool // generate .claude-plugin/ alongside source
}

Spec is the wizard's output: everything the language adapter needs to render a project. Tests construct this directly to drive Generate without running huh.

type ToolSpec

type ToolSpec struct {
	Name        string // snake_case
	Description string
	Schema      string // JSON object string (e.g. `{"type":"object","properties":{...}}`)
}

ToolSpec describes one MCP tool the generated server registers. Schema is stored as a raw JSON Schema object so adapters can emit it verbatim into their language's idiomatic shape.

Jump to

Keyboard shortcuts

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