Skip to content

Commit 64dfa7f

Browse files
authored
move static argParser variable to a createArgParser function (#212)
1 parent a5aa053 commit 64dfa7f

File tree

3 files changed

+52
-32
lines changed

3 files changed

+52
-32
lines changed

pkgs/dart_mcp_server/lib/arg_parser.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
export 'src/arg_parser.dart' show argParser;
5+
export 'src/arg_parser.dart' show createArgParser;

pkgs/dart_mcp_server/lib/src/arg_parser.dart

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

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

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');
7+
/// Creates an arg parser for th MCP server.
8+
///
9+
/// The `--help` option is only included if [includeHelp] is `true`.
10+
///
11+
/// Passing no options results in the default arg parser.
12+
ArgParser createArgParser({
13+
bool includeHelp = true,
14+
bool allowTrailingOptions = false,
15+
int? usageLineLength,
16+
}) {
17+
final parser =
18+
ArgParser(
19+
allowTrailingOptions: allowTrailingOptions,
20+
usageLineLength: usageLineLength,
21+
)
22+
..addOption(
23+
dartSdkOption,
24+
help:
25+
'The path to the root of the desired Dart SDK. Defaults to the '
26+
'DART_SDK environment variable.',
27+
)
28+
..addOption(
29+
flutterSdkOption,
30+
help:
31+
'The path to the root of the desired Flutter SDK. Defaults to '
32+
'the FLUTTER_SDK environment variable, then searching up from '
33+
'the Dart SDK.',
34+
)
35+
..addFlag(
36+
forceRootsFallbackFlag,
37+
negatable: true,
38+
defaultsTo: false,
39+
help:
40+
'Forces a behavior for project roots which uses MCP tools '
41+
'instead of the native MCP roots. This can be helpful for '
42+
'clients like cursor which claim to have roots support but do '
43+
'not actually support it.',
44+
)
45+
..addOption(
46+
logFileOption,
47+
help:
48+
'Path to a file to log all MPC protocol traffic to. File will be '
49+
'overwritten if it exists.',
50+
);
51+
52+
if (includeHelp) parser.addFlag(helpFlag, abbr: 'h', help: 'Show usage text');
53+
return parser;
54+
}
3855

3956
const dartSdkOption = 'dart-sdk';
4057
const flutterSdkOption = 'flutter-sdk';

pkgs/dart_mcp_server/lib/src/server.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ final class DartMCPServer extends MCPServer
144144
}
145145
}
146146

147+
/// The default arg parser for the MCP Server.
148+
static final argParser = createArgParser();
149+
147150
@override
148151
final LocalProcessManager processManager;
149152

0 commit comments

Comments
 (0)