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
1 change: 1 addition & 0 deletions pkgs/dart_mcp_server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
based on their text values.
* 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.

# 0.1.0 (Dart SDK 3.9.0)

Expand Down
1 change: 0 additions & 1 deletion pkgs/dart_mcp_server/lib/src/utils/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ enum CallToolFailureReason {
noRootGiven,
noRootsSet,
noSuchCommand,
nonZeroExitCode,
webSocketException,
}

Expand Down
8 changes: 5 additions & 3 deletions pkgs/dart_mcp_server/lib/src/utils/cli_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ Future<CallToolResult> runCommandInRoot(
content: [
TextContent(
text:
'$commandDescription failed in ${projectRoot.path}:\n'
'$commandDescription returned a non-zero exit code in '
'${projectRoot.path}:\n'
'$output${errors.isEmpty ? '' : '\nErrors:\n$errors'}',
),
// Returning a non-zero exit code is not considered an "error" in the
// "isError" sense.
],
isError: true,
)..failureReason ??= CallToolFailureReason.nonZeroExitCode;
);
}
return CallToolResult(
content: [
Expand Down
64 changes: 28 additions & 36 deletions pkgs/dart_mcp_server/test/dart_tooling_mcp_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,43 +60,35 @@ void main() {
});

test('sends analytics for failed tool calls', () async {
for (var reason in [null, CallToolFailureReason.nonZeroExitCode]) {
analytics.sentEvents.clear();
analytics.sentEvents.clear();

final tool = Tool(
name: 'hello${reason?.name ?? ''}',
inputSchema: Schema.object(),
);
server.registerTool(
tool,
(_) =>
CallToolResult(isError: true, content: [])
..failureReason = reason,
);
final result = await testHarness.mcpServerConnection.callTool(
CallToolRequest(name: tool.name),
);
expect(result.isError, true);
expect(
analytics.sentEvents.single,
isA<Event>()
.having((e) => e.eventName, 'eventName', DashEvent.dartMCPEvent)
.having(
(e) => e.eventData,
'eventData',
equals({
'client': server.clientInfo.name,
'clientVersion': server.clientInfo.version,
'serverVersion': server.implementation.version,
'type': AnalyticsEvent.callTool.name,
'tool': tool.name,
'success': false,
'elapsedMilliseconds': isA<int>(),
'failureReason': ?reason?.name,
}),
),
);
}
final tool = Tool(name: 'hello', inputSchema: Schema.object());
server.registerTool(
tool,
(_) => CallToolResult(isError: true, content: [])..failureReason = null,
);
final result = await testHarness.mcpServerConnection.callTool(
CallToolRequest(name: tool.name),
);
expect(result.isError, true);
expect(
analytics.sentEvents.single,
isA<Event>()
.having((e) => e.eventName, 'eventName', DashEvent.dartMCPEvent)
.having(
(e) => e.eventData,
'eventData',
equals({
'client': server.clientInfo.name,
'clientVersion': server.clientInfo.version,
'serverVersion': server.implementation.version,
'type': AnalyticsEvent.callTool.name,
'tool': tool.name,
'success': false,
'elapsedMilliseconds': isA<int>(),
}),
),
);
});

group('are sent for prompts', () {
Expand Down
Loading