Skip to content

Commit ee5b2b2

Browse files
authored
Stop reporting errors for non-zero exits (#262)
This stops reporting command line tools that return non-zero exit codes as "isError" failures of the tool, so that the LLM won't interpret failed tests or formatting of files as a failure to run the tool.
1 parent 6b4b2bc commit ee5b2b2

File tree

4 files changed

+34
-40
lines changed

4 files changed

+34
-40
lines changed

pkgs/dart_mcp_server/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
based on their text values.
1414
* Add an `--exclude-tool` command line flag to exclude tools by name.
1515
* Add the abillity to limit the output of `analyze_files` to a set of paths.
16+
* Stop reporting non-zero exit codes from command line tools as tool errors.
1617

1718
# 0.1.0 (Dart SDK 3.9.0)
1819

pkgs/dart_mcp_server/lib/src/utils/analytics.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ enum CallToolFailureReason {
130130
noRootGiven,
131131
noRootsSet,
132132
noSuchCommand,
133-
nonZeroExitCode,
134133
webSocketException,
135134
}
136135

pkgs/dart_mcp_server/lib/src/utils/cli_utils.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,14 @@ Future<CallToolResult> runCommandInRoot(
238238
content: [
239239
TextContent(
240240
text:
241-
'$commandDescription failed in ${projectRoot.path}:\n'
241+
'$commandDescription returned a non-zero exit code in '
242+
'${projectRoot.path}:\n'
242243
'$output${errors.isEmpty ? '' : '\nErrors:\n$errors'}',
243244
),
245+
// Returning a non-zero exit code is not considered an "error" in the
246+
// "isError" sense.
244247
],
245-
isError: true,
246-
)..failureReason ??= CallToolFailureReason.nonZeroExitCode;
248+
);
247249
}
248250
return CallToolResult(
249251
content: [

pkgs/dart_mcp_server/test/dart_tooling_mcp_server_test.dart

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,43 +60,35 @@ void main() {
6060
});
6161

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

66-
final tool = Tool(
67-
name: 'hello${reason?.name ?? ''}',
68-
inputSchema: Schema.object(),
69-
);
70-
server.registerTool(
71-
tool,
72-
(_) =>
73-
CallToolResult(isError: true, content: [])
74-
..failureReason = reason,
75-
);
76-
final result = await testHarness.mcpServerConnection.callTool(
77-
CallToolRequest(name: tool.name),
78-
);
79-
expect(result.isError, true);
80-
expect(
81-
analytics.sentEvents.single,
82-
isA<Event>()
83-
.having((e) => e.eventName, 'eventName', DashEvent.dartMCPEvent)
84-
.having(
85-
(e) => e.eventData,
86-
'eventData',
87-
equals({
88-
'client': server.clientInfo.name,
89-
'clientVersion': server.clientInfo.version,
90-
'serverVersion': server.implementation.version,
91-
'type': AnalyticsEvent.callTool.name,
92-
'tool': tool.name,
93-
'success': false,
94-
'elapsedMilliseconds': isA<int>(),
95-
'failureReason': ?reason?.name,
96-
}),
97-
),
98-
);
99-
}
65+
final tool = Tool(name: 'hello', inputSchema: Schema.object());
66+
server.registerTool(
67+
tool,
68+
(_) => CallToolResult(isError: true, content: [])..failureReason = null,
69+
);
70+
final result = await testHarness.mcpServerConnection.callTool(
71+
CallToolRequest(name: tool.name),
72+
);
73+
expect(result.isError, true);
74+
expect(
75+
analytics.sentEvents.single,
76+
isA<Event>()
77+
.having((e) => e.eventName, 'eventName', DashEvent.dartMCPEvent)
78+
.having(
79+
(e) => e.eventData,
80+
'eventData',
81+
equals({
82+
'client': server.clientInfo.name,
83+
'clientVersion': server.clientInfo.version,
84+
'serverVersion': server.implementation.version,
85+
'type': AnalyticsEvent.callTool.name,
86+
'tool': tool.name,
87+
'success': false,
88+
'elapsedMilliseconds': isA<int>(),
89+
}),
90+
),
91+
);
10092
});
10193

10294
group('are sent for prompts', () {

0 commit comments

Comments
 (0)