Skip to content

Commit 38734ff

Browse files
authored
Migrate to the connected app service (#208)
Closes #198 This does drop all support for connecting to apps on SDKs that don't have this service, and I bumped the min SDK accordingly.
1 parent b7d438b commit 38734ff

File tree

15 files changed

+342
-476
lines changed

15 files changed

+342
-476
lines changed

.github/workflows/dart_mcp_server.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
fail-fast: false
2929
matrix:
3030
flutterSdk:
31-
- stable
31+
- beta
3232
- master
3333
os:
3434
- ubuntu-latest

pkgs/dart_mcp_server/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
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+
* Listen to the new DTD `ConnectedApp` service instead of the `Editor.DebugSessions`
46+
service, when available.
4547
* Screenshot tool disabled until
4648
https://github.com/flutter/flutter/issues/170357 is resolved.
4749
* Add `arg_parser.dart` public library with minimal deps to be used by the dart tool.

pkgs/dart_mcp_server/lib/src/arg_parser.dart

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,37 @@
44

55
import 'package:args/args.dart';
66

7-
final argParser =
8-
ArgParser(allowTrailingOptions: false)
9-
..addOption(
10-
dartSdkOption,
11-
help:
12-
'The path to the root of the desired Dart SDK. Defaults to the '
13-
'DART_SDK environment variable.',
14-
)
15-
..addOption(
16-
flutterSdkOption,
17-
help:
18-
'The path to the root of the desired Flutter SDK. Defaults to '
19-
'the FLUTTER_SDK environment variable, then searching up from '
20-
'the Dart SDK.',
21-
)
22-
..addFlag(
23-
forceRootsFallbackFlag,
24-
negatable: true,
25-
defaultsTo: false,
26-
help:
27-
'Forces a behavior for project roots which uses MCP tools '
28-
'instead of the native MCP roots. This can be helpful for '
29-
'clients like cursor which claim to have roots support but do '
30-
'not actually support it.',
31-
)
32-
..addOption(
33-
logFileOption,
34-
help:
35-
'Path to a file to log all MPC protocol traffic to. File will be '
36-
'overwritten if it exists.',
37-
)
38-
..addFlag(helpFlag, abbr: 'h', help: 'Show usage text');
7+
final argParser = ArgParser(allowTrailingOptions: false)
8+
..addOption(
9+
dartSdkOption,
10+
help:
11+
'The path to the root of the desired Dart SDK. Defaults to the '
12+
'DART_SDK environment variable.',
13+
)
14+
..addOption(
15+
flutterSdkOption,
16+
help:
17+
'The path to the root of the desired Flutter SDK. Defaults to '
18+
'the FLUTTER_SDK environment variable, then searching up from '
19+
'the Dart SDK.',
20+
)
21+
..addFlag(
22+
forceRootsFallbackFlag,
23+
negatable: true,
24+
defaultsTo: false,
25+
help:
26+
'Forces a behavior for project roots which uses MCP tools '
27+
'instead of the native MCP roots. This can be helpful for '
28+
'clients like cursor which claim to have roots support but do '
29+
'not actually support it.',
30+
)
31+
..addOption(
32+
logFileOption,
33+
help:
34+
'Path to a file to log all MPC protocol traffic to. File will be '
35+
'overwritten if it exists.',
36+
)
37+
..addFlag(helpFlag, abbr: 'h', help: 'Show usage text');
3938

4039
const dartSdkOption = 'dart-sdk';
4140
const flutterSdkOption = 'flutter-sdk';

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

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,18 @@ base mixin DartAnalyzerSupport
110110
log(LoggingLevel.warning, line, logger: 'DartLanguageServer');
111111
});
112112

