From 0026611276091a0667b41c1dd926ed4a6646e5df Mon Sep 17 00:00:00 2001 From: Luke Memet Date: Sun, 3 Aug 2025 15:02:31 -0400 Subject: [PATCH 1/3] Add diagnostics for DTD service detection failures - Log all registered DTD services when checking for ConnectedApp - Capture and log specific errors instead of silently swallowing exceptions - Add contextual error messages explaining possible causes - Track VM service retrieval failures separately - Make error messages dynamic based on actual failure reason --- pkgs/dart_mcp_server/lib/src/mixins/dtd.dart | 92 +++++++++++++++----- 1 file changed, 69 insertions(+), 23 deletions(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart index 044af1a2..45090fb4 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart @@ -42,6 +42,12 @@ base mixin DartToolingDaemonSupport /// Once we connect to dtd, this may be toggled to `true`. bool _connectedAppServiceIsSupported = false; + /// Stores service detection errors for diagnostic purposes. + String? _serviceDetectionError; + + /// Stores the last error from getVmServices for diagnostic purposes. + String? _vmServicesError; + /// Whether to await the disposal of all [VmService] objects in /// [activeVmServices] upon server shutdown or loss of DTD connection. /// @@ -68,6 +74,8 @@ base mixin DartToolingDaemonSupport _dtd = null; _activeLocation = null; _connectedAppServiceIsSupported = false; + _serviceDetectionError = null; + _vmServicesError = null; // TODO: determine whether we need to dispose the [inspectorObjectGroup] on // the Flutter Widget Inspector for each VM service instance. @@ -88,8 +96,23 @@ base mixin DartToolingDaemonSupport if (dtd == null) return; if (!_connectedAppServiceIsSupported) return; - final vmServiceInfos = (await dtd.getVmServices()).vmServicesInfos; - if (vmServiceInfos.isEmpty) return; + List vmServiceInfos; + try { + vmServiceInfos = (await dtd.getVmServices()).vmServicesInfos; + _vmServicesError = null; + log(LoggingLevel.debug, + 'Found ${vmServiceInfos.length} VM service(s)'); + } catch (e, stack) { + _vmServicesError = 'Failed to get VM services: $e'; + log(LoggingLevel.error, _vmServicesError!); + log(LoggingLevel.debug, 'Stack trace: $stack'); + return; + } + if (vmServiceInfos.isEmpty) { + _vmServicesError = 'No VM services available'; + log(LoggingLevel.warning, _vmServicesError!); + return; + } for (final vmServiceInfo in vmServiceInfos) { final vmServiceUri = vmServiceInfo.uri; @@ -262,15 +285,26 @@ base mixin DartToolingDaemonSupport final dtd = _dtd!; _connectedAppServiceIsSupported = false; + _serviceDetectionError = null; try { final registeredServices = await dtd.getRegisteredServices(); - if (registeredServices.dtdServices.contains( - '${ConnectedAppServiceConstants.serviceName}.' - '${ConnectedAppServiceConstants.getVmServices}', - )) { + log(LoggingLevel.debug, + 'Registered DTD services: ${registeredServices.dtdServices}'); + final expectedService = '${ConnectedAppServiceConstants.serviceName}.' + '${ConnectedAppServiceConstants.getVmServices}'; + if (registeredServices.dtdServices.contains(expectedService)) { _connectedAppServiceIsSupported = true; + log(LoggingLevel.debug, 'ConnectedApp service detected successfully'); + } else { + _serviceDetectionError = + 'Service "$expectedService" not found in registered services'; + log(LoggingLevel.warning, _serviceDetectionError!); } - } catch (_) {} + } catch (e, stack) { + _serviceDetectionError = 'Failed to get registered services: $e'; + log(LoggingLevel.error, _serviceDetectionError!); + log(LoggingLevel.debug, 'Stack trace: $stack'); + } if (_connectedAppServiceIsSupported) { await _listenForConnectedAppServiceEvents(); @@ -997,16 +1031,21 @@ base mixin DartToolingDaemonSupport inputSchema: Schema.object(), ); - static final _connectedAppsNotSupported = CallToolResult( - isError: true, - content: [ - TextContent( - text: - 'A Dart SDK of version 3.9.0-163.0.dev or greater is required to ' - 'connect to Dart and Flutter applications.', - ), - ], - )..failureReason = CallToolFailureReason.connectedAppServiceNotSupported; + CallToolResult get _connectedAppsNotSupported { + String errorText; + if (_serviceDetectionError != null) { + errorText = 'ConnectedApp service not available: $_serviceDetectionError'; + } else { + errorText = + 'A Dart SDK of version 3.9.0-163.0.dev or greater is required to ' + 'connect to Dart and Flutter applications.'; + } + + return CallToolResult( + isError: true, + content: [TextContent(text: errorText)], + )..failureReason = CallToolFailureReason.connectedAppServiceNotSupported; + } static final _dtdNotConnected = CallToolResult( isError: true, @@ -1030,12 +1069,19 @@ base mixin DartToolingDaemonSupport ], )..failureReason = CallToolFailureReason.dtdAlreadyConnected; - static final _noActiveDebugSession = CallToolResult( - content: [ - TextContent(text: 'No active debug session to take a screenshot'), - ], - isError: true, - )..failureReason = CallToolFailureReason.noActiveDebugSession; + CallToolResult get _noActiveDebugSession { + var errorText = 'No VM services available'; + if (_vmServicesError != null) { + errorText += ': $_vmServicesError'; + } else if (_serviceDetectionError != null) { + errorText += ' (service detection failed: $_serviceDetectionError)'; + } + + return CallToolResult( + content: [TextContent(text: errorText)], + isError: true, + )..failureReason = CallToolFailureReason.noActiveDebugSession; + } static final _flutterDriverNotRegistered = CallToolResult( content: [ From 9eb89259439bc53162e987e19207293950218b22 Mon Sep 17 00:00:00 2001 From: Luke Memet Date: Thu, 7 Aug 2025 12:18:52 -0400 Subject: [PATCH 2/3] dart format --- pkgs/dart_mcp_server/lib/src/mixins/dtd.dart | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart index 45090fb4..a5445ad0 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart @@ -44,7 +44,7 @@ base mixin DartToolingDaemonSupport /// Stores service detection errors for diagnostic purposes. String? _serviceDetectionError; - + /// Stores the last error from getVmServices for diagnostic purposes. String? _vmServicesError; @@ -100,8 +100,7 @@ base mixin DartToolingDaemonSupport try { vmServiceInfos = (await dtd.getVmServices()).vmServicesInfos; _vmServicesError = null; - log(LoggingLevel.debug, - 'Found ${vmServiceInfos.length} VM service(s)'); + log(LoggingLevel.debug, 'Found ${vmServiceInfos.length} VM service(s)'); } catch (e, stack) { _vmServicesError = 'Failed to get VM services: $e'; log(LoggingLevel.error, _vmServicesError!); @@ -288,9 +287,12 @@ base mixin DartToolingDaemonSupport _serviceDetectionError = null; try { final registeredServices = await dtd.getRegisteredServices(); - log(LoggingLevel.debug, - 'Registered DTD services: ${registeredServices.dtdServices}'); - final expectedService = '${ConnectedAppServiceConstants.serviceName}.' + log( + LoggingLevel.debug, + 'Registered DTD services: ${registeredServices.dtdServices}', + ); + final expectedService = + '${ConnectedAppServiceConstants.serviceName}.' '${ConnectedAppServiceConstants.getVmServices}'; if (registeredServices.dtdServices.contains(expectedService)) { _connectedAppServiceIsSupported = true; @@ -1040,7 +1042,7 @@ base mixin DartToolingDaemonSupport 'A Dart SDK of version 3.9.0-163.0.dev or greater is required to ' 'connect to Dart and Flutter applications.'; } - + return CallToolResult( isError: true, content: [TextContent(text: errorText)], @@ -1076,7 +1078,7 @@ base mixin DartToolingDaemonSupport } else if (_serviceDetectionError != null) { errorText += ' (service detection failed: $_serviceDetectionError)'; } - + return CallToolResult( content: [TextContent(text: errorText)], isError: true, From a91675f89234f69b147b17b12466d5978e8b56e8 Mon Sep 17 00:00:00 2001 From: Luke Memet Date: Fri, 8 Aug 2025 19:56:08 -0400 Subject: [PATCH 3/3] Include SDK version requirement in all ConnectedApp error messages --- pkgs/dart_mcp_server/lib/src/mixins/dtd.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart index a5445ad0..dcbdf78e 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart @@ -1036,7 +1036,9 @@ base mixin DartToolingDaemonSupport CallToolResult get _connectedAppsNotSupported { String errorText; if (_serviceDetectionError != null) { - errorText = 'ConnectedApp service not available: $_serviceDetectionError'; + errorText = 'ConnectedApp service not available: $_serviceDetectionError. ' + 'A Dart SDK of version 3.9.0-163.0.dev or greater is required to ' + 'connect to Dart and Flutter applications.'; } else { errorText = 'A Dart SDK of version 3.9.0-163.0.dev or greater is required to '