Skip to main content
Glama

mcpgen

CI Go Reference License: MIT

mcpgen is a CLI that generates, extends, and verifies MCP (Model Context Protocol) servers in Go. Generated projects build on the official go-sdk v1.8.0 and target MCP spec 2026-07-28.

Full documentation: stdout.alesr.me/mcpgen.

Why mcpgen

  1. Safe regeneration. Every generated file is mcpgen-owned or user-owned, tracked with a sha256 in .mcpgen/manifest.json. Regeneration never overwrites your code.

  2. Built-in verification. mcpgen check runs config validation, tidy, fmt, vet, build, go test -race, and the official MCP conformance suite. Exit 0 means green.

  3. Agent-friendly. Every command emits one JSON envelope (--json) with stable exit codes and fix hints, so agents loop new → check → fix until exit 0. mcpgen can also run as an MCP server, so an AI client can drive it without shell access.

Related MCP server: MCP Tool Factory

Install

Requires Go 1.27+. Node.js/npx are optional (conformance suite only).

go install github.com/alesr/mcpgen@latest

Release binaries for Linux, macOS, and Windows are on the Releases page (tags vX.Y.Z, built by goreleaser).

Quickstart (60 seconds)

# 1. Generate an HTTP MCP server (runs the check pipeline after writing)
mcpgen new ./weather --name weather --module example.com/weather --transport http --json

# 2. Verify until green (exit 0 = every stage passed)
mcpgen check ./weather --json

# 3. Run it (loopback by default) and probe it
cd weather && go run ./cmd/weather &
curl -s http://127.0.0.1:8080/healthz        # -> ok

# 4. Extend at any time; your files are never touched
mcpgen add tool tools/health.json --dir ./weather --json
mcpgen check ./weather --json

Real check output (trimmed):

[passed] config — mcpgen.json valid (version 1, 1 tools, 1 prompts, 1 resources)
[passed] serverjson — server.json valid (MCP Registry descriptor)
[passed] tidy — go mod tidy
[passed] fmt — gofmt clean
[passed] vet — go vet clean
[passed] build — go build ok
[passed] test — go test -race ok
[passed] conformance — conformance passed against http://127.0.0.1:61255/mcp: 8/30 checks passed; ...

mcpgen with no arguments runs an interactive flow. mcpgen schema prints the full machine-readable contract (commands, flags, exit codes, envelope, mcpgen.json JSON Schema), the self-discovery entry point for agents. The same walkthrough, step by step: Quickstart.

Use it from an AI agent

mcpgen mcp runs mcpgen itself as a stdio MCP server. An MCP client (Claude Desktop, Cursor, or any MCP host) can then generate, extend, and verify MCP servers for you. Add it to your client:

{ "mcpServers": { "mcpgen": { "command": "mcpgen", "args": ["mcp"] } } }

The client gets four tools: mcpgen_new, mcpgen_add, mcpgen_check, mcpgen_schema. They use the same code path as the CLI. The model discovers the contract itself, calls mcpgen_new, implements the stubs, and loops mcpgen_check until green. Tool specs are passed as objects, not files. Writing the handler files needs a filesystem tool or shell on the host. See drive mcpgen from agents.

What you get

A fresh mcpgen new ./weather --name weather --module example.com/weather produces (verified against a real generation):

weather/
├── cmd/weather/main.go                  entrypoint (stdio, or HTTP server with -addr)
├── internal/mcpapp/
│   ├── mcpapp.go                        server wiring (stateless HTTP, protocol versions)
│   ├── tools.go / prompts.go / resources.go   registration + // mcpgen:begin/end markers
│   ├── tools/handlers/greet.go (+_test.go)   user-owned: your implementation
│   ├── prompts/welcome.go (+_test.go)        user-owned
│   └── resources/readme.go (+_test.go)       user-owned
├── mcpgen.json                          single source of truth (version 1)
├── .mcpgen/manifest.json                owner + sha256 per file
├── server.json, Dockerfile, Makefile, .github/workflows/ci.yml, go.mod (pins go-sdk v1.8.0)

