Skip to content

Commit 4b5715e

Browse files
committed
mcp: panic if AddTool ... add comment
1 parent c8b6bae commit 4b5715e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mcp/server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,17 @@ func (s *Server) RemovePrompts(names ...string) {
117117
}
118118

119119
// AddTool adds a [Tool] to the server, or replaces one with the same name.
120-
// The tool's input schema must be non-nil.
121120
// The Tool argument must not be modified after this call.
121+
//
122+
// The tool's input schema must be non-nil. For a tool that takes no input,
123+
// or one where any input is valid, set [Tool.InputSchema] to the empty schema,
124+
// &jsonschema.Schema{}.
122125
func (s *Server) AddTool(t *Tool, h ToolHandler) {
123-
// TODO(jba): This is a breaking behavior change. Add before v0.2.0?
124126
if t.InputSchema == nil {
127+
// This prevents the tool author from forgetting to write a schema where
128+
// one should be provided. If we papered over this by supplying the empty
129+
// schema, then every input would be validated and the problem wouldn't be
130+
// discovered until runtime, when the LLM sent bad data.
125131
panic(fmt.Sprintf("adding tool %q: nil input schema", t.Name))
126132
}
127133
if err := addToolErr(s, t, h); err != nil {

0 commit comments

Comments
 (0)