Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/src/mcp/mcp_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ If is omitted, then core will be selected.
description: 'Run tests in a Dart or Flutter project.',
inputSchema: ObjectSchema(
properties: {
'directory': StringSchema(
description:
'Target directory path (defaults to current directory). '
'Can be absolute or relative path to project root.',
),
'dart': BooleanSchema(
description:
'''Whether to run Dart tests. If not specified, Flutter tests will be run if a Flutter project is detected.''',
Expand Down Expand Up @@ -319,6 +324,9 @@ Only one value can be selected.
List<String> _parseTest(Map<String, Object?> args) {
final cliArgs = <String>[if (args['dart'] == true) 'dart', 'test'];

if (args['directory'] != null) {
cliArgs.add(args['directory']! as String);
}
if (args['coverage'] == true) {
cliArgs.add('--coverage');
}
Expand Down Expand Up @@ -464,9 +472,7 @@ Only one value can be selected.

if (exitCode == ExitCode.success.code) {
return CallToolResult(
content: [
TextContent(text: '"$toolName" completed successfully.'),
],
content: [TextContent(text: '"$toolName" completed successfully.')],
isError: false,
);
}
Expand Down
44 changes: 36 additions & 8 deletions test/src/mcp/mcp_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ void main() {
),
);
registerFallbackValue(
CallToolRequest(
name: 'dummyTool',
arguments: const {},
),
CallToolRequest(name: 'dummyTool', arguments: const {}),
);

when(
Expand Down Expand Up @@ -301,10 +298,7 @@ void main() {
await sendRequest(
CallToolRequest.methodName,
_params(
CallToolRequest(
name: 'test',
arguments: {'optimization': false},
),
CallToolRequest(name: 'test', arguments: {'optimization': false}),
),
);

Expand Down Expand Up @@ -376,6 +370,40 @@ void main() {
]);
});

test('passes directory as positional argument', () async {
await sendRequest(
CallToolRequest.methodName,
_params(
CallToolRequest(
name: 'test',
arguments: {'directory': 'my_dir'},
),
),
);

final capturedArgs =
verify(() => mockCommandRunner.run(captureAny())).captured.first
as List<String>;
expect(capturedArgs, ['test', 'my_dir']);
});

test('passes directory as positional argument with dart flag', () async {
await sendRequest(
CallToolRequest.methodName,
_params(
CallToolRequest(
name: 'test',
arguments: {'directory': 'my_dir', 'dart': true},
),
),
);

final capturedArgs =
verify(() => mockCommandRunner.run(captureAny())).captured.first
as List<String>;
expect(capturedArgs, ['dart', 'test', 'my_dir']);
});

test('handles command failure', () async {
when(
() => mockCommandRunner.run(any()),
Expand Down
Loading