Tool handlers are typed (mcp.AddTool[In, Out]): <Tool>Input/<Tool>Output structs are derived from the tool's JSON Schema, and the SDK validates arguments before your handler runs.

Features

  • Commands: new, add tool|prompt|resource, check, schema, version, mcp (mcpgen itself as a stdio MCP server), plus an interactive TUI.

  • Transports: stdio (default) and stateless streamable http on /mcp with /healthz. Loopback bind 127.0.0.1:<port> by default; cross-site Origin rejected (403).

  • Protocol modes: compat (default, negotiates down to legacy versions) or latest-only (2026-07-28 only).

  • Opt-in features (--features tasks,skills,oauth): tasks stub, skills served from skills/, commented OAuth wiring for 2026-07-28 authorization.

  • Machine interface: --json envelope (ok, result, error{stage,code,message,fix,command,exit_code}, next_actions). Exit codes: 0 ok, 1 failure, 2 usage, 3 exists/not-project, 4 permission, 5 conflict, 6 prerequisite missing.

Status and limitations

  • The conformance gate runs only the scenarios the official suite can run against a generated server: protocol-level scenarios gate; capability-fixture scenarios (which need well-known test tools) are reported as non-gating. A default server shows 8/30 checks passed with 22 non-gating fixture failures; that is expected, not a bug.

  • The generated HTTP server has no authentication unless you enable and wire the oauth feature. It binds to loopback and rejects cross-site Origins, which is the default protection.

  • mcpgen.json supports config version 1 only.

  • mcpgen v0.3.2; generated servers pin go-sdk v1.8.0 (the tidy check stage enforces the pin).

Documentation

  • Docs site: quickstart, end-to-end tutorial, concepts (ownership model, marker regions, security), how-to guides, and a generated reference (CLI, mcpgen.json, exit codes, file tree).

  • AGENTS.md: repo guidance for coding agents. SKILL.md: the agent loop as a skill.

  • Contributing: architecture, local checks (make check), releases.

  • Development: make check (tidy, fmt, vet, race tests), make golden, make docs-gen / make docs-build for the docs site.

License

MIT. See LICENSE.

Available Tools

4 tools
mcpgen_addAdd a capability to an existing projectB

Add a tool, prompt, or resource to an existing mcpgen-generated project (mcpgen add). spec is the parsed JSON spec object.

NameRequiredDescriptionDefault
dirNoProject root; default .
kindYestool, prompt, or resource
specYesThe capability spec object (same shape as the spec file)
forceNo
dryRunNo

Output Schema

NameRequiredDescription
okYes
fixNo
codeNo
errorNo
resultNo
exit_codeNo

TDQS

B3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It says nothing about what files get written or overwritten, what happens when a capability of the same name exists (the force flag hints at overwrite but is never explained), whether dryRun defaults to false, or that this mutates the project on disk.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two short sentences, front-loaded with the action and scope, with the spec clarification tacked on usefully. Efficient, though the second sentence's pronoun ('spec') is slightly clipped.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists so return values needn't be described, and required params are named. But for a file-mutating tool with zero annotations, an undocumented force flag, and an unexplained dryRun option, the definition is thinner than the tool's complexity warrants.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Only 'spec' gets meaning beyond the schema ('the parsed JSON spec object', implying the caller must parse the file rather than pass a path), and 'kind' is just restated. With 60% schema coverage, the undocumented 'force' and 'dryRun' flags — both behaviorally significant for a mutating tool — are left entirely unexplained in both schema and description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Names a specific verb and resource ('Add a tool, prompt, or resource') scoped to 'an existing mcpgen-generated project', which implicitly distinguishes it from mcpgen_new (new project) and mcpgen_schema/check. It never names a sibling explicitly, so the differentiation is inferred rather than stated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The phrase 'to an existing mcpgen-generated project' implies the prerequisite and hints that project creation belongs to mcpgen_new, but there is no explicit when-to-use/when-not guidance, no mention of what to do if the capability already exists, and no routing to mcpgen_check for validation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

