executeImpl method

  1. @override
Future executeImpl(
  1. Map<String, dynamic> params
)
override

Implement the actual tool logic

params are the validated parameters (never null here) Returns the result data to send in the response

Implementation

@override
Future<dynamic> executeImpl(Map<String, dynamic> params) async {
  final service = params['service'] as String;
  final environment = params['environment'] as String? ?? 'development';

  final project = ServerPodLocator.getProject();
  if (project == null || !project.isValid) {
    return {'error': 'Not a valid ServerPod project'};
  }

  final configFile = project.getConfigFile(environment);
  if (configFile == null) {
    return {
      'error': 'Config file not found',
      'environment': environment,
    };
  }

  try {
    final content = await configFile.readAsString();
    final yaml = loadYaml(content) as YamlMap?;

    if (yaml == null) {
      return {
        'error': 'Failed to parse config',
        'file': configFile.path,
      };
    }

    final serviceConfig = yaml[service];
    if (serviceConfig == null) {
      return {
        'error': 'Service not found in config',
        'service': service,
        'availableServices': yaml.keys.toList(),
      };
    }

    return {
      'service': service,
      'environment': environment,
      'config': _yamlToDynamic(serviceConfig),
      'file': configFile.path,
    };
  } catch (e) {
    return {
      'error': 'Failed to read config',
      'message': e.toString(),
    };
  }
}