fix(mcp): map tool-not-found to CodeNotFound via registry sentinel

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mathias Bergqvist
2026-05-04 20:59:15 +02:00
parent 93c5a6934b
commit c6c328e517
3 changed files with 33 additions and 4 deletions

View File

@@ -4,8 +4,11 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
)
var ErrToolNotFound = errors.New("tool not found")
type ToolDescriptor struct {
Name string `json:"name"`
Description string `json:"description"`
@@ -36,7 +39,7 @@ func (r *Registry) Tools() []ToolDescriptor {
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 nil, fmt.Errorf("tool %q: %w", name, ErrToolNotFound)
}
return t.Call(ctx, args)
}