@ai-content-space/loopx 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +343 -56
  2. package/README.zh-CN.md +392 -0
  3. package/package.json +4 -1
  4. package/plugins/loopx/.codex-plugin/plugin.json +1 -1
  5. package/plugins/loopx/scripts/plugin-install.test.mjs +1 -0
  6. package/plugins/loopx/skills/archive/SKILL.md +39 -0
  7. package/plugins/loopx/skills/build/SKILL.md +111 -9
  8. package/plugins/loopx/skills/clarify/SKILL.md +121 -1
  9. package/plugins/loopx/skills/debug/SKILL.md +296 -0
  10. package/plugins/loopx/skills/debug/condition-based-waiting.md +115 -0
  11. package/plugins/loopx/skills/debug/defense-in-depth.md +122 -0
  12. package/plugins/loopx/skills/debug/find-polluter.sh +63 -0
  13. package/plugins/loopx/skills/debug/root-cause-tracing.md +169 -0
  14. package/plugins/loopx/skills/go-style/SKILL.md +71 -0
  15. package/plugins/loopx/skills/kratos/SKILL.md +74 -0
  16. package/plugins/loopx/skills/kratos/references/advanced-features.md +314 -0
  17. package/plugins/loopx/skills/kratos/references/architecture.md +488 -0
  18. package/plugins/loopx/skills/kratos/references/configuration.md +399 -0
  19. package/plugins/loopx/skills/kratos/references/http-customization.md +512 -0
  20. package/plugins/loopx/skills/kratos/references/middleware-logging.md +400 -0
  21. package/plugins/loopx/skills/kratos/references/proto-api-design.md +432 -0
  22. package/plugins/loopx/skills/kratos/references/security-auth.md +411 -0
  23. package/plugins/loopx/skills/kratos/references/troubleshooting.md +385 -0
  24. package/plugins/loopx/skills/plan/SKILL.md +22 -2
  25. package/plugins/loopx/skills/review/SKILL.md +98 -1
  26. package/plugins/loopx/skills/tdd/SKILL.md +371 -0
  27. package/plugins/loopx/skills/tdd/testing-anti-patterns.md +299 -0
  28. package/plugins/loopx/skills/verify/SKILL.md +139 -0
  29. package/scripts/codex-stop-hook.mjs +71 -0
  30. package/scripts/codex-workflow-hook.mjs +153 -0
  31. package/skills/archive/SKILL.md +39 -0
  32. package/skills/build/SKILL.md +111 -9
  33. package/skills/clarify/SKILL.md +121 -1
  34. package/skills/debug/SKILL.md +296 -0
  35. package/skills/debug/condition-based-waiting.md +115 -0
  36. package/skills/debug/defense-in-depth.md +122 -0
  37. package/skills/debug/find-polluter.sh +63 -0
  38. package/skills/debug/root-cause-tracing.md +169 -0
  39. package/skills/go-style/SKILL.md +71 -0
  40. package/skills/kratos/SKILL.md +74 -0
  41. package/skills/kratos/references/advanced-features.md +314 -0
  42. package/skills/kratos/references/architecture.md +488 -0
  43. package/skills/kratos/references/configuration.md +399 -0
  44. package/skills/kratos/references/http-customization.md +512 -0
  45. package/skills/kratos/references/middleware-logging.md +400 -0
  46. package/skills/kratos/references/proto-api-design.md +432 -0
  47. package/skills/kratos/references/security-auth.md +411 -0
  48. package/skills/kratos/references/troubleshooting.md +385 -0
  49. package/skills/plan/SKILL.md +22 -2
  50. package/skills/review/SKILL.md +98 -1
  51. package/skills/tdd/SKILL.md +371 -0
  52. package/skills/tdd/testing-anti-patterns.md +299 -0
  53. package/skills/verify/SKILL.md +139 -0
  54. package/src/build-runtime.mjs +303 -26
  55. package/src/build-stop-gate.mjs +94 -0
  56. package/src/cli.mjs +51 -8
  57. package/src/codex-exec-runtime.mjs +105 -5
  58. package/src/context-manifest.mjs +172 -0
  59. package/src/install-discovery.mjs +352 -5
  60. package/src/next-skill.mjs +85 -0
  61. package/src/plan-runtime.mjs +100 -122
  62. package/src/review-runtime.mjs +378 -0
  63. package/src/runtime-maintenance.mjs +428 -14
  64. package/src/template-governance.mjs +223 -0
  65. package/src/workflow.mjs +1947 -118
  66. package/src/workspace-context.mjs +166 -0
  67. package/src/workspace-memory.mjs +69 -0
  68. package/templates/plan.md +6 -0
