registerTool

Result<RegisteredTool, String> registerTool(

  1. String name,
  2. ToolConfig config,
  3. ToolCallback callback
)

Register a tool.

Returns Success with RegisteredTool or Error with message.

Implementation

Result<RegisteredTool, String> registerTool(
  String name,
  ToolConfig config,
  ToolCallback callback,
) {
  try {
    final jsConfig = _toolConfigToJs(config);
    final jsCallback = _wrapToolCallback(callback);

final registerToolFn = _mcpServer['registerTool'] as JSFunction; final jsResult = registerToolFn.callAsFunction( _mcpServer, name.toJS, jsConfig, jsCallback, ) as JSObject;

return Success(_jsToRegisteredTool(name, jsResult)); } catch (e) { return Error('Failed to register tool "$name": $e'); } }