Skip to content

Commit 62db914

Browse files
authored
mcp: export ToolFor (#347)
This is needed so clients can modify tool schemas, and not merely to wrap ToolHandlers. (A consequence of returning a copy of Tool instead of modifying it.)
1 parent dd8e3af commit 62db914

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

mcp/requests.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
package mcp
88

9-
// TODO: expand the aliases
109
type (
1110
CallToolRequest = ServerRequest[*CallToolParams]
1211
CompleteRequest = ServerRequest[*CompleteParams]

mcp/server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ func (s *Server) AddTool(t *Tool, h ToolHandler) {
171171
func() bool { s.tools.add(st); return true })
172172
}
173173

174-
// toolFor returns a shallow copy of t and a [ToolHandler] that wraps h.
174+
// ToolFor returns a shallow copy of t and a [ToolHandler] that wraps h.
175175
// If the tool's input schema is nil, it is set to the schema inferred from the In
176176
// type parameter, using [jsonschema.For].
177177
// If the tool's output schema is nil and the Out type parameter is not the empty
178178
// interface, then the output schema is set to the schema inferred from Out.
179179
//
180-
// Most users will call [AddTool]. Use [toolFor] if you wish to wrap the ToolHandler
181-
// before calling [Server.AddTool].
182-
func toolFor[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHandler) {
180+
// Most users will call [AddTool]. Use [ToolFor] if you wish to modify the tool's
181+
// schemas or wrap the ToolHandler before calling [Server.AddTool].
182+
func ToolFor[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHandler) {
183183
tt, hh, err := toolForErr(t, h)
184184
if err != nil {
185185
panic(fmt.Sprintf("ToolFor: tool %q: %v", t.Name, err))
@@ -303,7 +303,7 @@ func setSchema[T any](sfield **jsonschema.Schema, rfield **jsonschema.Resolved)
303303
// If the tool's output schema is nil and the Out type parameter is not the empty
304304
// interface, then the copy's output schema is set to the schema inferred from Out.
305305
func AddTool[In, Out any](s *Server, t *Tool, h ToolHandlerFor[In, Out]) {
306-
s.AddTool(toolFor(t, h))
306+
s.AddTool(ToolFor(t, h))
307307
}
308308

309309
// RemoveTools removes the tools with the given names.

0 commit comments

Comments
 (0)