@@ -0,0 +1,314 @@
1
+ # Advanced Features
2
+
3
+ Guide for MCP server integration and other advanced Kratos features.
4
+
5
+ ## When to Use
6
+
7
+ - Integrating Kratos with AI agents via MCP
8
+ - Building tool-enabled microservices
9
+
10
+ ---
11
+
12
+ ## MCP Server Integration
13
+
14
+ Kratos can be combined with MCP (Model Context Protocol) to expose microservice functionality as AI agent tools.
15
+
16
+ ### What is MCP?
17
+
18
+ MCP is a protocol for AI agents to discover and call tools. By integrating MCP with Kratos services, you can:
19
+
20
+ - Expose Kratos APIs as MCP tools for AI agents
21
+ - Enable tool discovery and schema validation
22
+ - Handle structured input/output for AI workflows
23
+
24
+ ### Library Options
25
+
26
+ Two main Go MCP libraries exist:
27
+
28
+ | Library | Maintainer | Use Case |
29
+ |---------|------------|----------|
30
+ | `github.com/mark3labs/mcp-go` | Mark3 Labs | Community implementation |
31
+ | `github.com/modelcontextprotocol/go-sdk` | Anthropic | Official SDK |
32
+
33
+ **Note:** No official Kratos MCP transport exists yet. Integration requires custom setup.
34
+
35
+ ### Integration Approach: MCP Handler in Kratos HTTP Server
36
+
37
+ Add MCP endpoint to existing Kratos HTTP server:
38
+
39
+ ```go
40
+ import (
41
+ "context"
42
+ "fmt"
43
+ "github.com/go-kratos/kratos/v2"
44
+ "github.com/go-kratos/kratos/v2/log"
45
+ "github.com/go-kratos/kratos/v2/transport/http"
46
+ mcp "github.com/mark3labs/mcp-go/mcp"
47
+ "github.com/mark3labs/mcp-go/server"
48
+ )
49
+
50
+ func main() {
51
+ // Create MCP server
52
+ mcpSrv := server.NewMCPServer("kratos-mcp", "v1.0.0")
53
+
54
+ // Define tool
55
+ tool := mcp.NewTool("hello_world",
56
+ mcp.WithDescription("Say hello to someone"),
57
+ mcp.WithString("name",
58
+ mcp.Required(),
59
+ mcp.Description("Name of the person to greet"),
60
+ ),
61
+ )
62
+
63
+ // Add tool handler
64
+ mcpSrv.AddTool(tool, helloHandler)
65
+
66
+ // Create Kratos HTTP server with MCP endpoint
67
+ httpSrv := http.NewServer(http.Address(":8000"))
68
+
69
+ // Register MCP handler on Kratos HTTP server
70
+ // MCP typically uses SSE (Server-Sent Events) transport
71
+ route := httpSrv.Route("/")
72
+ route.GET("/mcp", func(ctx http.Context) error {
73
+ // Handle MCP SSE requests
74
+ return handleMCPRequest(ctx, mcpSrv)
75
+ })
76
+
77
+ // Create Kratos app
78
+ app := kratos.New(
79
+ kratos.Name("kratos-mcp"),
80
+ kratos.Server(httpSrv),
81
+ )
82
+
83
+ if err := app.Run(); err != nil {
84
+ panic(err)
85
+ }
86
+ }
87
+ ```
88
+
89
+ ### Tool Handler
90
+
91
+ ```go
92
+ func helloHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
93
+ // Extract arguments
94
+ name, ok := request.Params.Arguments["name"].(string)
95
+ if !ok {
96
+ return nil, errors.New("name must be a string")
97
+ }
98
+
99
+ // Return result
100
+ return mcp.NewToolResultText(fmt.Sprintf("Hello, %s!", name)), nil
101
+ }
102
+ ```
103
+
104
+ ### Multiple Tools
105
+
106
+ ```go
107
+ func registerMCPTools(mcpSrv *server.MCPServer, userUC *biz.UserUseCase, orderUC *biz.OrderUseCase) {
108
+ // Tool 1: User lookup
109
+ userTool := mcp.NewTool("get_user",
110
+ mcp.WithDescription("Get user by ID"),
111
+ mcp.WithString("user_id",
112
+ mcp.Required(),
113
+ mcp.Description("User identifier"),
114
+ ),
115
+ )
116
+ mcpSrv.AddTool(userTool, func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
117
+ userID, ok := req.Params.Arguments["user_id"].(string)
118
+ if !ok {
119
+ return mcp.NewToolResultError("user_id must be a string"), nil
120
+ }
121
+ // Call biz layer
122
+ user, err := userUC.GetUser(ctx, userID)
123
+ if err != nil {
124
+ return mcp.NewToolResultError(err.Error()), nil
125
+ }
126
+ return mcp.NewToolResultText(fmt.Sprintf("User: %s, Email: %s", user.Name, user.Email)), nil
127
+ })
128
+
129
+ // Tool 2: Order creation
130
+ orderTool := mcp.NewTool("create_order",
131
+ mcp.WithDescription("Create a new order"),
132
+ mcp.WithString("user_id", mcp.Required()),
133
+ mcp.WithString("product_id", mcp.Required()),
134
+ mcp.WithNumber("quantity", mcp.Required()),
135
+ )
136
+ mcpSrv.AddTool(orderTool, func(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToolResult, error) {
137
+ userID, ok := req.Params.Arguments["user_id"].(string)
138
+ if !ok {
139
+ return mcp.NewToolResultError("user_id must be a string"), nil
140
+ }
141
+ productID, ok := req.Params.Arguments["product_id"].(string)
142
+ if !ok {
143
+ return mcp.NewToolResultError("product_id must be a string"), nil
144
+ }
145
+ quantity, ok := req.Params.Arguments["quantity"].(float64)
146
+ if !ok {
147
+ return mcp.NewToolResultError("quantity must be a number"), nil
148
+ }
149
+
150
+ // Call biz layer
151
+ order, err := orderUC.CreateOrder(ctx, userID, productID, int(quantity))
152
+ if err != nil {
153
+ return mcp.NewToolResultError(err.Error()), nil
154
+ }
155
+
156
+ return mcp.NewToolResultText(fmt.Sprintf("Order created: %s", order.ID)), nil
157
+ })
158
+ }
159
+ ```
160
+
161
+ ### MCP with Kratos Middleware
162
+
163
+ Wrap MCP endpoint with Kratos middleware for logging, auth, etc.:
164
+
165
+ ```go
166
+ func NewHTTPServer(c *conf.Server, mcpSrv *server.MCPServer, logger log.Logger) *http.Server {
167
+ srv := http.NewServer(
168
+ http.Address(c.Http.Addr),
169
+ http.Middleware(
170
+ recovery.Recovery(),
171
+ tracing.Server(),
172
+ logging.Server(logger),
173
+ ),
174
+ )
175
+
176
+ // MCP endpoint with middleware chain
177
+ route := srv.Route("/")
178
+ route.GET("/mcp", func(ctx http.Context) error {
179
+ http.SetOperation(ctx, "/mcp/handle")
180
+ h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
181
+ return handleMCPRequest(ctx, mcpSrv)
182
+ })
183
+ resp, err := h(ctx, nil)
184
+ if err != nil {
185
+ return err
186
+ }
187
+ return ctx.JSON(200, resp)
188
+ })
189
+
190
+ return srv
191
+ }
192
+ ```
193
+
194
+ ### Health Check
195
+
196
+ Add health check alongside MCP endpoint:
197
+
198
+ ```go
199
+ route := srv.Route("/")
200
+ route.GET("/health/ready", func(ctx http.Context) error {
201
+ return ctx.JSON(200, map[string]string{"status": "ok"})
202
+ })
203
+ route.GET("/mcp", handleMCP)
204
+ ```
205
+
206
+ ---
207
+
208
+ ## MCP Tool Schema Types
209
+
210
+ ### String Parameter
211
+
212
+ ```go
213
+ mcp.WithString("name",
214
+ mcp.Required(),
215
+ mcp.Description("Description of parameter"),
216
+ mcp.Pattern("^[a-z]+$"), // Optional: regex pattern
217
+ )
218
+ ```
219
+
220
+ ### Number Parameter
221
+
222
+ ```go
223
+ mcp.WithNumber("quantity",
224
+ mcp.Required(),
225
+ mcp.Description("Number of items"),
226
+ mcp.MinNumber(1), // Optional: minimum
227
+ mcp.MaxNumber(100), // Optional: maximum
228
+ )
229
+ ```
230
+
231
+ ### Boolean Parameter
232
+
233
+ ```go
234
+ mcp.WithBoolean("enabled",
235
+ mcp.Description("Enable feature"),
236
+ )
237
+ ```
238
+
239
+ ### Object Parameter
240
+
241
+ ```go
242
+ mcp.WithObject("config",
243
+ mcp.Description("Configuration object"),
244
+ mcp.Properties(map[string]mcp.Property{
245
+ "timeout": mcp.NewNumberProperty(30),
246
+ "retries": mcp.NewNumberProperty(3),
247
+ }),
248
+ )
249
+ ```
250
+
251
+ ---
252
+
253
+ ## Result Types
254
+
255
+ ### Text Result
256
+
257
+ ```go
258
+ mcp.NewToolResultText("Operation completed successfully")
259
+ ```
260
+
261
+ ### Error Result
262
+
263
+ ```go
264
+ mcp.NewToolResultError("Invalid input: user_id required")
265
+ ```
266
+
267
+ ### JSON Result
268
+
269
+ ```go
270
+ mcp.NewToolResultJSON(map[string]interface{}{
271
+ "user_id": "123",
272
+ "name": "John",
273
+ "email": "john@example.com",
274
+ })
275
+ ```
276
+
277
+ ---
278
+
279
+ ## MCP Client Integration
280
+
281
+ AI agents discover and call tools via MCP protocol:
282
+
283
+ 1. **Discovery**: Agent calls `list_tools` to get available tools
284
+ 2. **Schema**: Agent receives tool definitions with parameters
285
+ 3. **Invocation**: Agent calls `call_tool` with arguments
286
+ 4. **Response**: Server returns structured result
287
+
288
+ ### Integration Example
289
+
290
+ Claude Code MCP client configuration:
291
+
292
+ ```json
293
+ {
294
+ "mcpServers": {
295
+ "kratos-mcp": {
296
+ "url": "http://localhost:8000/mcp"
297
+ }
298
+ }
299
+ }
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Future Extensions
305
+
306
+ This reference file can be extended with:
307
+
308
+ - Plugin system integration
309
+ - Custom transport protocols
310
+ - Service mesh patterns
311
+ - GraphQL gateway
312
+ - Event-driven architecture
313
+
314
+ Check official Kratos documentation for updates: https://go-kratos.dev