Skip to content
Open
63 changes: 63 additions & 0 deletions sites/docs/src/content/ai/mcp-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,69 @@ is now a single request.

[`package:fl_chart`]: {{site.pub-pkg}}/fl_chart

### Interact with a running app

You can use the Dart and Flutter MCP server to drive a running
Flutter app from your AI assistant—take screenshots, tap buttons,
enter text, scroll, and hot reload.

First, add the `flutter_driver` package:

```console
$ flutter pub add "flutter_driver:{sdk: flutter}"
```

On mobile and desktop, gate `enableFlutterDriverExtension()` behind a
`--dart-define` flag in your app's `main()` so it stays out of
production builds:

```dart
import 'package:flutter_driver/driver_extension.dart';
Comment thread
Ortes marked this conversation as resolved.

void main() {
if (const bool.fromEnvironment('ENABLE_FLUTTER_DRIVER')) {
enableFlutterDriverExtension();
}
runApp(const MyApp());
}
```

Launch your app with the flag turned on:

```console
$ flutter run -d <device-id> --dart-define=ENABLE_FLUTTER_DRIVER=true
```

:::warning
Enabling the Flutter Driver extension disables real keyboard input—typing
is dropped and the on-screen keyboard might not appear. To type manually,
use `enableFlutterDriverExtension(enableTextEntryEmulation: false)`, but
then the agent's `enterText` command stops working.
:::

Then ask your assistant to connect:

> Connect to my running Flutter app, take a screenshot, then tap "Sign In".

The agent uses the `dtd` tool to discover the app and
`flutter_driver_command` to drive its UI.

:::note
**Web**: the `flutter_driver` extension isn't supported on web builds, so
finder-based commands like screenshots and taps aren't available there.
Pair the Dart MCP server with a browser-driving MCP for those. Everything
that flows through DTD—widget tree, runtime errors, and hot reload—still
works in a normal `flutter run` web debug session. Prefer
`flutter run -d web-server` so the browser the agent drives is the one DTD
is connected to—with `-d chrome`, only the window Flutter spawned receives
hot reload patches.

See the [setup guide][flutter-driver-guide] for the web-safe conditional
import, the `-d web-server` versus `-d chrome` modes, and common pitfalls.
:::

[flutter-driver-guide]: https://github.com/dart-lang/ai/blob/main/pkgs/dart_mcp_server/README.md#connect-to-a-running-flutter-app
Comment thread
Ortes marked this conversation as resolved.

## Provide feedback

If you encounter any issues or have feedback about the
Expand Down
Loading