@@ -20,13 +20,13 @@ mcp-zero is an MCP (Model Context Protocol) server that brings go-zero framework
2020
2121``` bash
2222go install github.com/zeromicro/go-zero/tools/goctl@latest
23- ```
23+ ` ` ` text
2424
2525Verify installation:
2626
2727` ` ` bash
2828goctl --version
29- ```
29+ ` ` ` text
3030
3131# ## 2. Install mcp-zero
3232
@@ -36,13 +36,13 @@ Build from source:
3636git clone https://github.com/zeromicro/mcp-zero.git
3737cd mcp-zero
3838go build -o mcp-zero
39- ```
39+ ` ` ` text
4040
4141After the project is published, you' ll be able to install via:
4242
4343```bash
4444go install github.com/zeromicro/mcp-zero@latest
45- ```
45+ ```text
4646
4747### 3. Configure Claude Desktop
4848
@@ -59,7 +59,7 @@ Add to your Claude Desktop configuration (`~/Library/Application Support/Claude/
5959 }
6060 }
6161}
62- ```
62+ ```text
6363
6464**Note**: Adjust paths to match your installation locations.
6565
@@ -73,9 +73,9 @@ Quit and restart Claude Desktop to load the new MCP server.
7373
7474Open Claude Desktop and try:
7575
76- ```
76+ ```text
7777Create a new API service called "userservice" on port 8080
78- ```
78+ ```text
7979
8080Claude will use mcp-zero to:
8181
@@ -87,7 +87,7 @@ Claude will use mcp-zero to:
8787
8888Example response:
8989
90- ```
90+ ```text
9191Successfully created api service ' userservice'
9292
9393Output directory: /your/current/directory/userservice
@@ -100,6 +100,49 @@ Next steps:
100100 1. cd /your/current/directory/userservice
101101 2. go mod tidy
102102 3. go run .
103+ ```text
104+
105+ ### Understanding the Generated Structure
106+
107+ The generated service includes:
108+ - `userservice.api` - API specification file
109+ - `etc/userservice.yaml` - Configuration file
110+ - `internal/handler/` - HTTP handlers
111+ - `internal/logic/` - Business logic
112+ - `internal/svc/servicecontext.go` - Service context
113+ - `userservice.go` - Main entry point
114+
115+ ### Adding Your First Endpoint
116+
117+ Before running the service, you need to define your API endpoints. Edit the `userservice.api` file:
118+
119+ ```go
120+ syntax = "v1"
121+
122+ info (
123+ title: "userservice"
124+ desc: "userservice API"
125+ author: "your name"
126+ email: "your@email.com"
127+ )
128+
129+ type (
130+ PingRequest {}
131+ PingResponse {
132+ Message string `json:"message"`
133+ }
134+ )
135+
136+ service userservice-api {
137+ @handler PingHandler
138+ get /ping (PingRequest) returns (PingResponse)
139+ }
140+ ```
141+
142+ Then regenerate the code:
143+
144+ ```text
145+ Generate code from the userservice.api file in ./userservice
103146```
104147
105148### Running the Service
@@ -109,37 +152,48 @@ cd userservice
109152go run userservice.go
110153```
111154
112- Test it:
155+ Now test it:
113156
114157```bash
115158curl http://localhost:8080/ping
116159# Response: {"message":"pong"}
117160```
118161
119- ### Adding an Endpoint
162+ You ' ll need to implement the logic in ` internal/logic/pinglogic.go ` :
120163
121- To add new endpoints, you'll need to:
164+ ` ` ` go
165+ func (l * PingLogic) Ping(req * types.PingRequest) (resp * types.PingResponse, err error) {
166+ return & types.PingResponse{
167+ Message: " pong" ,
168+ }, nil
169+ }
170+ ```
122171
123- 1 . Edit the ` .api ` file manually to add your endpoint
124- 2 . Regenerate code from the updated spec:
172+ ### Adding More Endpoints
125173
126- ```
127- Generate code from the userservice.api file in ./userservice
128- ```
174+ To add another endpoint, just add it to the ` .api ` file and regenerate:
129175
130- Claude will use the ` generate_api_from_spec ` tool to regenerate the service with your new endpoints.
176+ ``` go
177+ service userservice-api {
178+ @handler PingHandler
179+ get /ping (PingRequest) returns (PingResponse)
180+
181+ @handler UserInfoHandler
182+ get /user/:id (UserInfoRequest) returns (UserInfoResponse)
183+ }
184+ ```
131185
132186### Creating an RPC Service
133187
134- ```
188+ ``` text
135189Create an RPC service called "authservice" with methods Login and Verify
136- ```
190+ ```text
137191
138192### Analyzing a Project
139193
140- ```
194+ ```text
141195Analyze the project in /path/to/my/go-zero/project
142- ```
196+ ```text
143197
144198You'll get:
145199
@@ -150,60 +204,60 @@ You'll get:
150204
151205### Generating Database Models
152206
153- ```
207+ ```text
154208Generate models for the users table in mysql://user:pass@localhost:3306/mydb
155- ```
209+ ```text
156210
157211### Creating Middleware
158212
159- ```
213+ ```text
160214Generate authentication middleware for JWT tokens
161- ```
215+ ```text
162216
163217## Common Use Cases
164218
165219### 1. Starting a New Microservice Project
166220
167- ```
221+ ```text
168222Create these services in ./services directory:
169223- API gateway on port 8080
170224- User service RPC on port 9001
171225- Order service RPC on port 9002
172- ```
226+ ```text
173227
174228### 2. Spec-First Development
175229
176- ```
230+ ```text
177231Create an API spec for a user service with these endpoints:
178232- POST /login
179233- POST /register
180234- GET /user/:id
181235- PUT /user/:id
182- ```
236+ ```text
183237
184238Then generate code:
185239
186- ```
240+ ```text
187241Generate code from userservice.api
188- ```
242+ ```text
189243
190244### 3. Adding Features to Existing Service
191245
192- ```
246+ ```text
193247I have a service at ./userservice. Add rate limiting middleware.
194- ```
248+ ```text
195249
196250### 4. Configuration Management
197251
198- ```
252+ ```text
199253Generate a production configuration template for my API service
200- ```
254+ ```text
201255
202256### 5. Migration from Another Framework
203257
204- ```
258+ ```text
205259How do I migrate my Express.js API to go-zero?
206- ```
260+ ```text
207261
208262## Tips & Best Practices
209263
@@ -222,45 +276,45 @@ How do I migrate my Express.js API to go-zero?
222276
223277For monorepo:
224278
225- ```
279+ ```text
226280myproject/
227281├── services/
228282│ ├── api-gateway/
229283│ ├── user-service/
230284│ └── order-service/
231285└── shared/
232286 └── types/
233- ```
287+ ```text
234288
235289Ask Claude:
236290
237- ```
291+ ```text
238292Create services in ./services directory
239- ```
293+ ```text
240294
241295### Error Recovery
242296
243297If generation fails:
244298
245- ```
299+ ```text
246300The service generation failed. Try again with corrected parameters.
247- ```
301+ ```text
248302
249303mcp-zero preserves partial state, so you won't lose progress.
250304
251305### Getting Help
252306
253- ```
307+ ```text
254308Explain go-zero middleware
255- ```
309+ ```text
256310
257- ```
311+ ```text
258312What's the difference between API and RPC services in go-zero?
259- ```
313+ ```text
260314
261- ```
315+ ```text
262316Show me best practices for error handling in go-zero
263- ```
317+ ```text
264318
265319## Troubleshooting
266320
@@ -308,29 +362,29 @@ Show me best practices for error handling in go-zero
308362
309363### Custom Templates
310364
311- ```
365+ ```text
312366Use this middleware template for my service:
313367[paste your template]
314- ```
368+ ```text
315369
316370### Batch Operations
317371
318- ```
372+ ```text
319373Create 5 microservices: user, order, product, payment, notification
320374All RPC services, ports starting from 9001
321- ```
375+ ```text
322376
323377### Configuration Validation
324378
325- ```
379+ ```text
326380Validate my configuration file at ./etc/config.yaml
327- ```
381+ ```text
328382
329383### Project Documentation
330384
331- ```
385+ ```text
332386Generate documentation for my project structure
333- ```
387+ ```text
334388
335389## Environment Variables
336390
0 commit comments