Skip to content

Commit d282330

Browse files
committed
mcp: panic if AddTool ... add comment
1 parent 1c456ea commit d282330

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
@@ -131,11 +131,17 @@ func (s *Server) RemovePrompts(names ...string) {
131131
}
132132

133133
// AddTool adds a [Tool] to the server, or replaces one with the same name.
134-
// The tool's input schema must be non-nil.
135134
// The Tool argument must not be modified after this call.
135+
//
136+
// The tool's input schema must be non-nil. For a tool that takes no input,
137+
// or one where any input is valid, set [Tool.InputSchema] to the empty schema,
138+
// &jsonschema.Schema{}.
136139
func (s *Server) AddTool(t *Tool, h ToolHandler) {
137-
// TODO(jba): This is a breaking behavior change. Add before v0.2.0?
138140
if t.InputSchema == nil {
141+
// This prevents the tool author from forgetting to write a schema where
142+
// one should be provided. If we papered over this by supplying the empty
143+
// schema, then every input would be validated and the problem wouldn't be
144+
// discovered until runtime, when the LLM sent bad data.
139145
panic(fmt.Sprintf("adding tool %q: nil input schema", t.Name))
140146
}
141147
if err := addToolErr(s, t, h); err != nil {

0 commit comments

Comments
 (0)