Feature: MCP Tool for go-zero Framework Version: 1.0.0 Date: November 14, 2025
mcp-zero is an MCP (Model Context Protocol) server that brings go-zero framework capabilities to AI assistants like Claude Desktop. Use natural language to create services, generate code, and manage go-zero projects.
- Go 1.19 or later
- goctl (go-zero CLI tool)
- Claude Desktop (or other MCP-compatible AI assistant)
go install github.com/zeromicro/go-zero/tools/goctl@latestVerify installation:
goctl --versionBuild from source:
git clone https://github.com/zeromicro/mcp-zero.git
cd mcp-zero
go build -o mcp-zeroAfter the project is published, you'll be able to install via:
go install github.com/zeromicro/mcp-zero@latestAdd to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"go-zero": {
"command": "/Users/yourname/go/bin/mcp-zero",
"env": {
"GOCTL_PATH": "/Users/yourname/go/bin/goctl"
}
}
}
}Note: Adjust paths to match your installation locations.
Quit and restart Claude Desktop to load the new MCP server.
Open Claude Desktop and try:
Create a new API service called "userservice" on port 8080
Claude will use mcp-zero to:
- Validate the service name
- Execute goctl to generate project structure
- Fix import paths and initialize go modules
- Verify the build succeeds
- Provide next steps
Example response:
Successfully created api service 'userservice'
Output directory: /your/current/directory/userservice
Additional Information:
port: 8080
style: go_zero
Next steps:
1. cd /your/current/directory/userservice
2. go mod tidy
3. go run .
The generated service includes:
userservice.api- API specification fileetc/userservice.yaml- Configuration fileinternal/handler/- HTTP handlersinternal/logic/- Business logicinternal/svc/servicecontext.go- Service contextuserservice.go- Main entry point
Before running the service, you need to define your API endpoints. Edit the userservice.api file:
syntax = "v1"
info (
title: "userservice"
desc: "userservice API"
author: "your name"
email: "your@email.com"
)
type (
PingRequest {}
PingResponse {
Message string `json:"message"`
}
)
service userservice-api {
@handler PingHandler
get /ping (PingRequest) returns (PingResponse)
}Then regenerate the code:
Generate code from the userservice.api file in ./userservice
cd userservice
go run userservice.goNow test it:
curl http://localhost:8080/ping
# Response: {"message":"pong"}You'll need to implement the logic in internal/logic/pinglogic.go:
func (l *PingLogic) Ping(req *types.PingRequest) (resp *types.PingResponse, err error) {
return &types.PingResponse{
Message: "pong",
}, nil
}To add another endpoint, just add it to the .api file and regenerate:
service userservice-api {
@handler PingHandler
get /ping (PingRequest) returns (PingResponse)
@handler UserInfoHandler
get /user/:id (UserInfoRequest) returns (UserInfoResponse)
}Create an RPC service called "authservice" with methods Login and Verify
Analyze the project in /path/to/my/go-zero/project
You'll get:
- List of all endpoints
- Service dependencies
- Configuration files
- Suggestions for improvements
Generate models for the users table in mysql://user:pass@localhost:3306/mydb
Generate authentication middleware for JWT tokens
Create these services in ./services directory:
- API gateway on port 8080
- User service RPC on port 9001
- Order service RPC on port 9002
Create an API spec for a user service with these endpoints:
- POST /login
- POST /register
- GET /user/:id
- PUT /user/:id
Then generate code:
Generate code from userservice.api
I have a service at ./userservice. Add rate limiting middleware.
Generate a production configuration template for my API service
How do I migrate my Express.js API to go-zero?
- ✅ Good:
userservice,orderservice,apigateway - ❌ Bad:
user-service(hyphens not allowed),123service(must start with letter)
- Use ports 8080-8089 for API services
- Use ports 9000-9099 for RPC services
- mcp-zero will warn if ports are already in use
For monorepo:
myproject/
├── services/
│ ├── api-gateway/
│ ├── user-service/
│ └── order-service/
└── shared/
└── types/
Ask Claude:
Create services in ./services directory
If generation fails:
The service generation failed. Try again with corrected parameters.
mcp-zero preserves partial state, so you won't lose progress.
Explain go-zero middleware
What's the difference between API and RPC services in go-zero?
Show me best practices for error handling in go-zero
Problem: mcp-zero can't find goctl executable.
Solution:
- Verify goctl is installed:
goctl --version - Add GOCTL_PATH to Claude config (see Installation step 3)
- Or add goctl to your PATH
Problem: Service name contains invalid characters.
Solution: Use only letters, numbers, and underscores. Start with a letter.
user-service→userserviceoruser_service
Problem: Specified port is occupied.
Solution: Choose a different port or stop the service using that port.
Problem: Generated code doesn't compile.
Solution:
- Check the error message for missing dependencies
- Run
go mod tidy - Report the issue if it persists
Problem: Can't write to output directory.
Solution: Use a directory where you have write permissions, or create the directory first.
Use this middleware template for my service:
[paste your template]
Create 5 microservices: user, order, product, payment, notification
All RPC services, ports starting from 9001
Validate my configuration file at ./etc/config.yaml
Generate documentation for my project structure
GOCTL_PATH: Override goctl executable location
- Read the full documentation
- Explore go-zero documentation
- Join the go-zero community
- GitHub Issues: github.com/zeromicro/mcp-zero/issues
- go-zero Discord: discord.gg/go-zero
Happy coding with mcp-zero! 🚀