RegisterFunc registers the tool with the server using the provided dependencies. Icons are automatically applied from the toolset metadata if not already set. A shallow copy of the tool is made to avoid mutating the original ServerTool. Panics if the tool has no handler - all tools should have handl
(s *mcp.Server, deps any)
| 109 | // A shallow copy of the tool is made to avoid mutating the original ServerTool. |
| 110 | // Panics if the tool has no handler - all tools should have handlers. |
| 111 | func (st *ServerTool) RegisterFunc(s *mcp.Server, deps any) { |
| 112 | handler := st.Handler(deps) // This will panic if HandlerFunc is nil |
| 113 | // Make a shallow copy of the tool to avoid mutating the original |
| 114 | toolCopy := st.Tool |
| 115 | // Apply icons from toolset metadata if tool doesn't have icons set |
| 116 | if len(toolCopy.Icons) == 0 { |
| 117 | toolCopy.Icons = st.Toolset.Icons() |
| 118 | } |
| 119 | s.AddTool(&toolCopy, handler) |
| 120 | } |
| 121 | |
| 122 | // NewServerToolWithContextHandler creates a ServerTool with a handler that receives deps via context. |
| 123 | // This is the preferred approach for tools because it doesn't create closures at registration time, |
no test coverage detected