From 1e4b8cad39bc07c02574fd6dea452ec0d680881b Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 17 Jun 2025 16:51:36 +0000 Subject: [PATCH 1/7] add events for dart mcp server tool invocations --- pkgs/unified_analytics/lib/src/enums.dart | 5 +++++ pkgs/unified_analytics/lib/src/event.dart | 25 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pkgs/unified_analytics/lib/src/enums.dart b/pkgs/unified_analytics/lib/src/enums.dart index eff8205a5..63f5a356f 100644 --- a/pkgs/unified_analytics/lib/src/enums.dart +++ b/pkgs/unified_analytics/lib/src/enums.dart @@ -55,6 +55,11 @@ enum DashEvent { description: 'Pub package resolution details', toolOwner: DashTool.dartTool, ), + dartMcpToolEvent( + label: 'dart_mcp_tool', + description: 'Information for a Dart MCP tool invocation', + toolOwner: DashTool.dartTool, + ), // Events for Flutter devtools diff --git a/pkgs/unified_analytics/lib/src/event.dart b/pkgs/unified_analytics/lib/src/event.dart index 0071ebd84..08b3d4942 100644 --- a/pkgs/unified_analytics/lib/src/event.dart +++ b/pkgs/unified_analytics/lib/src/event.dart @@ -905,6 +905,31 @@ final class Event { }, ); + /// Event that is sent from the Dart MCP server when a tool is invoked. + /// + /// The [tool] is the name of the tool that was invoked. + /// + /// If [success] is `true`, it indicates the tool was successfully invoked, + /// specifically this corresponds to the `isError` field on the tool result. + /// + /// The [elapsedMilliseconds] is the total time from when the tool call was + /// received by the server, to when the response was initiated by the server. + /// This does not measure the total round trip time, just the time spent in + /// the servers own handling of requests. It includes time spent handling + /// any other asynchronous tasks as well. + Event.dartMcpTool({ + required String tool, + required bool success, + required int elapsedMilliseconds, + }) : this._( + eventName: DashEvent.dartMcpToolEvent, + eventData: { + 'tool': tool, + 'success': success, + 'elapsedMilliseconds': elapsedMilliseconds, + }, + ); + @override int get hashCode => Object.hash(eventName, jsonEncode(eventData)); From 04bcae1484c4b202879bacd02ee850b9ee4c6bad Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 17 Jun 2025 19:29:31 +0000 Subject: [PATCH 2/7] add client and clientVersion fields --- pkgs/unified_analytics/lib/src/event.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/unified_analytics/lib/src/event.dart b/pkgs/unified_analytics/lib/src/event.dart index 08b3d4942..00432c69c 100644 --- a/pkgs/unified_analytics/lib/src/event.dart +++ b/pkgs/unified_analytics/lib/src/event.dart @@ -909,6 +909,9 @@ final class Event { /// /// The [tool] is the name of the tool that was invoked. /// + /// The [client] is the name of the client, as given when it connected to the + /// MCP server, and [clientVersion] is the version of the client. + /// /// If [success] is `true`, it indicates the tool was successfully invoked, /// specifically this corresponds to the `isError` field on the tool result. /// @@ -919,12 +922,16 @@ final class Event { /// any other asynchronous tasks as well. Event.dartMcpTool({ required String tool, + required String client, + required String clientVersion, required bool success, required int elapsedMilliseconds, }) : this._( eventName: DashEvent.dartMcpToolEvent, eventData: { 'tool': tool, + 'client': client, + 'clientVersion': clientVersion, 'success': success, 'elapsedMilliseconds': elapsedMilliseconds, }, From 941da2bd5eaf1d76a531099d0c4c00b75a7e3764 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 17 Jun 2025 20:37:55 +0000 Subject: [PATCH 3/7] make the event generic --- pkgs/unified_analytics/lib/src/event.dart | 26 +++++++++-------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/pkgs/unified_analytics/lib/src/event.dart b/pkgs/unified_analytics/lib/src/event.dart index 00432c69c..782e9d979 100644 --- a/pkgs/unified_analytics/lib/src/event.dart +++ b/pkgs/unified_analytics/lib/src/event.dart @@ -907,33 +907,27 @@ final class Event { /// Event that is sent from the Dart MCP server when a tool is invoked. /// - /// The [tool] is the name of the tool that was invoked. - /// /// The [client] is the name of the client, as given when it connected to the /// MCP server, and [clientVersion] is the version of the client. /// - /// If [success] is `true`, it indicates the tool was successfully invoked, - /// specifically this corresponds to the `isError` field on the tool result. + /// The [serverVersion] is the version of the Dart MCP server. /// - /// The [elapsedMilliseconds] is the total time from when the tool call was - /// received by the server, to when the response was initiated by the server. - /// This does not measure the total round trip time, just the time spent in - /// the servers own handling of requests. It includes time spent handling - /// any other asynchronous tasks as well. - Event.dartMcpTool({ - required String tool, + /// The [type] identifies the kind of event this is, and [eventData] is the + /// actual data for that event. + Event.dartMCPEvent({ required String client, required String clientVersion, - required bool success, - required int elapsedMilliseconds, + required String serverVersion, + required String type, + required Map eventData, }) : this._( eventName: DashEvent.dartMcpToolEvent, eventData: { - 'tool': tool, 'client': client, 'clientVersion': clientVersion, - 'success': success, - 'elapsedMilliseconds': elapsedMilliseconds, + 'serverVersion': serverVersion, + 'type': type, + 'eventData': eventData, }, ); From 46c958c95ea6ed8bc99373053319f24dd3114a20 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 17 Jun 2025 21:12:20 +0000 Subject: [PATCH 4/7] rename the event enum as well --- pkgs/unified_analytics/lib/src/enums.dart | 6 +++--- pkgs/unified_analytics/lib/src/event.dart | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/unified_analytics/lib/src/enums.dart b/pkgs/unified_analytics/lib/src/enums.dart index 63f5a356f..b051e8487 100644 --- a/pkgs/unified_analytics/lib/src/enums.dart +++ b/pkgs/unified_analytics/lib/src/enums.dart @@ -55,9 +55,9 @@ enum DashEvent { description: 'Pub package resolution details', toolOwner: DashTool.dartTool, ), - dartMcpToolEvent( - label: 'dart_mcp_tool', - description: 'Information for a Dart MCP tool invocation', + dartMCPEvent( + label: 'dart_mcp_server', + description: 'Information for a Dart MCP server event', toolOwner: DashTool.dartTool, ), diff --git a/pkgs/unified_analytics/lib/src/event.dart b/pkgs/unified_analytics/lib/src/event.dart index 782e9d979..88bfcbb52 100644 --- a/pkgs/unified_analytics/lib/src/event.dart +++ b/pkgs/unified_analytics/lib/src/event.dart @@ -921,7 +921,7 @@ final class Event { required String type, required Map eventData, }) : this._( - eventName: DashEvent.dartMcpToolEvent, + eventName: DashEvent.dartMCPEvent, eventData: { 'client': client, 'clientVersion': clientVersion, From ea3342954727f648bb98664df6f3db8af2cedcda Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Tue, 17 Jun 2025 21:40:58 +0000 Subject: [PATCH 5/7] inline the additional data directly into the parent map --- pkgs/unified_analytics/lib/src/event.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/unified_analytics/lib/src/event.dart b/pkgs/unified_analytics/lib/src/event.dart index 88bfcbb52..b1966785a 100644 --- a/pkgs/unified_analytics/lib/src/event.dart +++ b/pkgs/unified_analytics/lib/src/event.dart @@ -919,7 +919,7 @@ final class Event { required String clientVersion, required String serverVersion, required String type, - required Map eventData, + CustomMetrics? additionalData, }) : this._( eventName: DashEvent.dartMCPEvent, eventData: { @@ -927,7 +927,7 @@ final class Event { 'clientVersion': clientVersion, 'serverVersion': serverVersion, 'type': type, - 'eventData': eventData, + ...?additionalData?.toMap(), }, ); From 9851ce670e34bcec64f587a6968a74499660e9ad Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 23 Jun 2025 15:24:47 +0000 Subject: [PATCH 6/7] add pubspec version, changelog, and test --- pkgs/unified_analytics/CHANGELOG.md | 3 +++ pkgs/unified_analytics/lib/src/constants.dart | 2 +- pkgs/unified_analytics/pubspec.yaml | 2 +- pkgs/unified_analytics/test/event_test.dart | 23 ++++++++++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index 3d4c4f278..e5c26c902 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -1,3 +1,6 @@ +## 8.0.2 +- Added `Event.dartMCPEvent` for events from the `dart mcp-server` command. + ## 8.0.1 - Added `Event.flutterInjectDarwinPlugins` event for plugins injected into an iOS/macOS project. diff --git a/pkgs/unified_analytics/lib/src/constants.dart b/pkgs/unified_analytics/lib/src/constants.dart index c6ba7496e..3d472ea0e 100644 --- a/pkgs/unified_analytics/lib/src/constants.dart +++ b/pkgs/unified_analytics/lib/src/constants.dart @@ -87,7 +87,7 @@ const int kMaxLogFileSize = 25 * (1 << 20); const String kLogFileName = 'dart-flutter-telemetry.log'; /// The current version of the package, should be in line with pubspec version. -const String kPackageVersion = '8.0.1'; +const String kPackageVersion = '8.0.2'; /// The minimum length for a session. const int kSessionDurationMinutes = 30; diff --git a/pkgs/unified_analytics/pubspec.yaml b/pkgs/unified_analytics/pubspec.yaml index 8bba46243..94b3fe901 100644 --- a/pkgs/unified_analytics/pubspec.yaml +++ b/pkgs/unified_analytics/pubspec.yaml @@ -5,7 +5,7 @@ description: >- # LINT.IfChange # When updating this, keep the version consistent with the changelog and the # value in lib/src/constants.dart. -version: 8.0.1 +version: 8.0.2 # LINT.ThenChange(lib/src/constants.dart) repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics diff --git a/pkgs/unified_analytics/test/event_test.dart b/pkgs/unified_analytics/test/event_test.dart index e8a9f5696..9c4a99c0b 100644 --- a/pkgs/unified_analytics/test/event_test.dart +++ b/pkgs/unified_analytics/test/event_test.dart @@ -655,6 +655,27 @@ void main() { expect(constructedEvent.eventData.length, 20); }); + test('Event.dartMCPEvent constructed', () { + final event = Event.dartMCPEvent( + client: 'test client', + clientVersion: '1.0.0', + serverVersion: '1.1.0', + type: 'some_event', + additionalData: + _TestMetrics(boolField: true, stringField: 'hello', intField: 1)); + expect( + event.eventData, + equals({ + 'client': 'test client', + 'clientVersion': '1.0.0', + 'serverVersion': '1.1.0', + 'type': 'some_event', + 'boolField': true, + 'stringField': 'hello', + 'intField': 1, + })); + }); + test('Confirm all constructors were checked', () { var constructorCount = 0; for (final declaration in reflectClass(Event).declarations.keys) { @@ -667,7 +688,7 @@ void main() { // Change this integer below if your PR either adds or removes // an Event constructor - final eventsAccountedForInTests = 28; + final eventsAccountedForInTests = 29; expect(eventsAccountedForInTests, constructorCount, reason: 'If you added or removed an event constructor, ' 'ensure you have updated ' From 4d4df790f7ff8cbf4d3bbcfe0e20370bca6cf424 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 23 Jun 2025 22:15:47 +0000 Subject: [PATCH 7/7] update comment --- pkgs/unified_analytics/lib/src/event.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/unified_analytics/lib/src/event.dart b/pkgs/unified_analytics/lib/src/event.dart index b1966785a..7fcaad6f2 100644 --- a/pkgs/unified_analytics/lib/src/event.dart +++ b/pkgs/unified_analytics/lib/src/event.dart @@ -905,15 +905,15 @@ final class Event { }, ); - /// Event that is sent from the Dart MCP server when a tool is invoked. + /// An event that is sent from the Dart MCP server. /// /// The [client] is the name of the client, as given when it connected to the /// MCP server, and [clientVersion] is the version of the client. /// /// The [serverVersion] is the version of the Dart MCP server. /// - /// The [type] identifies the kind of event this is, and [eventData] is the - /// actual data for that event. + /// The [type] identifies the kind of event this is, and [additionalData] is + /// the actual data for the event. Event.dartMCPEvent({ required String client, required String clientVersion,