From 053503e2b8a95e8d5809190940a3ad7c4b7fb693 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Mon, 9 Jun 2025 22:20:23 +0000 Subject: [PATCH] Support CLI arguments to the run_tests tool Add strong language to the `run_tests` tool description asserting it's use in favor of the CLI alternatives. Add support for forwarding arbitrary CLI arguments so the MCP version is equally powerful as the CLI versions. Check for a reporter argument specified by the client before assuming the failure only reporter should be used. This may allow a client to use the JSON reporter. --- .../lib/src/mixins/dash_cli.dart | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/dash_cli.dart b/pkgs/dart_mcp_server/lib/src/mixins/dash_cli.dart index a6f8bfc8..eaef352b 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/dash_cli.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/dash_cli.dart @@ -66,9 +66,19 @@ base mixin DashCliSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport /// Implementation of the [runTestsTool]. Future _runTests(CallToolRequest request) async { + final cliArgs = (request.arguments?['args'] as List?)?.cast(); + final hasReporterArg = + cliArgs?.any( + (a) => a == '-r' || a == '--reporter' || a.startsWith('--reporter='), + ) ?? + false; return runCommandInRoots( request, - arguments: ['test', '--reporter=failures-only'], + arguments: [ + 'test', + if (!hasReporterArg) '--reporter=failures-only', + ...?cliArgs, + ], commandDescription: 'dart|flutter test', processManager: processManager, knownRoots: await roots, @@ -187,14 +197,24 @@ base mixin DashCliSupport on ToolsSupport, LoggingSupport, RootsTrackingSupport ), ); - static final runTestsTool = Tool( - name: 'run_tests', - description: 'Runs Dart or Flutter tests for the given project roots.', - annotations: ToolAnnotations(title: 'Run tests', readOnlyHint: true), - inputSchema: Schema.object( - properties: {ParameterNames.roots: rootsSchema(supportsPaths: true)}, - ), - ); + static final Tool runTestsTool = () { + return Tool( + name: 'run_tests', + description: + 'Run Dart tests with an agent centric UX. ' + 'ALWAYS use instead of `dart test` or `flutter test` shell commands.', + annotations: ToolAnnotations(title: 'Run tests', readOnlyHint: true), + inputSchema: Schema.object( + properties: { + ParameterNames.roots: rootsSchema(supportsPaths: true), + 'args': Schema.list( + description: 'CLI arguments', + items: Schema.string(), + ), + }, + ), + ); + }(); static final createProjectTool = Tool( name: 'create_project',