discoverRunningApps function

Future<CallToolResult> discoverRunningApps(
  1. VmBridge bridge,
  2. Map<String, dynamic> args
)

Lists running Flutter/Dart apps and their VM Service URIs.

Uses the Dart Tooling Daemon, so the agent never has to read or copy the URI that flutter run prints to its console.

Implementation

Future<CallToolResult> discoverRunningApps(
  VmBridge bridge,
  Map<String, dynamic> args,
) async {
  try {
    final workspace = args['workspaceFilter'] as String?;

    final apps = await VmServiceDiscovery.discoverApps(
      workspaceFilter: workspace,
    );

    return CallToolResult(
      content: [TextContent(text: VmServiceDiscovery.describe(apps))],
    );
  } on Object catch (e) {
    return CallToolResult(
      content: [
        TextContent(
          text:
              'Discovery failed: $e\n\n'
              'Falling back: pass the URI from the `flutter run` console '
              '(the "This app is linked to the debug service: ws://..." line) '
              'to connect_to_app.',
        ),
      ],
      isError: true,
    );
  }
}