Files
cutdex/tool/mcp_stdio.dart
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

48 lines
1.3 KiB
Dart

import 'dart:async';
import 'dart:convert';
import 'dart:io';
/// Launch this from an MCP client while the configured Cutdex editor is open.
Future<void> 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<List<int>>? 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();
}
}