mcpgen_checkVerify a projectA

Run the mcpgen verification pipeline (mcpgen check). ok=true means green; stages lists every stage status and error.fix carries the first failure file:line.

NameRequiredDescriptionDefault
dirNoProject root; default .
inspectorNoRun the Inspector v2 smoke check
timeoutSecNoOverall pipeline timeout in seconds; default 600
conformanceNoForce the conformance stage on/off; default auto

Output Schema

NameRequiredDescription
okYes
fixNo
codeNo
errorNo
resultYes
exit_codeNo

TDQS

A3.5/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations supplied, the description carries the burden, and it does disclose the outcome model: ok=true means green, stages enumerates per-stage status, and error.fix gives the first failure at file:line. That is genuinely useful behavioral context. However, it omits side effects (does the pipeline write anything to disk?), expected runtime, and whether it is safe to run repeatedly — important for a tool whose name suggests a full pipeline.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single dense sentence with the outcome semantics front-loaded and no filler. It could be split for readability, but nothing is redundant.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Because an output schema exists and the input schema is fully described, the description only needs to frame intent and outcome, which it does. Minor gaps remain around side effects and interaction between the description and the optional stages (inspector/conformance), but an agent has enough to call it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all four parameters (dir, inspector, timeoutSec, conformance) and their defaults are already documented. The description adds no parameter-level meaning beyond the prose, so the baseline of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ("Run the mcpgen verification pipeline") and ties it to the CLI command it wraps (`mcpgen check`), which makes the tool's job immediately identifiable. It doesn't explicitly contrast itself with siblings like `mcpgen_add` or `mcpgen_schema`, but the verify-vs-scaffold distinction is clear from the wording.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Usage is only implied: an agent can infer it should call this to check a project's health, but there is no explicit when-to-use/when-not or reference to the sibling tools. No prerequisites (e.g. project must already be generated) are stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

mcpgen_newGenerate a new MCP server projectB

Generate a new Go MCP server project (mcpgen new). Writes files unless dryRun. Runs the validation pipeline unless noCheck.

NameRequiredDescriptionDefault
dirNoOutput directory, e.g. ./weather
nameNoServer name
portNoHTTP port when transport=http
forceNoAllow generating into an existing non-empty directory
toolsNoTool spec objects
dryRunNoPlan only; write nothing
moduleNoGo module path, e.g. github.com/acme/weather
noCheckNoSkip the validation pipeline
promptsNoPrompt spec objects
versionNoServer version (semver)
featuresNoOpt-in features: tasks, skills, oauth
protocolNocompat or latest-only
resourcesNoResource spec objects
transportNostdio or http

Output Schema

NameRequiredDescription
okYes
dirNo
fixNo
codeNo
planNo
checkNo
errorNo
exit_codeNo
next_actionsNo
files_skippedNo
files_writtenNo

TDQS

B3.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It usefully discloses that the tool writes files unless dryRun and runs a validation pipeline unless noCheck, but it omits that generation into an existing non-empty directory fails without force, does not say whether existing files can be overwritten, and gives no sense of reversibility or failure behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two short sentences, front-loaded with the core action, and no wasted wording. The dryRun and noCheck behavior is stated compactly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

