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..6d585910 100644 --- a/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart +++ b/pkgs/dart_mcp_server/lib/src/mixins/dtd.dart @@ -12,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'; @@ -182,10 +183,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')], ); } } @@ -602,9 +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.', + '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()}, 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: