expose public arg_parser.dart library (#209)
This can be imported by the dart tool without pulling in a bunch of extra DEPS.
cc @bkonyi
diff --git a/pkgs/dart_mcp_server/CHANGELOG.md b/pkgs/dart_mcp_server/CHANGELOG.md
index 91854d3..c641328 100644
--- a/pkgs/dart_mcp_server/CHANGELOG.md
+++ b/pkgs/dart_mcp_server/CHANGELOG.md
@@ -42,3 +42,4 @@
* Add `--log-file` argument to log all protocol traffic to a file.
* Improve error text for failed DTD connections as well as the tool description.
* Add support for injecting an `Analytics` instance to track usage.
+* Add `arg_parser.dart` public library with minimal deps to be used by the dart tool.
diff --git a/pkgs/dart_mcp_server/lib/arg_parser.dart b/pkgs/dart_mcp_server/lib/arg_parser.dart
new file mode 100644
index 0000000..ccb7844
--- /dev/null
+++ b/pkgs/dart_mcp_server/lib/arg_parser.dart
@@ -0,0 +1,5 @@
+// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+export 'src/arg_parser.dart' show argParser;
diff --git a/pkgs/dart_mcp_server/lib/src/arg_parser.dart b/pkgs/dart_mcp_server/lib/src/arg_parser.dart
new file mode 100644
index 0000000..4dd55c3
--- /dev/null
+++ b/pkgs/dart_mcp_server/lib/src/arg_parser.dart
@@ -0,0 +1,44 @@
+// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:args/args.dart';
+
+final argParser =
+ ArgParser(allowTrailingOptions: false)
+ ..addOption(
+ dartSdkOption,
+ help:
+ 'The path to the root of the desired Dart SDK. Defaults to the '
+ 'DART_SDK environment variable.',
+ )
+ ..addOption(
+ flutterSdkOption,
+ help:
+ 'The path to the root of the desired Flutter SDK. Defaults to '
+ 'the FLUTTER_SDK environment variable, then searching up from '
+ 'the Dart SDK.',
+ )
+ ..addFlag(
+ forceRootsFallbackFlag,
+ negatable: true,
+ defaultsTo: false,
+ help:
+ 'Forces a behavior for project roots which uses MCP tools '
+ 'instead of the native MCP roots. This can be helpful for '
+ 'clients like cursor which claim to have roots support but do '
+ 'not actually support it.',
+ )
+ ..addOption(
+ logFileOption,
+ help:
+ 'Path to a file to log all MPC protocol traffic to. File will be '
+ 'overwritten if it exists.',
+ )
+ ..addFlag(helpFlag, abbr: 'h', help: 'Show usage text');
+
+const dartSdkOption = 'dart-sdk';
+const flutterSdkOption = 'flutter-sdk';
+const forceRootsFallbackFlag = 'force-roots-fallback';
+const helpFlag = 'help';
+const logFileOption = 'log-file';
diff --git a/pkgs/dart_mcp_server/lib/src/server.dart b/pkgs/dart_mcp_server/lib/src/server.dart
index e900dd6..d685e5a 100644
--- a/pkgs/dart_mcp_server/lib/src/server.dart
+++ b/pkgs/dart_mcp_server/lib/src/server.dart
@@ -6,7 +6,6 @@
import 'dart:convert';
import 'dart:io' as io;
-import 'package:args/args.dart';
import 'package:async/async.dart';
import 'package:dart_mcp/server.dart';
import 'package:file/file.dart';
@@ -16,6 +15,7 @@
import 'package:stream_channel/stream_channel.dart';
import 'package:unified_analytics/unified_analytics.dart';
+import 'arg_parser.dart';
import 'mixins/analyzer.dart';
import 'mixins/dash_cli.dart';
import 'mixins/dtd.dart';
@@ -200,47 +200,8 @@
validateArguments: validateArguments,
);
}
-
- static final argParser =
- ArgParser(allowTrailingOptions: false)
- ..addOption(
- dartSdkOption,
- help:
- 'The path to the root of the desired Dart SDK. Defaults to the '
- 'DART_SDK environment variable.',
- )
- ..addOption(
- flutterSdkOption,
- help:
- 'The path to the root of the desired Flutter SDK. Defaults to '
- 'the FLUTTER_SDK environment variable, then searching up from '
- 'the Dart SDK.',
- )
- ..addFlag(
- forceRootsFallbackFlag,
- negatable: true,
- defaultsTo: false,
- help:
- 'Forces a behavior for project roots which uses MCP tools '
- 'instead of the native MCP roots. This can be helpful for '
- 'clients like cursor which claim to have roots support but do '
- 'not actually support it.',
- )
- ..addOption(
- logFileOption,
- help:
- 'Path to a file to log all MPC protocol traffic to. File will be '
- 'overwritten if it exists.',
- )
- ..addFlag(helpFlag, abbr: 'h', help: 'Show usage text');
}
-const dartSdkOption = 'dart-sdk';
-const flutterSdkOption = 'flutter-sdk';
-const forceRootsFallbackFlag = 'force-roots-fallback';
-const helpFlag = 'help';
-const logFileOption = 'log-file';
-
/// Creates a `Sink<String>` for [logFile].
Sink<String> _createLogSink(io.File logFile) {
logFile.createSync(recursive: true);