This is a complex 14-parameter generator that writes files and runs validation, yet the description explains only two boolean side effects. The output schema covers return values, but the description does not prepare an agent for directory conflicts, force semantics, transport/module choices, or the relationship between tools, prompts, and resources.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3. The description adds a little meaning for dryRun and noCheck by explaining their effect, but says nothing about the other 12 parameters, including force, dir, transport, or feature selection.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: generate a new Go MCP server project, with the CLI equivalent `mcpgen new`. It distinguishes itself reasonably from `mcpgen_add`, `mcpgen_check`, and `mcpgen_schema` by the word 'new', though it never explicitly contrasts them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The only usage guidance is behavioral: writes files unless dryRun and runs validation unless noCheck. There is no guidance on when to use this tool instead of `mcpgen_add` or `mcpgen_check`, no prerequisite for existing directories, and no mention that `force` is needed for non-empty output.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

mcpgen_schemaMachine-readable spec of mcpgenB

Emit the mcpgen schema document: commands, flags, exit codes, the JSON envelope, and the mcpgen.json JSON Schema (mcpgen schema).

NameRequiredDescriptionDefault

No parameters

TDQS

B3.3/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are supplied, so the description carries the full burden. It usefully discloses what the returned payload contains (commands, flags, exit codes, JSON envelope, JSON Schema), which is effectively a return-value summary, but leaves the verb 'Emit' ambiguous: it does not say whether output goes to stdout or is written to a file, nor whether the call has side effects or is purely read-only.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single front-loaded sentence with a compact colon-delimited list of contents; nearly every clause adds information. The trailing parenthetical '(mcpgen schema)' restates the tool name and is mildly redundant.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no parameters and no output schema, the description does the right thing by enumerating the returned document's sections, but it stops short of describing the transport/format of the emitted output or its size, which is the main thing an agent still needs to know before calling.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool takes zero parameters, so the baseline is 4; there is nothing for the description to disambiguate. It correctly implies the call is parameterless by describing a fixed document rather than configurable output.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

