callTool method

Future<CallToolResult> callTool(
  1. CallToolRequest request
)

Invokes a Tool returned from the ListToolsResult.

Implementation

Future<CallToolResult> callTool(CallToolRequest request) async {
  try {
    return await sendRequest(CallToolRequest.methodName, request);
  } on RpcException catch (e) {
    // If we are set up to try and auto handle url elicitation and we get
    // an error that the url elicitation is required, we will try and handle
    // it and then retry the request a single time.
    if (_elicitationUrlSupport?.autoHandleUrlElicitationRequired == true &&
        e.code == McpErrorCodes.urlElicitationRequired) {
      final elicitRequest = e.data as ElicitRequest;
      final elicitationComplete =
          elicitRequest.onElicitationComplete(this).firstOrNull;
      final elicitResult = await _elicitationUrlSupport!.handleElicitation(
        elicitRequest,
        this,
      );
      if (elicitResult.action == ElicitationAction.accept) {
        await elicitationComplete;
        return await sendRequest(CallToolRequest.methodName, request);
      }
    }
    rethrow;
  }
}