精简项目:只保留 docker_logs + health + info 三个工具
- 移除 database/middleware 等复杂模块,先聚焦核心功能 - docker_logs:封装 docker logs --tail N <container> - 修复 go.mod 版本为 1.24 匹配 Docker 构建镜像 - Dockerfile 改用 alpine + docker-cli,避免 scratch 无 shell 问题 - docker-compose.yml 简化为单服务定义 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+18
-22
@@ -13,35 +13,33 @@ import (
|
||||
|
||||
var StartTime = time.Now()
|
||||
|
||||
// SystemTool 提供 health 和 info 两个基础工具。
|
||||
type SystemTool struct {
|
||||
version string
|
||||
registry HealthChecker
|
||||
}
|
||||
|
||||
// HealthChecker 用于 system 工具检查其他工具的连通性。
|
||||
type HealthChecker interface {
|
||||
HealthCheckAll(ctx context.Context) map[string]error
|
||||
}
|
||||
|
||||
type SystemTool struct {
|
||||
version string
|
||||
registry HealthChecker
|
||||
}
|
||||
|
||||
func NewSystemTool(version string, reg HealthChecker) *SystemTool {
|
||||
return &SystemTool{version: version, registry: reg}
|
||||
}
|
||||
|
||||
func (s *SystemTool) Name() string { return "system" }
|
||||
func (s *SystemTool) Description() string { return "系统健康检查和信息查询" }
|
||||
|
||||
func (s *SystemTool) Description() string { return "服务健康检查和信息查询" }
|
||||
func (s *SystemTool) Initialize(_ context.Context) error { return nil }
|
||||
func (s *SystemTool) Shutdown(_ context.Context) error { return nil }
|
||||
func (s *SystemTool) HealthCheck(_ context.Context) error { return nil }
|
||||
|
||||
func (s *SystemTool) Register(mcpServer *server.MCPServer) error {
|
||||
mcpServer.AddTool(mcp.NewTool("health",
|
||||
mcp.WithDescription("服务健康检查:运行时间、内存使用、连接状态"),
|
||||
mcp.WithDescription("服务健康检查:运行时间、内存、连接状态"),
|
||||
), s.handleHealth)
|
||||
|
||||
mcpServer.AddTool(mcp.NewTool("info",
|
||||
mcp.WithDescription("服务信息:版本号、已配置的数据库、已加载的工具"),
|
||||
mcp.WithDescription("服务信息:版本号、Go 版本、已加载工具"),
|
||||
), s.handleInfo)
|
||||
|
||||
return nil
|
||||
@@ -52,11 +50,10 @@ func (s *SystemTool) handleHealth(ctx context.Context, _ mcp.CallToolRequest) (*
|
||||
runtime.ReadMemStats(&m)
|
||||
|
||||
result := map[string]any{
|
||||
"status": "ok",
|
||||
"uptime": time.Since(StartTime).String(),
|
||||
"goroutines": runtime.NumGoroutine(),
|
||||
"heap_mb": float64(m.HeapAlloc) / 1024 / 1024,
|
||||
"gc_cycles": m.NumGC,
|
||||
"status": "ok",
|
||||
"uptime": time.Since(StartTime).String(),
|
||||
"goroutines": runtime.NumGoroutine(),
|
||||
"heap_mb": float64(m.HeapAlloc) / 1024 / 1024,
|
||||
}
|
||||
|
||||
if s.registry != nil {
|
||||
@@ -69,14 +66,13 @@ func (s *SystemTool) handleHealth(ctx context.Context, _ mcp.CallToolRequest) (*
|
||||
|
||||
func (s *SystemTool) handleInfo(ctx context.Context, _ mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||
result := map[string]any{
|
||||
"version": s.version,
|
||||
"go_version": runtime.Version(),
|
||||
"os": runtime.GOOS,
|
||||
"arch": runtime.GOARCH,
|
||||
"cpus": runtime.NumCPU(),
|
||||
"start_time": StartTime.Format(time.RFC3339),
|
||||
"version": s.version,
|
||||
"go_version": runtime.Version(),
|
||||
"os": runtime.GOOS,
|
||||
"arch": runtime.GOARCH,
|
||||
"cpus": runtime.NumCPU(),
|
||||
"start_time": StartTime.Format(time.RFC3339),
|
||||
}
|
||||
|
||||
data, _ := json.MarshalIndent(result, "", " ")
|
||||
return mcp.NewToolResultText(fmt.Sprintf("```json\n%s\n```", string(data))), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user