import 'dart:async'; import 'dart:convert'; import 'dart:io'; /// Launch this from an MCP client while the configured Cutdex editor is open. Future main() async { final port = int.tryParse(Platform.environment['CUTDEX_MCP_PORT'] ?? ''); final token = Platform.environment['CUTDEX_MCP_TOKEN']; if (port == null || port < 1 || port > 65535 || token == null || token.length < 32 || token.length > 1024 || token.contains('\n') || token.contains('\r')) { stderr.writeln( 'Set CUTDEX_MCP_PORT and CUTDEX_MCP_TOKEN to match the running app.', ); exitCode = 64; return; } Socket? socket; StreamSubscription>? input; try { final connection = await Socket.connect( InternetAddress.loopbackIPv4, port, timeout: const Duration(seconds: 5), ); socket = connection; connection.add(utf8.encode('$token\n')); input = stdin.listen( connection.add, onDone: connection.destroy, onError: (Object _) => connection.destroy(), ); await stdout.addStream(connection); await stdout.flush(); } catch (_) { stderr.writeln('Could not connect to the Cutdex MCP endpoint.'); exitCode = 1; } finally { await input?.cancel(); socket?.destroy(); } }