Skip to content

Commit 59db320

Browse files
authored
Add the Flutter launcher tools (#292)
1 parent e285b26 commit 59db320

File tree

7 files changed

+841
-16
lines changed

7 files changed

+841
-16
lines changed

pkgs/dart_mcp_server/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* Stop reporting non-zero exit codes from command line tools as tool errors.
1717
* Add descriptions for pub tools, add support for `pub deps` and `pub outdated`.
1818
* Fix a bug in hot_reload ([#290](https://github.com/dart-lang/ai/issues/290)).
19+
* Add the `list_devices`, `launch_app`, `get_app_logs`, and `list_running_apps`
20+
tools for running Flutter apps.
1921

2022
# 0.1.0 (Dart SDK 3.9.0)
2123

pkgs/dart_mcp_server/README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,30 @@ For more information, see the official VS Code documentation for
135135

136136
| Tool Name | Title | Description |
137137
| --- | --- | --- |
138+
| `add_roots` | Add roots | Adds one or more project roots. Tools are only allowed to run under these roots, so you must call this function before passing any roots to any other tools. |
139+
| `analyze_files` | Analyze projects | Analyzes specific paths, or the entire project, for errors. |
138140
| `connect_dart_tooling_daemon` | Connect to DTD | Connects to the Dart Tooling Daemon. You should get the uri either from available tools or the user, do not just make up a random URI to pass. When asking the user for the uri, you should suggest the "Copy DTD Uri to clipboard" action. When reconnecting after losing a connection, always request a new uri first. |
141+
| `create_project` | Create project | Creates a new Dart or Flutter project. |
142+
| `dart_fix` | Dart fix | Runs `dart fix --apply` for the given project roots. |
143+
| `dart_format` | Dart format | Runs `dart format .` for the given project roots. |
144+
| `flutter_driver` | Flutter Driver | Run a flutter driver command |
145+
| `get_active_location` | Get Active Editor Location | Retrieves the current active location (e.g., cursor position) in the connected editor. Requires "connect_dart_tooling_daemon" to be successfully called first. |
146+
| `get_app_logs` | | Returns the collected logs for a given flutter run process id. Can only retrieve logs started by the launch_app tool. |
139147
| `get_runtime_errors` | Get runtime errors | Retrieves the most recent runtime errors that have occurred in the active Dart or Flutter application. Requires "connect_dart_tooling_daemon" to be successfully called first. |
140-
| `hot_reload` | Hot reload | Performs a hot reload of the active Flutter application. This is to apply the latest code changes to the running application. Requires "connect_dart_tooling_daemon" to be successfully called first. |
141-
| `get_widget_tree` | Get widget tree | Retrieves the widget tree from the active Flutter application. Requires "connect_dart_tooling_daemon" to be successfully called first. |
142148
| `get_selected_widget` | Get selected widget | Retrieves the selected widget from the active Flutter application. Requires "connect_dart_tooling_daemon" to be successfully called first. |
143-
| `set_widget_selection_mode` | Set Widget Selection Mode | Enables or disables widget selection mode in the active Flutter application. Requires "connect_dart_tooling_daemon" to be successfully called first. This is not necessary when using flutter driver, only use it when you want the user to select a widget. |
144-
| `get_active_location` | Get Active Editor Location | Retrieves the current active location (e.g., cursor position) in the connected editor. Requires "connect_dart_tooling_daemon" to be successfully called first. |
145-
| `flutter_driver` | Flutter Driver | Run a flutter driver command |
149+
| `get_widget_tree` | Get widget tree | Retrieves the widget tree from the active Flutter application. Requires "connect_dart_tooling_daemon" to be successfully called first. |
150+
| `hot_reload` | Hot reload | Performs a hot reload of the active Flutter application. This is to apply the latest code changes to the running application. Requires "connect_dart_tooling_daemon" to be successfully called first. |
151+
| `hover` | Hover information | Get hover information at a given cursor position in a file. This can include documentation, type information, etc for the text at that position. |
152+
| `launch_app` | | Launches a Flutter application and returns its DTD URI. |
153+
| `list_devices` | | Lists available Flutter devices. |
154+
| `list_running_apps` | | Returns the list of running app process IDs and associated DTD URIs for apps started by the launch_app tool. |
155+
| `pub` | pub | Runs a pub command for the given project roots, like `dart pub get` or `flutter pub add`. |
146156
| `pub_dev_search` | pub.dev search | Searches pub.dev for packages relevant to a given search query. The response will describe each result with its download count, package description, topics, license, and publisher. |
147157
| `remove_roots` | Remove roots | Removes one or more project roots previously added via the add_roots tool. |
148-
| `add_roots` | Add roots | Adds one or more project roots. Tools are only allowed to run under these roots, so you must call this function before passing any roots to any other tools. |
149-
| `dart_fix` | Dart fix | Runs `dart fix --apply` for the given project roots. |
150-
| `dart_format` | Dart format | Runs `dart format .` for the given project roots. |
151-
| `run_tests` | Run tests | Run Dart or Flutter tests with an agent centric UX. ALWAYS use instead of `dart test` or `flutter test` shell commands. |
152-
| `create_project` | Create project | Creates a new Dart or Flutter project. |
153-
| `pub` | pub | Runs a pub command for the given project roots, like `dart pub get` or `flutter pub add`. |
154-
| `analyze_files` | Analyze projects | Analyzes specific paths, or the entire project, for errors. |
155158
| `resolve_workspace_symbol` | Project search | Look up a symbol or symbols in all workspaces by name. Can be used to validate that a symbol exists or discover small spelling mistakes, since the search is fuzzy. |
159+
| `run_tests` | Run tests | Run Dart or Flutter tests with an agent centric UX. ALWAYS use instead of `dart test` or `flutter test` shell commands. |
160+
| `set_widget_selection_mode` | Set Widget Selection Mode | Enables or disables widget selection mode in the active Flutter application. Requires "connect_dart_tooling_daemon" to be successfully called first. This is not necessary when using flutter driver, only use it when you want the user to select a widget. |
156161
| `signature_help` | Signature help | Get signature help for an API being used at a given cursor position in a file. |
157-
| `hover` | Hover information | Get hover information at a given cursor position in a file. This can include documentation, type information, etc for the text at that position. |
162+
| `stop_app` | | Kills a running Flutter process started by the launch_app tool. |
158163

159164
<!-- generated -->

pkgs/dart_mcp_server/lib/src/mixins/analyzer.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import '../utils/analytics.dart';
1717
import '../utils/cli_utils.dart';
1818
import '../utils/constants.dart';
1919
import '../utils/file_system.dart';
20+
import '../utils/process_manager.dart';
2021
import '../utils/sdk.dart';
2122

2223
/// Mix this in to any MCPServer to add support for analyzing Dart projects.
@@ -25,7 +26,7 @@ import '../utils/sdk.dart';
2526
/// mixins applied.
2627
base mixin DartAnalyzerSupport
2728
on ToolsSupport, LoggingSupport, RootsTrackingSupport, FileSystemSupport
28-
implements SdkSupport {
29+
implements SdkSupport, ProcessManagerSupport {
2930
/// The LSP server connection for the analysis server.
3031
Peer? _lspConnection;
3132

@@ -94,7 +95,8 @@ base mixin DartAnalyzerSupport
9495
///
9596
/// On failure, returns a reason for the failure.
9697
Future<String?> _initializeAnalyzerLspServer() async {
97-
final lspServer = await Process.start(sdk.dartExecutablePath, [
98+
final lspServer = await processManager.start([
99+
sdk.dartExecutablePath,
98100
'language-server',
99101
// Required even though it is documented as the default.
100102
// https://github.com/dart-lang/sdk/issues/60574

0 commit comments

Comments
 (0)