package registry import ( "context" "encoding/json" "errors" ) type ToolDescriptor struct { Name string `json:"name"` Description string `json:"description"` InputSchema json.RawMessage `json:"inputSchema"` } type Tool interface { Descriptor() ToolDescriptor Call(ctx context.Context, args json.RawMessage) (json.RawMessage, error) } type Registry struct { tools map[string]Tool } func New() *Registry { return &Registry{tools: map[string]Tool{}} } func (r *Registry) Register(t Tool) { r.tools[t.Descriptor().Name] = t } func (r *Registry) Tools() []ToolDescriptor { out := make([]ToolDescriptor, 0, len(r.tools)) for _, t := range r.tools { out = append(out, t.Descriptor()) } return out } func (r *Registry) Dispatch(ctx context.Context, name string, args json.RawMessage) (json.RawMessage, error) { t, ok := r.tools[name] if !ok { return nil, errors.New("tool not found: " + name) } return t.Call(ctx, args) }