@@ -73,7 +73,7 @@ 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
7878```
7979
@@ -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
@@ -102,42 +102,96 @@ Next steps:
102102 3. go run .
103103```
104104
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
146+ ```
147+
105148### Running the Service
106149
107150``` bash
108151cd 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
136190```
137191
138192### Analyzing a Project
139193
140- ```
194+ ``` text
141195Analyze the project in /path/to/my/go-zero/project
142196```
143197
@@ -150,21 +204,21 @@ 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
155209```
156210
157211### Creating Middleware
158212
159- ```
213+ ``` text
160214Generate authentication middleware for JWT tokens
161215```
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
@@ -173,7 +227,7 @@ Create these services in ./services directory:
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
@@ -183,25 +237,25 @@ Create an API spec for a user service with these endpoints:
183237
184238Then generate code:
185239
186- ```
240+ ``` text
187241Generate code from userservice.api
188242```
189243
190244### 3. Adding Features to Existing Service
191245
192- ```
246+ ``` text
193247I have a service at ./userservice. Add rate limiting middleware.
194248```
195249
196250### 4. Configuration Management
197251
198- ```
252+ ``` text
199253Generate a production configuration template for my API service
200254```
201255
202256### 5. Migration from Another Framework
203257
204- ```
258+ ``` text
205259How do I migrate my Express.js API to go-zero?
206260```
207261
@@ -222,7 +276,7 @@ How do I migrate my Express.js API to go-zero?
222276
223277For monorepo:
224278
225- ```
279+ ``` text
226280myproject/
227281├── services/
228282│ ├── api-gateway/
@@ -234,31 +288,31 @@ myproject/
234288
235289Ask Claude:
236290
237- ```
291+ ``` text
238292Create services in ./services directory
239293```
240294
241295### Error Recovery
242296
243297If generation fails:
244298
245- ```
299+ ``` text
246300The service generation failed. Try again with corrected parameters.
247301```
248302
249303mcp-zero preserves partial state, so you won't lose progress.
250304
251305### Getting Help
252306
253- ```
307+ ``` text
254308Explain go-zero middleware
255309```
256310
257- ```
311+ ``` text
258312What's the difference between API and RPC services in go-zero?
259313```
260314
261- ```
315+ ``` text
262316Show me best practices for error handling in go-zero
263317```
264318
@@ -308,27 +362,27 @@ 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]
314368```
315369
316370### Batch Operations
317371
318- ```
372+ ``` text
319373Create 5 microservices: user, order, product, payment, notification
320374All RPC services, ports starting from 9001
321375```
322376
323377### Configuration Validation
324378
325- ```
379+ ``` text
326380Validate my configuration file at ./etc/config.yaml
327381```
328382
329383### Project Documentation
330384
331- ```
385+ ``` text
332386Generate documentation for my project structure
333387```
334388
0 commit comments