From 650ed68b6dde406d6d0f4e3a7c9fc987db77c23b Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Wed, 3 Sep 2025 11:15:17 -0700 Subject: [PATCH 1/6] Add pub add format guidance --- pkgs/dart_mcp_server/lib/src/mixins/pub.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/pub.dart b/pkgs/dart_mcp_server/lib/src/mixins/pub.dart index e9bd90dc..014871d0 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/pub.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/pub.dart @@ -87,7 +87,15 @@ base mixin PubSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport inputSchema: Schema.object( properties: { ParameterNames.command: Schema.string( - title: 'The pub command to run.', + title: '''The pub subcommand to run. + +For the `add` subcommand: + - To add a package normally (typical): "pkg_name" + - Git reference: "pkg_name:{git:{url: https://github.com/pkg_name/pkg_name.git, ref: branch, path: subdir}}" + - branch and subdir are optional. + - Local path reference: "pkg_name:{path: ../pkg_name}" + - Dev Dependency: "dev:pkg_name" +''', description: 'Currently only ${SupportedPubCommand.listAll} are supported.', ), From 9884d8858219296303ae97be894ab404c3e547c3 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Wed, 3 Sep 2025 13:48:53 -0700 Subject: [PATCH 2/6] Switch to enum values, move descriptions --- pkgs/dart_mcp_server/lib/src/mixins/pub.dart | 80 ++++++++++++++------ 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/pub.dart b/pkgs/dart_mcp_server/lib/src/mixins/pub.dart index 014871d0..87d64186 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/pub.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/pub.dart @@ -87,29 +87,18 @@ base mixin PubSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport inputSchema: Schema.object( properties: { ParameterNames.command: Schema.string( - title: '''The pub subcommand to run. - -For the `add` subcommand: - - To add a package normally (typical): "pkg_name" - - Git reference: "pkg_name:{git:{url: https://github.com/pkg_name/pkg_name.git, ref: branch, path: subdir}}" - - branch and subdir are optional. - - Local path reference: "pkg_name:{path: ../pkg_name}" - - Dev Dependency: "dev:pkg_name" -''', + title: 'The pub subcommand to run.', + enumValues: SupportedPubCommand.values.map((e) => e.name), description: - 'Currently only ${SupportedPubCommand.listAll} are supported.', + 'Only ${SupportedPubCommand.listAll} are supported.\n' + '${SupportedPubCommand.commandDescriptions}', ), ParameterNames.packageNames: Schema.list( title: 'The package names to run the command for.', description: 'This is required for the ' '${SupportedPubCommand.listAllThatRequirePackageName} commands. ', - items: Schema.string( - title: 'A package to run the command for.', - description: - 'When used with "add", prefix with "dev:" to add the package ' - 'as a dev dependency.', - ), + items: Schema.string(title: 'A package to run the command for.'), ), ParameterNames.roots: rootsSchema(), }, @@ -120,22 +109,49 @@ For the `add` subcommand: /// The set of supported `dart pub` subcommands. enum SupportedPubCommand { - // This is supported in a simplified form: `dart pub add `. - // TODO(https://github.com/dart-lang/ai/issues/77): add support for adding - // dev dependencies. - add(requiresPackageNames: true), + add( + requiresPackageNames: true, + description: '''Add package dependencies. + - To add a package normally (typical): "pkg_name" + - Git reference: "pkg_name:{git:{url: https://github.com/pkg_name/pkg_name.git, ref: branch, path: subdir}}" + - ref and path are optional. + - From local path: "pkg_name:{path: ../pkg_name}" + - Dev Dependency: "dev:pkg_name" + - Dependency override: "override:pkg_name:1.0.0" + ''', + ), + + deps(description: 'Print the dependency tree of the current package.'), - get, + get( + description: "Fetch the current package's dependencies and install them.", + ), + + outdated( + description: 'Analyze dependencies to find which ones can be upgraded.', + ), // This is supported in a simplified form: `dart pub remove `. - remove(requiresPackageNames: true), + remove( + requiresPackageNames: true, + description: 'Removes specified dependencies from `pubspec.yaml`.', + ), - upgrade; + upgrade( + description: + "Upgrade the current package's dependencies to latest versions.", + ); - const SupportedPubCommand({this.requiresPackageNames = false}); + const SupportedPubCommand({ + this.requiresPackageNames = false, + required this.description, + }); final bool requiresPackageNames; + /// The description to use in the subcommand help. + final String description; + static SupportedPubCommand? fromName(String name) { for (final command in SupportedPubCommand.values) { if (command.name == name) { @@ -155,6 +171,22 @@ enum SupportedPubCommand { ); } + static String get commandDescriptions { + return _getDescriptions(values); + } + + static String _getDescriptions(Iterable commands) { + final buffer = StringBuffer(); + for (final command in commands) { + final commandName = command.name; + final description = command.description; + if (description.isNotEmpty) { + buffer.writeln('- `$commandName`: $description'); + } + } + return buffer.toString(); + } + static String _writeCommandsAsList(List commands) { final buffer = StringBuffer(); for (var i = 0; i < commands.length; i++) { From d9c4c7b55166c2e329f56724e68c0ab8b1d1f350 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Wed, 3 Sep 2025 14:19:45 -0700 Subject: [PATCH 3/6] Add test --- pkgs/dart_mcp_server/lib/src/mixins/pub.dart | 4 +- pkgs/dart_mcp_server/test/tools/pub_test.dart | 46 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/pub.dart b/pkgs/dart_mcp_server/lib/src/mixins/pub.dart index 87d64186..96475432 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/pub.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/pub.dart @@ -88,7 +88,9 @@ base mixin PubSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport properties: { ParameterNames.command: Schema.string( title: 'The pub subcommand to run.', - enumValues: SupportedPubCommand.values.map((e) => e.name), + enumValues: SupportedPubCommand.values + .map((e) => e.name) + .toList(), description: 'Only ${SupportedPubCommand.listAll} are supported.\n' '${SupportedPubCommand.commandDescriptions}', diff --git a/pkgs/dart_mcp_server/test/tools/pub_test.dart b/pkgs/dart_mcp_server/test/tools/pub_test.dart index 50d0cc61..24f4cb58 100644 --- a/pkgs/dart_mcp_server/test/tools/pub_test.dart +++ b/pkgs/dart_mcp_server/test/tools/pub_test.dart @@ -160,6 +160,50 @@ void main() { ]); }); + test('deps', () async { + final request = CallToolRequest( + name: dartPubTool.name, + arguments: { + ParameterNames.command: 'deps', + ParameterNames.roots: [ + {ParameterNames.root: testRoot.uri}, + ], + }, + ); + final result = await testHarness.callToolWithRetry(request); + + // Verify the command was sent to the process manager without error. + expect(result.isError, isNot(true)); + expect(testProcessManager.commandsRan, [ + equalsCommand(( + command: [endsWith(executableName), 'pub', 'deps'], + workingDirectory: testRoot.path, + )), + ]); + }); + + test('outdated', () async { + final request = CallToolRequest( + name: dartPubTool.name, + arguments: { + ParameterNames.command: 'outdated', + ParameterNames.roots: [ + {ParameterNames.root: testRoot.uri}, + ], + }, + ); + final result = await testHarness.callToolWithRetry(request); + + // Verify the command was sent to the process manager without error. + expect(result.isError, isNot(true)); + expect(testProcessManager.commandsRan, [ + equalsCommand(( + command: [endsWith(executableName), 'pub', 'outdated'], + workingDirectory: testRoot.path, + )), + ]); + }); + test('in a subdir of an a root', () async { fileSystem.file(p.join(fakeAppPath, 'subdir', 'pubspec.yaml')) ..createSync(recursive: true) @@ -214,7 +258,7 @@ void main() { expect( (result.content.single as TextContent).text, - contains('Unsupported pub command `publish`.'), + contains('String "publish" is not one of the allowed values:'), ); expect(testProcessManager.commandsRan, isEmpty); }); From be8bcebd3731bd6b13abdebaf54f8f83f2029641 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Wed, 3 Sep 2025 14:32:05 -0700 Subject: [PATCH 4/6] Bump up retries for analyzer in multiple roots --- pkgs/dart_mcp_server/test/tools/analyzer_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/dart_mcp_server/test/tools/analyzer_test.dart b/pkgs/dart_mcp_server/test/tools/analyzer_test.dart index 14397c1c..86e548f0 100644 --- a/pkgs/dart_mcp_server/test/tools/analyzer_test.dart +++ b/pkgs/dart_mcp_server/test/tools/analyzer_test.dart @@ -309,7 +309,7 @@ void main() { ], }, ); - final result = await testHarness.callToolWithRetry(request); + final result = await testHarness.callToolWithRetry(request, maxTries: 10); expect(result.isError, isNot(true)); expect(result.content, hasLength(2)); expect( From a7726cc8f4e77037303062553df433737db7e5fe Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Wed, 3 Sep 2025 14:41:05 -0700 Subject: [PATCH 5/6] Update CHANGELOG.md --- pkgs/dart_mcp_server/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/dart_mcp_server/CHANGELOG.md b/pkgs/dart_mcp_server/CHANGELOG.md index ebbc5abf..d5fb6d05 100644 --- a/pkgs/dart_mcp_server/CHANGELOG.md +++ b/pkgs/dart_mcp_server/CHANGELOG.md @@ -14,6 +14,7 @@ * Add an `--exclude-tool` command line flag to exclude tools by name. * Add the abillity to limit the output of `analyze_files` to a set of paths. * Stop reporting non-zero exit codes from command line tools as tool errors. +* Add descriptions for pub tools, add support for `pub deps` and `pub outdated`. # 0.1.0 (Dart SDK 3.9.0) From e26de687bca8129e00a077f49d9a5e84f669c11a Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Thu, 4 Sep 2025 13:28:29 -0700 Subject: [PATCH 6/6] Eliminate list of available commands from description --- pkgs/dart_mcp_server/lib/src/mixins/pub.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/pub.dart b/pkgs/dart_mcp_server/lib/src/mixins/pub.dart index 96475432..6b71d632 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/pub.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/pub.dart @@ -91,9 +91,7 @@ base mixin PubSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport enumValues: SupportedPubCommand.values .map((e) => e.name) .toList(), - description: - 'Only ${SupportedPubCommand.listAll} are supported.\n' - '${SupportedPubCommand.commandDescriptions}', + description: SupportedPubCommand.commandDescriptions, ), ParameterNames.packageNames: Schema.list( title: 'The package names to run the command for.', @@ -174,7 +172,7 @@ enum SupportedPubCommand { } static String get commandDescriptions { - return _getDescriptions(values); + return 'Available subcommands:\n${_getDescriptions(values)}'; } static String _getDescriptions(Iterable commands) {