A Model Context Protocol (MCP) tool that helps developers quickly scaffold and generate go-zero projects with ease.
New to mcp-zero? Check out our Quick Start Guide for a step-by-step tutorial on getting started!
The quickstart covers:
- Installation and configuration
- Creating your first API service
- Common use cases and workflows
- Integration with Claude Desktop
- Create API Services: Generate new REST API services with customizable ports and styles
- Create RPC Services: Generate gRPC services from protobuf definitions
- Generate API Code: Convert API specification files to Go code
- Generate Models: Create database models from various sources (MySQL, PostgreSQL, MongoDB, DDL)
- Create API Specs: Generate sample API specification files
- Analyze Projects: Analyze existing go-zero projects to understand structure and dependencies
- Manage Configuration: Generate configuration files with proper structure validation
- Generate Templates: Create middleware, error handlers, and deployment templates
- Query Documentation: Access go-zero concepts and migration guides from other frameworks
- Validate Input: Comprehensive validation for API specs, protobuf definitions, and configurations
-
Go (1.19 or later)
-
go-zero CLI (goctl): Install with
go install github.com/zeromicro/go-zero/tools/goctl@latest -
Claude Desktop (or other MCP-compatible client)
For detailed installation instructions, see the Quick Start Guide.
-
Create a new directory for your MCP tool:
mkdir go-zero-mcp && cd go-zero-mcp
-
Initialize Go module:
go mod init go-zero-mcp
-
Install dependencies:
go get github.com/modelcontextprotocol/go-sdk go get gopkg.in/yaml.v3
-
Save the main tool code as
main.go -
Build the tool:
go build -o go-zero-mcp main.go
Add this configuration to your Claude Desktop MCP settings:
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"mcp-zero": {
"command": "/path/to/your/mcp-zero",
"env": {
"GOCTL_PATH": "/Users/yourname/go/bin/goctl"
}
}
}
}Edit ~/.config/Claude/claude_desktop_config.json:
{
"mcpServers": {
"mcp-zero": {
"command": "/path/to/your/mcp-zero",
"env": {
"GOCTL_PATH": "/usr/local/bin/goctl"
}
}
}
}Edit %APPDATA%\Claude\claude_desktop_config.json:
{
"mcpServers": {
"mcp-zero": {
"command": "C:\\path\\to\\your\\mcp-zero.exe",
"env": {
"GOCTL_PATH": "C:\\Go\\bin\\goctl.exe"
}
}
}
}Creates a new go-zero API service.
Parameters:
service_name(required): Name of the API serviceport(optional): Port number (default: 8888)style(optional): Code style - "go_zero" or "gozero" (default: "go_zero")output_dir(optional): Output directory (default: current directory)
Creates a new go-zero RPC service from protobuf definition.
Parameters:
service_name(required): Name of the RPC serviceproto_content(required): Protobuf definition contentoutput_dir(optional): Output directory (default: current directory)
Generates go-zero API code from an API specification file.
Parameters:
api_file(required): Path to the .api specification fileoutput_dir(optional): Output directory (default: current directory)style(optional): Code style - "go_zero" or "gozero" (default: "go_zero")
Generates database model code from database schema.
Parameters:
source_type(required): Source type - "mysql", "postgresql", "mongo", or "ddl"source(required): Database connection string or DDL file pathtable(optional): Specific table name (for database sources)output_dir(optional): Output directory (default: "./model")
Creates a sample API specification file.
Parameters:
service_name(required): Name of the API serviceendpoints(required): Array of endpoint objects with method, path, and handleroutput_file(optional): Output file path (default: service_name.api)
Analyzes an existing go-zero project structure and dependencies.
Parameters:
project_dir(required): Path to the project directoryanalysis_type(optional): Type of analysis - "api", "rpc", "model", or "full" (default: "full")
Generates configuration files for go-zero services.
Parameters:
service_name(required): Name of the serviceservice_type(required): Service type - "api" or "rpc"config_type(optional): Configuration type - "dev", "test", or "prod" (default: "dev")output_file(optional): Output file path (default: etc/{service_name}.yaml)
Generates common code templates for go-zero services.
Parameters:
template_type(required): Template type - "middleware", "error_handler", "dockerfile", "docker_compose", or "kubernetes"service_name(required): Name of the serviceoutput_path(optional): Output file path (uses defaults based on template type)
Queries go-zero documentation and migration guides.
Parameters:
query(required): Natural language query about go-zero concepts or migrationdoc_type(optional): Documentation type - "concept", "migration", or "both" (default: "both")
Validates API specs, protobuf definitions, or configuration files.
Parameters:
input_type(required): Input type - "api_spec", "proto", or "config"content(required): Content to validatestrict(optional): Enable strict validation mode (default: false)
Please create a new go-zero API service called "user-service" on port 8080
Create a new go-zero RPC service called "auth-service" with this protobuf definition:
syntax = "proto3";
package auth;
option go_package = "./auth";
service AuthService {
rpc Login(LoginRequest) returns (LoginResponse);
rpc Logout(LogoutRequest) returns (LogoutResponse);
}
message LoginRequest {
string username = 1;
string password = 2;
}
message LoginResponse {
string token = 1;
int64 expires_at = 2;
}
message LogoutRequest {
string token = 1;
}
message LogoutResponse {
bool success = 1;
}
Generate go-zero models from my MySQL database with connection string "user:password@tcp(localhost:3306)/mydb"
Create an API specification for a "blog-service" with these endpoints:
- GET /api/posts (handler: GetPostsHandler)
- POST /api/posts (handler: CreatePostHandler)
- GET /api/posts/:id (handler: GetPostHandler)
- PUT /api/posts/:id (handler: UpdatePostHandler)
- DELETE /api/posts/:id (handler: DeletePostHandler)
Analyze my go-zero project in /path/to/myproject to understand its structure
Generate a production configuration file for my "order-service" API service
Generate a middleware template for my "auth-service"
How do I implement JWT authentication in go-zero?
How do I migrate from Express.js to go-zero?
Validate this API spec file at /path/to/service.api with strict mode enabled
After building, your MCP server will have the following structure:
mcp-zero/
├── main.go # Entry point and tool registration
├── tools/ # Tool implementations
│ ├── create_api_service.go
│ ├── create_rpc_service.go
│ ├── generate_api.go
│ ├── generate_model.go
│ ├── create_api_spec.go
│ ├── analyze_project.go
│ ├── generate_config.go
│ ├── generate_template.go
│ ├── query_docs.go
│ └── validate_input.go
├── internal/ # Internal packages
│ ├── analyzer/ # Project analysis
│ ├── validation/ # Input validation
│ ├── security/ # Credential handling
│ ├── templates/ # Code templates
│ ├── docs/ # Documentation database
│ ├── logging/ # Structured logging
│ └── metrics/ # Performance metrics
└── tests/ # Test suites
├── integration/
└── unit/
The MCP server is built with:
- MCP SDK: Uses github.com/modelcontextprotocol/go-sdk for protocol implementation
- Transport: stdio-based communication with Claude Desktop
- Code Generation: Leverages go-zero's goctl CLI tool for generating production-ready code
- Validation: Comprehensive input validation for safety and correctness
- Security: Safe credential handling with environment variable substitution
- Observability: Built-in logging and metrics for monitoring tool performance
- Service Naming: Use lowercase with hyphens (e.g., "user-service", "auth-api")
- Port Configuration: Choose unique ports for each service (8080-8090 range recommended)
- Code Style: Stick to "go_zero" style for consistency with official conventions
- Configuration: Use environment-specific configs (dev, test, prod)
- Documentation: Query docs regularly to stay aligned with go-zero best practices
- Validation: Always validate inputs before generation to catch errors early
- goctl command not found: Make sure goctl is installed and in your PATH
- Permission denied: Ensure the MCP tool executable has proper permissions
- Database connection errors: Verify connection strings and database accessibility
To enable debug logging, set the environment variable:
export MCP_DEBUG=1Feel free to extend this tool with additional go-zero features such as:
- Dockerfile generation
- Kubernetes manifest generation
- Docker Compose file creation
- API documentation generation
- Testing template creation
MIT License - see LICENSE file for details.
Copyright (c) 2025 go-zero team