From 0965c3f733f0ec6a6f99ff9553ab1fc88fe80cfb Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Wed, 18 Jun 2025 16:50:43 +0000 Subject: [PATCH 1/3] improve tool description for the dtd connection tool and improve error messages --- pkgs/dart_mcp_server/CHANGELOG.md | 1 + pkgs/dart_mcp_server/lib/src/mixins/dtd.dart | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkgs/dart_mcp_server/CHANGELOG.md b/pkgs/dart_mcp_server/CHANGELOG.md index 83c27103..32429e8d 100644 --- a/pkgs/dart_mcp_server/CHANGELOG.md +++ b/pkgs/dart_mcp_server/CHANGELOG.md @@ -40,3 +40,4 @@ * Instruct clients to prefer MCP tools over running tools in the shell. * Reduce output size of `run_tests` tool to save on input tokens. * Add `--log-file` argument to log all protocol traffic to a file. +* Improve error text for failed DTD connections as well as the tool description. diff --git a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart index 1dfffe44..7c21b3fa 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart @@ -4,6 +4,8 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:ffi'; +import 'dart:io'; import 'package:dart_mcp/server.dart'; import 'package:dds_service_extensions/dds_service_extensions.dart'; @@ -182,10 +184,19 @@ base mixin DartToolingDaemonSupport return CallToolResult( content: [TextContent(text: 'Connection succeeded')], ); + } on WebSocketException catch (_) { + return CallToolResult( + isError: true, + content: [ + Content.text( + text: 'Connection failed, make sure your DTD Uri is up to date.', + ), + ], + ); } catch (e) { return CallToolResult( isError: true, - content: [TextContent(text: 'Connection failed: $e')], + content: [Content.text(text: 'Connection failed: $e')], ); } } @@ -604,7 +615,8 @@ base mixin DartToolingDaemonSupport description: 'Connects to the Dart Tooling Daemon. You should ask the user for the ' 'dart tooling daemon URI, and suggest the "Copy DTD Uri to clipboard" ' - 'command. Do not just make up a random URI to pass.', + 'command. Do not just make up a random URI to pass. When reconnecting ' + 'to DTD after losing a connection, always request a new DTD Uri first.', annotations: ToolAnnotations(title: 'Connect to DTD', readOnlyHint: true), inputSchema: Schema.object( properties: {ParameterNames.uri: Schema.string()}, From 6c49d6bf843cecadbc930c1e699d767d06af3378 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Wed, 18 Jun 2025 17:20:25 +0000 Subject: [PATCH 2/3] use the WebSocketException from package:web_socket --- pkgs/dart_mcp_server/lib/src/mixins/dtd.dart | 3 +-- pkgs/dart_mcp_server/pubspec.yaml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart index 7c21b3fa..0f7a4175 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart @@ -4,8 +4,6 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:ffi'; -import 'dart:io'; import 'package:dart_mcp/server.dart'; import 'package:dds_service_extensions/dds_service_extensions.dart'; @@ -14,6 +12,7 @@ import 'package:json_rpc_2/json_rpc_2.dart'; import 'package:meta/meta.dart'; import 'package:vm_service/vm_service.dart'; import 'package:vm_service/vm_service_io.dart'; +import 'package:web_socket/web_socket.dart'; import '../utils/constants.dart'; diff --git a/pkgs/dart_mcp_server/pubspec.yaml b/pkgs/dart_mcp_server/pubspec.yaml index b560d110..03e1aea4 100644 --- a/pkgs/dart_mcp_server/pubspec.yaml +++ b/pkgs/dart_mcp_server/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: stream_channel: ^2.1.4 vm_service: ^15.0.0 watcher: ^1.1.1 + web_socket: ^1.0.1 yaml: ^3.1.3 dev_dependencies: From bc8f4ae39788e6ed4ea30a3498c23fe891ffd49d Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Wed, 18 Jun 2025 17:24:40 +0000 Subject: [PATCH 3/3] refine the text more to promote tool invocations to get the URI --- pkgs/dart_mcp_server/lib/src/mixins/dtd.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart index 0f7a4175..6d585910 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart @@ -612,10 +612,11 @@ base mixin DartToolingDaemonSupport static final connectTool = Tool( name: 'connect_dart_tooling_daemon', description: - 'Connects to the Dart Tooling Daemon. You should ask the user for the ' - 'dart tooling daemon URI, and suggest the "Copy DTD Uri to clipboard" ' - 'command. Do not just make up a random URI to pass. When reconnecting ' - 'to DTD after losing a connection, always request a new DTD Uri first.', + 'Connects to the Dart Tooling Daemon. You should get the uri either ' + 'from available tools or the user, do not just make up a random URI to ' + 'pass. When asking the user for the uri, you should suggest the "Copy ' + 'DTD Uri to clipboard" action. Do . When reconnecting after losing a ' + 'connection, always request a new uri first.', annotations: ToolAnnotations(title: 'Connect to DTD', readOnlyHint: true), inputSchema: Schema.object( properties: {ParameterNames.uri: Schema.string()},