mcp: panic if AddTool method is given a nil InputSchema (#157)
The spec requires an input schema for every tool.
This commit is contained in:
parent
94b88a26e0
commit
8dd9a819bb
1 changed files with 14 additions and 8 deletions
|
|
@ -12,7 +12,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"iter"
|
||||
"log"
|
||||
"maps"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
|
|
@ -132,13 +131,18 @@ func (s *Server) RemovePrompts(names ...string) {
|
|||
}
|
||||
|
||||
// AddTool adds a [Tool] to the server, or replaces one with the same name.
|
||||
// The tool's input schema must be non-nil.
|
||||
// The Tool argument must not be modified after this call.
|
||||
//
|
||||
// The tool's input schema must be non-nil. For a tool that takes no input,
|
||||
// or one where any input is valid, set [Tool.InputSchema] to the empty schema,
|
||||
// &jsonschema.Schema{}.
|
||||
func (s *Server) AddTool(t *Tool, h ToolHandler) {
|
||||
// TODO(jba): This is a breaking behavior change. Add before v0.2.0?
|
||||
if t.InputSchema == nil {
|
||||
log.Printf("mcp: tool %q has a nil input schema. This will panic in a future release.", t.Name)
|
||||
// panic(fmt.Sprintf("adding tool %q: nil input schema", t.Name))
|
||||
// This prevents the tool author from forgetting to write a schema where
|
||||
// one should be provided. If we papered over this by supplying the empty
|
||||
// schema, then every input would be validated and the problem wouldn't be
|
||||
// discovered until runtime, when the LLM sent bad data.
|
||||
panic(fmt.Sprintf("adding tool %q: nil input schema", t.Name))
|
||||
}
|
||||
if err := addToolErr(s, t, h); err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue