mcp: polish package doc for v0.3.0

Do a pass through the package doc for v0.3.0.
This commit is contained in:
Rob Findley 2025-08-22 19:52:37 +00:00 • committed by Robert Findley
commit f37e549e25

View file

@ -182,16 +182,17 @@ func (s *Server) AddTool(t *Tool, h ToolHandler) {
}
// ToolFor returns a shallow copy of t and a [ToolHandler] that wraps h.
//
// If the tool's input schema is nil, it is set to the schema inferred from the In
// type parameter, using [jsonschema.For]. The In type parameter must be a map
// or a struct, so that its inferred JSON Schema has type "object".
//
// If the tool's output schema is nil and the Out type parameter is not the empty
// interface, then the output schema is set to the schema inferred from Out, which
// must be a map or a struct.
// For tools that don't return structured output, Out should be 'any'.
// Otherwise, if the tool's output schema is nil the output schema is set to
// the schema inferred from Out, which must be a map or a struct.
//
// Most users will call [AddTool]. Use [ToolFor] if you wish to modify the tool's
// schemas or wrap the ToolHandler before calling [Server.AddTool].
// Most users will call [AddTool]. Use [ToolFor] if you wish to modify the
// tool's schemas or wrap the ToolHandler before calling [Server.AddTool].
func ToolFor[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHandler) {
tt, hh, err := toolForErr(t, h)
if err != nil {
@ -317,7 +318,16 @@ func setSchema[T any](sfield **jsonschema.Schema, rfield **jsonschema.Resolved)
return zero, err
}
// AddTool adds a tool and handler to the server.
// AddTool adds a tool and typed tool handler to the server.
//
// If the tool's input schema is nil, it is set to the schema inferred from the
// In type parameter, using [jsonschema.For]. The In type parameter must be a
// map or a struct, so that its inferred JSON Schema has type "object".
//
// For tools that don't return structured output, Out should be 'any'.
// Otherwise, if the tool's output schema is nil the output schema is set to
// the schema inferred from Out, which must be a map or a struct.
//
// It is a convenience for s.AddTool(ToolFor(t, h)).
func AddTool[In, Out any](s *Server, t *Tool, h ToolHandlerFor[In, Out]) {
s.AddTool(ToolFor(t, h))