113-
final lspConnection =
114-
Peer(lspChannel(lspServer.stdout, lspServer.stdin))
115-
..registerMethod(
116-
lsp.Method.textDocument_publishDiagnostics.toString(),
117-
_handleDiagnostics,
118-
)
119-
..registerMethod(r'$/analyzerStatus', _handleAnalyzerStatus)
120-
..registerFallback((Parameters params) {
121-
log(
122-
LoggingLevel.debug,
123-
() => 'Unhandled LSP message: ${params.method} - ${params.asMap}',
124-
);
125-
});
113+
final lspConnection = Peer(lspChannel(lspServer.stdout, lspServer.stdin))
114+
..registerMethod(
115+
lsp.Method.textDocument_publishDiagnostics.toString(),
116+
_handleDiagnostics,
117+
)
118+
..registerMethod(r'$/analyzerStatus', _handleAnalyzerStatus)
119+
..registerFallback((Parameters params) {
120+
log(
121+
LoggingLevel.debug,
122+
() => 'Unhandled LSP message: ${params.method} - ${params.asMap}',
123+
);
124+
});
126125
_lspConnection = lspConnection;
127126

128127
unawaited(lspConnection.listen());
@@ -357,8 +356,9 @@ base mixin DartAnalyzerSupport
357356
diagnostics[diagnosticParams.uri] = diagnosticParams.diagnostics;
358357
log(LoggingLevel.debug, {
359358
ParameterNames.uri: diagnosticParams.uri,
360-
'diagnostics':
361-
diagnosticParams.diagnostics.map((d) => d.toJson()).toList(),
359+
'diagnostics': diagnosticParams.diagnostics
360+
.map((d) => d.toJson())
361+
.toList(),
362362
});
363363
}
364364

@@ -370,16 +370,18 @@ base mixin DartAnalyzerSupport
370370
final newRoots = await roots;
371371

372372
final oldWorkspaceFolders = _currentWorkspaceFolders;
373-
final newWorkspaceFolders =
374-
_currentWorkspaceFolders = HashSet<lsp.WorkspaceFolder>(
373+
final newWorkspaceFolders = _currentWorkspaceFolders =
374+
HashSet<lsp.WorkspaceFolder>(
375375
equals: (a, b) => a.uri == b.uri,
376376
hashCode: (a) => a.uri.hashCode,
377377
)..addAll(newRoots.map((r) => r.asWorkspaceFolder));
378378

379-
final added =
380-
newWorkspaceFolders.difference(oldWorkspaceFolders).toList();
381-
final removed =
382-
oldWorkspaceFolders.difference(newWorkspaceFolders).toList();
379+
final added = newWorkspaceFolders
380+
.difference(oldWorkspaceFolders)
381+
.toList();
382+
final removed = oldWorkspaceFolders
383+
.difference(newWorkspaceFolders)
384+
.toList();
383385

384386
// This can happen in the case of multiple notifications in quick
385387
// succession, the `roots` future will complete only after the state has

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,9 @@ base mixin DashCliSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport
119119
// Platforms are ignored for Dart, so no need to validate them.
120120
final invalidPlatforms = platforms.difference(_allowedFlutterPlatforms);
121121
if (invalidPlatforms.isNotEmpty) {
122-
final plural =
123-
invalidPlatforms.length > 1
124-
? 'are not valid platforms'
125-
: 'is not a valid platform';
122+
final plural = invalidPlatforms.length > 1
123+
? 'are not valid platforms'
124+
: 'is not a valid platform';
126125
errors.add(
127126
ValidationError(
128127
ValidationErrorType.custom,
@@ -163,14 +162,13 @@ base mixin DashCliSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport
163162
return runCommandInRoot(
164163
request,
165164
arguments: commandArgs,
166-
commandForRoot:
167-
(_, _, sdk) =>
168-
switch (projectType) {
169-
'dart' => sdk.dartExecutablePath,
170-
'flutter' => sdk.flutterExecutablePath,
171-
_ => StateError('Unknown project type: $projectType'),
172-
}
173-
as String,
165+
commandForRoot: (_, _, sdk) =>
166+
switch (projectType) {
167+
'dart' => sdk.dartExecutablePath,
168+
'flutter' => sdk.flutterExecutablePath,
169+
_ => StateError('Unknown project type: $projectType'),
170+
}
171+
as String,
174172
commandDescription: '$projectType create',
175173
fileSystem: fileSystem,
176174
processManager: processManager,

0 commit comments

Comments
 (0)