generateExecuteHandler function
Generates the _execute handler method.
Implementation
String generateExecuteHandler(int codeModeTimeout) {
return '''
FutureOr<CallToolResult> _execute(CallToolRequest request) async {
try {
final code = request.arguments!['code'] as String;
// Validate code length to prevent abuse
if (code.length > $maxCodeModeLength) {
return CallToolResult(
content: [TextContent(text: 'Code exceeds maximum length of $maxCodeModeLength characters.')],
isError: true,
);
}
final result = await _runCodeSandbox(code, $codeModeTimeout);
return CallToolResult(
content: [TextContent(text: result ?? 'null')],
);
} catch (e, st) {
if (_logErrors) {
io.stderr.writeln('[easy_api] _execute: \$e');
io.stderr.writeln(st);
await io.stderr.flush();
}
return CallToolResult(
content: [TextContent(text: 'An error occurred while processing the request.')],
isError: true,
);
}
}''';
}