-
Notifications
You must be signed in to change notification settings - Fork 166
Add flutter-app-runtime skill for runtime interaction and proactive hot reload #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -431,4 +431,43 @@ | |
| - https://docs.flutter.dev/cookbook/networking/send-data | ||
| - https://docs.flutter.dev/cookbook/networking/update-data | ||
| - https://docs.flutter.dev/data-and-backend/serialization | ||
| - https://docs.flutter.dev/data-and-backend/serialization/json | ||
| - https://docs.flutter.dev/data-and-backend/serialization/json | ||
| - name: flutter-app-runtime | ||
| description: Interacts with running Dart and Flutter applications via the | ||
| Dart MCP server to enable hot reload, hot restart, widget inspection, and | ||
| error fetching. Use when modifying UI widgets, debugging errors, inspecting | ||
| running apps, or proactively hot reloading whenever changes are made to | ||
| Flutter UI widgets. | ||
|
|
||
|
Comment on lines
+435
to
+441
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - name: flutter-app-runtime
description: Interacts with running Dart and Flutter applications via the
Dart MCP server to enable hot reload, hot restart, widget inspection, and
error fetching. Use when modifying UI widgets, debugging errors, inspecting
running apps, or proactively hot reloading whenever changes are made to
Flutter UI widgets.
examplePrompt: "Proactively hot reload the app when making UI changes"
instructions: | |
||
| instructions: | | ||
| This Skill enables zero-configuration interaction with running Dart and Flutter | ||
| applications. The Dart MCP server manages the underlying connection to the | ||
| application's VM service, allowing the agent to focus on high-level runtime | ||
| operations. | ||
|
|
||
| Pre-requisite: | ||
| The Dart and Flutter MCP server must be configured and active. | ||
|
|
||
| Core capabilities include: | ||
| - Hot Reload: Proactively trigger hot reloads to immediately push visual feedback for UI widget updates and simple logic changes. | ||
| - Hot Restart: Reset the app state for deep non-widget changes or clean resets. | ||
| - Widget Inspection: Query tree structures and identify UI hierarchy names. | ||
| - Error Fetching: Retrieve live runtime exceptions and trace pointers live. | ||
|
|
||
| Decision workflow: | ||
| 1. Identify Targets: Use `list_running_apps` or the `dtd` tool to discover and connect | ||
| to running application instances in the current workspace. If no app is running, | ||
| inform the user but do not let it stop you from completing code edits. | ||
| 2. Verify Connection: Use `dtd` or `vm_service` to ensure the required `appUri` | ||
| is active and matches the project's workspace. Re-sync via `dtd` if necessary. | ||
| 3. Proactive Hot Reload & Ops: Whenever edits or changes are made to Flutter UI widgets | ||
| or Dart code, proactively trigger `hot_reload` across all targeted instances immediately | ||
| to maintain visual consistency. For diagnosis, query live logs with `get_runtime_errors` | ||
| first or inspect UI with `widget_inspector`. Use `hot_restart` to reset state across | ||
| all devices when debugging foundational logic. | ||
|
|
||
| Sample scenarios include proactive hot reloading after widget modifications, | ||
| autonomous bug fixing by fetching exceptions, inspecting and modifying UI using | ||
| the widget inspector, and multi-device synchronization for global changes like themes. | ||
| resources: | ||
| - https://docs.flutter.dev/ai/mcp-server | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| --- | ||
| name: flutter-app-runtime | ||
| description: Interacts with running Dart and Flutter applications via the Dart MCP server to enable hot reload, hot restart, widget inspection, and error fetching. Use when modifying UI widgets, debugging errors, inspecting running apps, or proactively hot reloading whenever changes are made to Flutter UI widgets. | ||
| metadata: | ||
| model: models/gemini-3.1-pro-preview | ||
| last_modified: Fri, 07 Aug 2026 21:16:50 GMT | ||
| --- | ||
| # Managing Dart and Flutter Applications via MCP | ||
|
|
||
| ## Contents | ||
| - [Core Capabilities](#core-capabilities) | ||
| - [Workflow: Application Discovery and Connection](#workflow-application-discovery-and-connection) | ||
| - [Workflow: UI Modification and Hot Reloading](#workflow-ui-modification-and-hot-reloading) | ||
| - [Workflow: Runtime Debugging and Error Resolution](#workflow-runtime-debugging-and-error-resolution) | ||
| - [Workflow: UI Interaction via Flutter Driver](#workflow-ui-interaction-via-flutter-driver) | ||
| - [Examples](#examples) | ||
|
|
||
| ## Core Capabilities | ||
|
|
||
| The Dart and Flutter MCP server manages the underlying connection to the application's VM service via the Dart Tooling Daemon (`dtd`). Assume the server is already configured and active. | ||
|
|
||
| - **Hot Reload:** Proactively push visual feedback for UI widget updates and simple logic changes. | ||
| - **Hot Restart:** Reset the app state for deep non-widget changes or clean resets. | ||
| - **Widget Inspection:** Query tree structures and identify UI hierarchy names. | ||
| - **Error Fetching:** Retrieve live runtime exceptions and trace pointers live. | ||
| - **Package Management:** Search pub.dev and manage `pubspec.yaml` dependencies. | ||
|
|
||
| ## Workflow: Application Discovery and Connection | ||
|
|
||
| Execute this workflow before attempting runtime operations. | ||
|
|
||
| - [ ] 1. Run `list_running_apps` or use the `dtd` tool to discover active application instances in the current workspace. | ||
| - [ ] 2. Extract the `appUri` for the target application. | ||
| - [ ] 3. Verify the connection using `dtd` or `vm_service` to ensure the `appUri` matches the project's workspace. Re-sync via `dtd` if necessary. | ||
| - [ ] 4. **Conditional:** If no app is running, inform the user immediately, but **do not stop**. Proceed with static code edits and file modifications. | ||
|
|
||
| ## Workflow: UI Modification and Hot Reloading | ||
|
|
||
| Whenever modifying Flutter UI widgets or Dart code, follow this feedback loop to maintain visual consistency. | ||
|
|
||
| - [ ] 1. Implement the requested code changes in the target `.dart` files. | ||
| - [ ] 2. **Conditional:** | ||
| - If editing Flutter UI widgets or simple methods, trigger `hot_reload` across all targeted instances immediately. | ||
| - If modifying foundational logic, state initialization, or `main()`, trigger `hot_restart` to reset state across all devices. | ||
| - [ ] 3. Run `get_runtime_errors` to verify the reload/restart did not introduce new exceptions. | ||
| - [ ] 4. If errors exist, review the stack trace, apply a fix, and repeat step 2. | ||
|
|
||
| ## Workflow: Runtime Debugging and Error Resolution | ||
|
|
||
| When tasked with fixing layout issues (e.g., RenderFlex overflow) or runtime exceptions, use this diagnostic loop. | ||
|
|
||
| - [ ] 1. Execute `get_runtime_errors` to fetch live exceptions from the running application. | ||
| - [ ] 2. Identify the failing widget or logic block from the stack trace. | ||
| - [ ] 3. Execute `widget_inspector` to query the live UI tree structure and understand the layout constraints causing the issue. | ||
| - [ ] 4. Apply the code fix to the relevant Dart file. | ||
| - [ ] 5. Trigger `hot_reload`. | ||
| - [ ] 6. Execute `get_runtime_errors` again to confirm the error is resolved. | ||
|
|
||
| ## Workflow: UI Interaction via Flutter Driver | ||
|
|
||
| To drive a running Flutter app (take screenshots, tap buttons, enter text), the app must be instrumented with `flutter_driver`. | ||
|
|
||
| - [ ] 1. Verify `flutter_driver` is in `pubspec.yaml`. If not, run `flutter pub add "flutter_driver:{sdk: flutter}"`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change: - [ ] 1. Verify `flutter_driver` is in `pubspec.yaml`. If not, run `flutter pub add 'dev:flutter_driver:{"sdk":"flutter"}'.` |
||
| - [ ] 2. Ensure the app's `main()` function conditionally enables the driver extension: | ||
| ```dart | ||
| import 'package:flutter_driver/driver_extension.dart'; | ||
|
|
||
| void main() { | ||
| if (const bool.fromEnvironment('ENABLE_FLUTTER_DRIVER')) { | ||
| enableFlutterDriverExtension(); | ||
| } | ||
| runApp(const MyApp()); | ||
| } | ||
| ``` | ||
| - [ ] 3. Instruct the user to launch the app with: `flutter run -d <device-id> --dart-define=ENABLE_FLUTTER_DRIVER=true`. | ||
|
Comment on lines
+64
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Importing Suggested change: - [ ] 2. Ensure a separate entry point (e.g., `lib/main_test.dart`) is created to enable the driver extension without affecting production builds:
```dart
import 'package:flutter_driver/driver_extension.dart';
import 'main.dart' as app;
void main() {
enableFlutterDriverExtension();
app.main();
}
|
||
| - [ ] 4. Use the `dtd` tool to discover the app and `flutter_driver_command` to drive its UI. | ||
| - [ ] 5. **Conditional (Web Targets):** If the target is a web build, do not use `flutter_driver` finder-based commands (screenshots/taps). Instead, rely on a browser-driving MCP. Ensure the user runs `flutter run -d web-server` so DTD connects properly to the driven browser. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Scenario: Adding a Package and Scaffolding UI | ||
|
|
||
| **Input:** "Add a line chart to map user scores over time." | ||
|
|
||
| **Execution Steps:** | ||
| 1. Execute `pub_dev_search` with query "line chart". | ||
| 2. Identify `fl_chart` as the optimal package. | ||
| 3. Add dependency to `pubspec.yaml`. | ||
| 4. Generate the widget code using `fl_chart` boilerplate. | ||
| 5. Insert the widget into the target UI file. | ||
| 6. Trigger `hot_reload`. | ||
| 7. Run `get_runtime_errors` to ensure no missing constraints or syntax errors exist. | ||
|
|
||
| ### Scenario: Proactive Hot Reloading | ||
|
|
||
| **Input:** "Change the primary button color to blue and increase the padding to 16." | ||
|
|
||
| **Execution Steps:** | ||
| 1. Locate the target `ElevatedButton` or `Container` in the Dart code. | ||
| 2. Update `style: ElevatedButton.styleFrom(backgroundColor: Colors.blue)` and `padding: EdgeInsets.all(16)`. | ||
| 3. Save the file. | ||
| 4. Immediately execute `hot_reload` using the active `appUri`. | ||
| 5. Confirm successful reload via tool output. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example prompt column for the
flutter-app-runtimeskill is currently empty. To maintain consistency with other skills in the table, please provide a representative example prompt.