mcpgen
Generate Go MCP server boilerplate from OpenAPI 3 specifications
claude mcp add --transport stdio lyeslabs-mcpgen npx -y github.com/lyeslabs/mcpgen/cmd/mcpgen@latest
How to use
mcpgen is a Go-based tool that reads an OpenAPI specification (YAML or JSON, OpenAPI 3.0) and generates a complete MCP server boilerplate in Go. The generated code includes server initialization, tool registration, handler skeletons, embedded JSON schemas for inputs, and markdown-based response prompts to guide AI agents. With mcpgen, you can turn your existing APIs into MCP tools that AI agents can interact with, while also optionally generating a Go HTTP client and types based on your schema. This makes it straightforward to expose complex APIs to agents with consistent, well-documented interfaces and prompts.
To use mcpgen, provide your OpenAPI spec via --input and specify an output directory with --output. You can enable validation, and optionally request the generation of an HTTP client and types with the --includes flag (e.g., --includes=httpclient,types). The tool then analyzes the endpoints, handles multiple content types, and outputs a Go-based MCP server scaffold with constants for schemas and markdown templates for responses, facilitating easy integration with your backend services.
How to install
Prerequisites:\n- Go installed (version 1.20+ recommended).\n- Ensure GOPATH/bin or your Go bin directory is in your PATH.\n\nInstall the mcpgen CLI:\nsh\ngo install github.com/lyeslabs/mcpgen/cmd/mcpgen@latest\n\nThis places the mcpgen executable in your Go bin directory (typically $HOME/go/bin or %USERPROFILE%\go\bin on Windows). Make sure that directory is in your PATH.\n\nUsage example:\nsh\nmcpgen --input api/openapi.yaml --output generated-server\n\nReplace api/openapi.yaml with the path to your OpenAPI file and generated-server with your desired output directory. Optional flags include --validation, --package, and --includes to tailor the generated code.\n
Additional notes
Notes and tips:\n- OpenAPI compatibility: mcpgen expects OpenAPI 3.0 definitions. Ensure schemas are valid and that components/schemas referenced by operations exist.\n- Multi-content support: If an operation defines multiple request/response content types, mcpgen will generate corresponding input schemas and response templates for each content type.\n- Generated prompts: The markdown-based response templates are designed to guide AI agents; you can customize them post-generation if needed.\n- Optional client and types: Use --includes=httpclient,types to also generate a Go HTTP client and type definitions alongside the server skeleton.\n- Validation: Enabling --validation performs OpenAPI validation during generation.\n- Common issues: Ensure the OpenAPI file ends with a valid document structure (no undefined references), and that any external references are resolvable. If generation fails due to schema constraints, inspect the generated output directory for the relevant error context and adjust the OpenAPI accordingly.
Related MCP Servers
sandbox
A Model Context Protocol (MCP) server that enables LLMs to run ANY code safely in isolated Docker containers.
github-brain
An experimental GitHub MCP server with local database.
temporal
Empowering AI with Workflow Orchestration
mcp-tts
MCP Server for Text to Speech
tasker
An MCP server for Android's Tasker automation app.
chromedp
MCP server for browser automation using chromedp