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 env = params['environment'] as String? ?? 'development';
  final section = params['section'] as String?;

  final project = ServerPodLocator.getProject();

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

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

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

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

  // Return full config or specific section
  if (section != null && yaml.containsKey(section)) {
    return {
      'environment': env,
      'section': section,
      'config': _yamlToDynamic(yaml[section]),
    };
  }

  return {
    'environment': env,
    'file': configFile.path,
    'config': _yamlToDynamic(yaml),
  };
}