4
4
5
5
import 'dart:async' ;
6
6
7
+ import 'package:args/args.dart' ;
8
+ import 'package:dart_mcp_server/arg_parser.dart' as dart_mcp_server;
9
+ import 'package:dartdev/src/utils.dart' ;
10
+
7
11
import '../core.dart' ;
8
12
import '../sdk.dart' ;
9
13
import '../vm_interop_handler.dart' ;
@@ -14,44 +18,43 @@ class DartMCPServerCommand extends DartdevCommand {
14
18
static const String cmdDescription = '''
15
19
A stdio based Model Context Protocol (MCP) server to aid in Dart and Flutter development.''' ;
16
20
17
- static const _forceRootsFallbackFlag = 'force-roots-fallback' ;
18
21
static const _experimentFlag = 'experimental-mcp-server' ;
19
22
23
+ @override
24
+ ArgParser createArgParser () => dart_mcp_server.createArgParser (
25
+ usageLineLength: dartdevUsageLineLength, includeHelp: false );
26
+
20
27
DartMCPServerCommand ({bool verbose = false })
21
28
: super (cmdName, cmdDescription, verbose, hidden: true ) {
22
- argParser
23
- .. addFlag (
24
- _forceRootsFallbackFlag,
25
- negatable : true ,
29
+ argParser. addFlag (_experimentFlag,
30
+ // This flag is no longer required but we are leaving it in for
31
+ // backwards compatibility.
32
+ hide : true ,
26
33
defaultsTo: false ,
27
- help:
28
- 'Forces a behavior for project roots which uses MCP tools instead '
29
- 'of the native MCP roots. This can be helpful for clients like '
30
- 'Cursor which claim to have roots support but do not actually '
31
- 'support it.' ,
32
- )
33
- ..addFlag (_experimentFlag,
34
- // This flag is no longer required but we are leaving it in for
35
- // backwards compatibility.
36
- hide: true ,
37
- defaultsTo: false ,
38
- help: 'A required flag in order to use this command. Passing this '
39
- 'flag is an acknowledgement that you understand it is an '
40
- 'experimental feature with no stability guarantees.' );
34
+ help: 'A required flag in order to use this command. Passing this '
35
+ 'flag is an acknowledgement that you understand it is an '
36
+ 'experimental feature with no stability guarantees.' );
41
37
}
42
38
43
39
@override
44
40
CommandCategory get commandCategory => CommandCategory .tools;
45
41
46
42
@override
47
43
Future <int > run () async {
48
- final args = argResults! ;
44
+ final parsedArgs = argResults! ;
45
+
46
+ // Strip out the experiment flag before forwarding on the args, this flag
47
+ // isn't supported by the actual binary.
48
+ final forwardedArgs = argResults! .arguments.toList ();
49
+ if (parsedArgs.wasParsed (_experimentFlag)) {
50
+ forwardedArgs.removeWhere ((arg) => arg.endsWith (_experimentFlag));
51
+ }
49
52
try {
50
53
VmInteropHandler .run (
51
54
sdk.dartAotRuntime,
52
55
[
53
56
sdk.dartMCPServerAotSnapshot,
54
- if (args. flag (_forceRootsFallbackFlag)) '--$ _forceRootsFallbackFlag '
57
+ ...forwardedArgs,
55
58
],
56
59
useExecProcess: true ,
57
60
);
0 commit comments