Uses a specific verb ('Emit') with a concrete resource ('the mcpgen schema document') and enumerates its contents: commands, flags, exit codes, the JSON envelope, and the mcpgen.json JSON Schema. This clearly separates it from the sibling mutation/validation tools (mcpgen_add, mcpgen_check, mcpgen_new), though it never names them explicitly.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no when-to-use guidance, no statement of prerequisites, and no reference to alternatives such as mcpgen_check. The agent must infer from the purpose alone that this is the self-description/discovery call rather than a validation or scaffolding call.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool updatev0.1.1
    • Changedmcpgen_new15 fields changed
      • addedInput schema / properties / prompts / items / additionalProperties
        Added value: +false
      • removedInput schema / properties / prompts / items / items
        Removed value: -{
        -  "maximum": 255,
        -  "minimum": 0,
        -  "type": "integer"
        -}
      • addedInput schema / properties / prompts / items / properties
        Added value: +{
        +  "arguments": {
        +    "description": "Prompt arguments",
        +    "items": {
        +      "additionalProperties": false,
        +      "properties": {
        +        "description": {
        +          "description": "Argument description",
        +          "type": "string"
        +        },
        +        "name": {
        +          "description": "Argument name",
        +          "type": "string"
        +        },
        +        "required": {
        +          "description": "Whether the argument is required",
        +          "type": "boolean"
        +        },
        +        "title": {
        +          "description": "Argument title",
        +          "type": "string"
        +        }
        +      },
        +      "required": [
        +        "name"
        +      ],
        +      "type": "object"
        +    },
        +    "type": [
        +      "null",
        +      "array"
        +    ]
        +  },
        +  "description": {
        +    "description": "Prompt description",
        +    "type": "string"
        +  },
        +  "id": {
        +    "description": "Prompt id (unique, [a-zA-Z0-9_-]+)",
        +    "type": "string"
        +  },
        +  "title": {
        +    "description": "Prompt title",
        +    "type": "string"
        +  }
        +}
      • addedInput schema / properties / prompts / items / required
        Added value: +[
        +  "id"
        +]
      • changedInput schema / properties / prompts / items / type
        Previous value: -[
        -  "null",
        -  "array"
        -]New value: +"object"
      • addedInput schema / properties / resources / items / additionalProperties
        Added value: +false
      • removedInput schema / properties / resources / items / items
        Removed value: -{
        -  "maximum": 255,
        -  "minimum": 0,
        -  "type": "integer"
        -}
      • addedInput schema / properties / resources / items / properties
        Added value: +{
        +  "description": {
        +    "description": "Resource description",
        +    "type": "string"
        +  },
        +  "id": {
        +    "description": "Resource id (unique, [a-zA-Z0-9_-]+)",
        +    "type": "string"
        +  },
        +  "mimeType": {
        +    "description": "Resource MIME type",
        +    "type": "string"
        +  },
        +  "text": {
        +    "description": "Stub content served by the generated handler",
        +    "type": "string"
        +  },
        +  "title": {
        +    "description": "Resource title",
        +    "type": "string"
        +  },
        +  "uri": {
        +    "description": "Absolute URI. Exactly one of uri/uriTemplate",
        +    "type": "string"
        +  },
        +  "uriTemplate": {
        +    "description": "RFC 6570 URI template. Exactly one of uri/uriTemplate",
        +    "type": "string"
        +  }
        +}
      • addedInput schema / properties / resources / items / required
        Added value: +[
        +  "id"
        +]
      • changedInput schema / properties / resources / items / type
        Previous value: -[
        -  "null",
        -  "array"
        -]New value: +"object"
      • addedInput schema / properties / tools / items / additionalProperties
        Added value: +false
      • removedInput schema / properties / tools / items / items
        Removed value: -{
        -  "maximum": 255,
        -  "minimum": 0,
        -  "type": "integer"
        -}
      • addedInput schema / properties / tools / items / properties
        Added value: +{
        +  "description": {
        +    "description": "Tool description",
        +    "type": "string"
        +  },
        +  "id": {
        +    "description": "Tool id (unique, [a-zA-Z0-9_-]+)",
        +    "type": "string"
        +  },
        +  "idempotent": {
        +    "description": "Maps to the tool idempotentHint annotation",
        +    "type": "boolean"
        +  },
        +  "inputSchema": {
        +    "additionalProperties": true,
        +    "description": "JSON Schema object for tool input",
        +    "type": "object"
        +  },
        +  "outputSchema": {
        +    "additionalProperties": true,
        +    "description": "JSON Schema object for tool output",
        +    "type": "object"
        +  },
        +  "readOnly": {
        +    "description": "Maps to the tool readOnlyHint annotation",
        +    "type": "boolean"
        +  },
        +  "title": {
        +    "description": "Tool title",
        +    "type": "string"
        +  }
        +}
      • addedInput schema / properties / tools / items / required
        Added value: +[
        +  "id"
        +]
      • changedInput schema / properties / tools / items / type
        Previous value: -[
        -  "null",
        -  "array"
        -]New value: +"object"
  2. 4 tool updatesv0.1.0
    • First observedmcpgen_add
    • First observedmcpgen_check
    • First observedmcpgen_new
    • First observedmcpgen_schema

TDQS

A3.6/5.0

Scored across 4 tools

Disambiguation5/5

Each tool maps to a distinct mcpgen CLI subcommand: new creates a project, add extends one, check verifies it, and schema emits documentation. There is no overlap in purpose or resource, making selection unambiguous.

Naming Consistency4/5

All tools use a consistent mcpgen_ prefix followed by a short identifier. The pattern is slightly broken by 'schema' being a noun while new/add/check are verbs, but the overall convention is predictable and readable.

Tool Count5/5

Four tools is well-scoped for a CLI wrapper: one per core subcommand. Every tool earns its place without redundancy or missing obvious commands.

Completeness4/5

The surface covers project creation, extension, validation, and schema introspection, forming a coherent lifecycle. Minor gaps exist: no explicit removal, update, or listing operations, but agents can work around these via filesystem or CLI directly.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues

Related MCP Connectors

Related MCP Servers