Skip to content

Commit b7d438b

Browse files
authored
disable the screenshots tool by default (#210)
Disabling due to flutter/flutter#170357 - this only works today by default on the desktop environment. We could fall back on full device screenshots but are holding off on that for now as we have to evaluate some extra potential privacy concerns with exposing the entire screen as opposed to just the flutter drawn pixels.
1 parent c230aaa commit b7d438b

6 files changed

Lines changed: 34 additions & 24 deletions

File tree

‎pkgs/dart_mcp_server/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@
4242
* Add `--log-file` argument to log all protocol traffic to a file.
4343
* Improve error text for failed DTD connections as well as the tool description.
4444
* Add support for injecting an `Analytics` instance to track usage.
45+
* Screenshot tool disabled until
46+
https://github.com/flutter/flutter/issues/170357 is resolved.
4547
* Add `arg_parser.dart` public library with minimal deps to be used by the dart tool.

‎pkgs/dart_mcp_server/README.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ for configuring the server in Android Studio. -->
7474
[![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/install-mcp?name=dart&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoiZGFydCBtY3Atc2VydmVyIC0tZXhwZXJpbWVudGFsLW1jcC1zZXJ2ZXIgLS1mb3JjZS1yb290cy1mYWxsYmFjayJ9)
7575

7676
The easiest way to configure the Dart MCP server with Cursor is by clicking the "Add to Cursor"
77-
button above.
77+
button above.
7878

7979
Alternatively, you can configure the server manually. Go to **Cursor -> Settings -> Cursor Settings > Tools & Integrations**, and then click **"Add Custom MCP"** or **"New MCP Server"**
8080
depending on whether you already have other MCP servers configured. Edit the `.cursor/mcp.json` file in your local project (configuration will only apply to this project) or
@@ -155,7 +155,6 @@ For more information, see the official VS Code documentation for
155155
| `pub` | `static tool` | Runs a `dart pub` command for the given project roots. |
156156
| `pub_dev_search` | `package search` | Searches pub.dev for packages relevant to a given search query. |
157157
| `get_runtime_errors` | `runtime analysis` | Retrieves the list of runtime errors that have occurred in the active Dart or Flutter application. |
158-
| `take_screenshot` | `runtime analysis` | Takes a screenshot of the active Flutter application in its current state. |
159158
| `get_widget_tree` | `runtime analysis` | Retrieves the widget tree from the active Flutter application. |
160159
| `get_selected_widget` | `runtime analysis` | Retrieves the selected widget from the active Flutter application. |
161160
| `hot_reload` | `runtime tool` | Performs a hot reload of the active Flutter application. |

‎pkgs/dart_mcp_server/lib/src/mixins/dtd.dart‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ base mixin DartToolingDaemonSupport
6161
/// for full list of available Flutter Widget Inspector service extensions.
6262
static const _inspectorServiceExtensionPrefix = 'ext.flutter.inspector';
6363

64+
/// Whether or not to enable the screenshot tool.
65+
bool get enableScreenshots;
66+
6467
/// Called when the DTD connection is lost, resets all associated state.
6568
Future<void> _resetDtd() async {
6669
_dtd = null;
@@ -165,7 +168,7 @@ base mixin DartToolingDaemonSupport
165168
// they should return an error when used against a pure Dart app (or a
166169
// Flutter app that does not support the operation, e.g. hot reload is not
167170
// supported in profile mode).
168-
registerTool(screenshotTool, takeScreenshot);
171+
if (enableScreenshots) registerTool(screenshotTool, takeScreenshot);
169172
registerTool(hotReloadTool, hotReload);
170173
registerTool(getWidgetTreeTool, widgetTree);
171174
registerTool(getSelectedWidgetTool, selectedWidget);

‎pkgs/dart_mcp_server/lib/src/server.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ final class DartMCPServer extends MCPServer
5252
@visibleForTesting this.processManager = const LocalProcessManager(),
5353
@visibleForTesting this.fileSystem = const LocalFileSystem(),
5454
this.forceRootsFallback = false,
55+
// Disabled due to https://github.com/flutter/flutter/issues/170357
56+
this.enableScreenshots = false,
5557
super.protocolLogSink,
5658
}) : super.fromStreamChannel(
5759
implementation: Implementation(
@@ -156,6 +158,9 @@ final class DartMCPServer extends MCPServer
156158
@override
157159
final Analytics? analytics;
158160

161+
@override
162+
final bool enableScreenshots;
163+
159164
@override
160165
/// Automatically logs all tool calls via analytics by wrapping the [impl],
161166
/// if [analytics] is not `null`.

‎pkgs/dart_mcp_server/test/test_harness.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ Future<ServerConnectionPair> _initializeMCPServer(
445445
fileSystem: fileSystem,
446446
sdk: sdk,
447447
analytics: analytics,
448+
// So we can test them.
449+
enableScreenshots: true,
448450
);
449451
addTearDown(server.shutdown);
450452
connection = client.connectServer(clientChannel);

‎pkgs/dart_mcp_server/test/tools/dtd_test.dart‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,6 @@ void main() {
3232
});
3333

3434
group('flutter tests', () {
35-
test('can take a screenshot', () async {
36-
await testHarness.startDebugSession(
37-
counterAppPath,
38-
'lib/main.dart',
39-
isFlutter: true,
40-
);
41-
final tools =
42-
(await testHarness.mcpServerConnection.listTools()).tools;
43-
final screenshotTool = tools.singleWhere(
44-
(t) => t.name == DartToolingDaemonSupport.screenshotTool.name,
45-
);
46-
final screenshotResult = await testHarness.callToolWithRetry(
47-
CallToolRequest(name: screenshotTool.name),
48-
);
49-
expect(screenshotResult.content.single, {
50-
'data': anything,
51-
'mimeType': 'image/png',
52-
'type': ImageContent.expectedType,
53-
});
54-
});
55-
5635
test('can get the widget tree', () async {
5736
await testHarness.startDebugSession(
5837
counterAppPath,
@@ -225,6 +204,26 @@ void main() {
225204
});
226205
});
227206

207+
test('can take a screenshot', () async {
208+
await testHarness.startDebugSession(
209+
counterAppPath,
210+
'lib/main.dart',
211+
isFlutter: true,
212+
);
213+
final tools = (await testHarness.mcpServerConnection.listTools()).tools;
214+
final screenshotTool = tools.singleWhere(
215+
(t) => t.name == DartToolingDaemonSupport.screenshotTool.name,
216+
);
217+
final screenshotResult = await testHarness.callToolWithRetry(
218+
CallToolRequest(name: screenshotTool.name),
219+
);
220+
expect(screenshotResult.content.single, {
221+
'data': anything,
222+
'mimeType': 'image/png',
223+
'type': ImageContent.expectedType,
224+
});
225+
});
226+
228227
group('get selected widget', () {
229228
test('when a selected widget exists', () async {
230229
final server = testHarness.serverConnectionPair.server!;

0 commit comments

Comments
 (0)