writeMcpSessionFile function

void writeMcpSessionFile(
  1. File file, {
  2. required int port,
  3. required String token,
})

Where an application's own running LoopbackMcpServer can be found, written beside the application's existing session state.

Takes the directory as a plain path rather than resolving a per-platform application-support directory, because this package stays plain Dart and the application wiring a server in already has that directory. Written after the socket is bound, since port and token both come from the running server — a file naming a port nothing is listening on yet would race whatever reads it.

Implementation

void writeMcpSessionFile(
  File file, {
  required int port,
  required String token,
}) {
  file.parent.createSync(recursive: true);
  file.writeAsStringSync(
    json.encode(<String, Object?>{'port': port, 'token': token}),
  );
}