@@ -150,6 +150,8 @@ func (s *Server) RemovePrompts(names ...string) {
150150// When the handler is invoked as part of a CallTool request, req.Params.Arguments
151151// will be a json.RawMessage. Unmarshaling the arguments and validating them against the
152152// input schema are the handler author's responsibility.
153+ //
154+ // Most users will prefer the top-level function [AddTool].
153155func (s * Server ) AddTool (t * Tool , h ToolHandler ) {
154156 if t .InputSchema == nil {
155157 // This prevents the tool author from forgetting to write a schema where
@@ -167,15 +169,15 @@ func (s *Server) AddTool(t *Tool, h ToolHandler) {
167169 func () bool { s .tools .add (st ); return true })
168170}
169171
170- // ToolFor returns a shallow copy of t and a [ToolHandler] that wraps h.
172+ // toolFor returns a shallow copy of t and a [ToolHandler] that wraps h.
171173// If the tool's input schema is nil, it is set to the schema inferred from the In
172174// type parameter, using [jsonschema.For].
173175// If the tool's output schema is nil and the Out type parameter is not the empty
174176// interface, then the output schema is set to the schema inferred from Out.
175177//
176- // Most users will call [AddTool]. Use [ToolFor ] if you wish to wrap the ToolHandler
178+ // Most users will call [AddTool]. Use [toolFor ] if you wish to wrap the ToolHandler
177179// before calling [Server.AddTool].
178- func ToolFor [In , Out any ](t * Tool , h ToolHandlerFor [In , Out ]) (* Tool , ToolHandler ) {
180+ func toolFor [In , Out any ](t * Tool , h ToolHandlerFor [In , Out ]) (* Tool , ToolHandler ) {
179181 tt , hh , err := toolForErr (t , h )
180182 if err != nil {
181183 panic (fmt .Sprintf ("ToolFor: tool %q: %v" , t .Name , err ))
@@ -250,9 +252,15 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
250252 return & tt , th , nil
251253}
252254
253- // AddTool is a convenience for s.AddTool(ToolFor(t, h)).
255+ // AddTool adds a tool and handler to the server.
256+ //
257+ // A shallow copy of the tool is made first.
258+ // If the tool's input schema is nil, the copy's input schema is set to the schema
259+ // inferred from the In type parameter, using [jsonschema.For].
260+ // If the tool's output schema is nil and the Out type parameter is not the empty
261+ // interface, then the copy's output schema is set to the schema inferred from Out.
254262func AddTool [In , Out any ](s * Server , t * Tool , h ToolHandlerFor [In , Out ]) {
255- s .AddTool (ToolFor (t , h ))
263+ s .AddTool (toolFor (t , h ))
256264}
257265
258266// RemoveTools removes the tools with the given names.
0 commit comments