精简项目:只保留 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:
@@ -19,18 +19,16 @@ func NewRegistry() *Registry {
|
||||
return &Registry{tools: make(map[string]tool.Tool)}
|
||||
}
|
||||
|
||||
// Register 注册一个工具。如果工具名重复则报错。
|
||||
func (r *Registry) Register(t tool.Tool) error {
|
||||
name := t.Name()
|
||||
if _, exists := r.tools[name]; exists {
|
||||
return fmt.Errorf("tool %q already registered", name)
|
||||
}
|
||||
r.tools[name] = t
|
||||
slog.Info("tool registered", "name", name, "desc", t.Description())
|
||||
slog.Info("tool registered", "name", name)
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitializeAll 调用所有工具的 Initialize,任一失败则终止。
|
||||
func (r *Registry) InitializeAll(ctx context.Context) error {
|
||||
for name, t := range r.tools {
|
||||
slog.Info("initializing tool", "name", name)
|
||||
@@ -41,18 +39,15 @@ func (r *Registry) InitializeAll(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterAll 将所有工具注册到 MCP Server。
|
||||
func (r *Registry) RegisterAll(mcpServer *server.MCPServer) error {
|
||||
for name, t := range r.tools {
|
||||
if err := t.Register(mcpServer); err != nil {
|
||||
return fmt.Errorf("register tool %q: %w", name, err)
|
||||
}
|
||||
slog.Info("tool handlers registered", "name", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ShutdownAll 调用所有工具的 Shutdown,收集所有错误。
|
||||
func (r *Registry) ShutdownAll(ctx context.Context) []error {
|
||||
var errs []error
|
||||
for name, t := range r.tools {
|
||||
@@ -64,7 +59,6 @@ func (r *Registry) ShutdownAll(ctx context.Context) []error {
|
||||
return errs
|
||||
}
|
||||
|
||||
// HealthCheckAll 检查所有工具的连通性,用于 system health 工具。
|
||||
func (r *Registry) HealthCheckAll(ctx context.Context) map[string]error {
|
||||
result := make(map[string]error, len(r.tools))
|
||||
for name, t := range r.tools {
|
||||
@@ -72,12 +66,3 @@ func (r *Registry) HealthCheckAll(ctx context.Context) map[string]error {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// List 返回所有已注册工具的名称。
|
||||
func (r *Registry) List() []string {
|
||||
names := make([]string, 0, len(r.tools))
|
||||
for name := range r.tools {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user