Implements the Streamable HTTP transport: POST routing handles initialize (issues session ID), tools/list, tools/call, and unknown methods; GET SSE emits a keepalive comment then blocks on context cancellation. A minimal registry stub is introduced so the server compiles and tools/list returns an empty array until Phase 6+ registers real tools. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
968 B
Go
43 lines
968 B
Go
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)
|
|
}
|