feat(mcp): streamable HTTP transport with session, init, and dispatch
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>
This commit is contained in:
42
internal/registry/registry.go
Normal file
42
internal/registry/registry.go
Normal file
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user