From 88a16c52c2ce1cadf31993823ec524bd3d1b2b54 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Mon, 21 Jul 2025 17:10:29 +0000 Subject: [PATCH] rename ElicitationHandler.reject to ElicitationHandler.decline --- pkgs/dart_mcp/CHANGELOG.md | 7 +++++++ pkgs/dart_mcp/example/elicitations_client.dart | 4 ++-- pkgs/dart_mcp/example/elicitations_server.dart | 4 ++-- pkgs/dart_mcp/lib/src/api/elicitation.dart | 16 ++++++++++++---- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pkgs/dart_mcp/CHANGELOG.md b/pkgs/dart_mcp/CHANGELOG.md index fd4ba063..a7ab42a9 100644 --- a/pkgs/dart_mcp/CHANGELOG.md +++ b/pkgs/dart_mcp/CHANGELOG.md @@ -1,6 +1,13 @@ ## 0.3.3-wip - Fix `PingRequest` handling when it is sent from a non-Dart client. +- Deprecate `ElicitationAction.reject` and replace it with + `ElicitationAction.decline`. + - In the initial elicitations schema this was incorrectly listed as `reject`. + - This package still allows `reject` and treats it as an alias for`decline`. + - The old `reject` enum value was replaced with a static constant equal + exactly to `decline`, so switches are not affected. + ## 0.3.2 diff --git a/pkgs/dart_mcp/example/elicitations_client.dart b/pkgs/dart_mcp/example/elicitations_client.dart index 05d1c1d3..4436056c 100644 --- a/pkgs/dart_mcp/example/elicitations_client.dart +++ b/pkgs/dart_mcp/example/elicitations_client.dart @@ -67,12 +67,12 @@ final class TestMCPClientWithElicitationSupport extends MCPClient print(''' Elicitation received from server: ${request.message} -Do you want to accept (a), reject (r), or cancel (c) the elicitation? +Do you want to accept (a), decline (d), or cancel (c) the elicitation? '''); final answer = stdin.readLineSync(); final action = switch (answer) { 'a' => ElicitationAction.accept, - 'r' => ElicitationAction.reject, + 'd' => ElicitationAction.decline, 'c' => ElicitationAction.cancel, _ => throw ArgumentError('Invalid answer: $answer'), }; diff --git a/pkgs/dart_mcp/example/elicitations_server.dart b/pkgs/dart_mcp/example/elicitations_server.dart index 0fa7cac6..bee8425c 100644 --- a/pkgs/dart_mcp/example/elicitations_server.dart +++ b/pkgs/dart_mcp/example/elicitations_server.dart @@ -56,8 +56,8 @@ base class MCPServerWithElicitation extends MCPServer 'Hello $name! I see that you are $age years ' 'old and identify as $gender', ); - case ElicitationAction.reject: - log(LoggingLevel.warning, 'Request for name was rejected'); + case ElicitationAction.decline: + log(LoggingLevel.warning, 'Request for name was declined'); case ElicitationAction.cancel: log(LoggingLevel.warning, 'Request for name was cancelled'); } diff --git a/pkgs/dart_mcp/lib/src/api/elicitation.dart b/pkgs/dart_mcp/lib/src/api/elicitation.dart index 4d5c1cf4..834167a5 100644 --- a/pkgs/dart_mcp/lib/src/api/elicitation.dart +++ b/pkgs/dart_mcp/lib/src/api/elicitation.dart @@ -105,14 +105,19 @@ extension type ElicitResult.fromMap(Map _value) /// /// - [ElicitationAction.accept]: The user accepted the request and provided /// the requested information. - /// - [ElicitationAction.reject]: The user explicitly declined the action. + /// - [ElicitationAction.decline]: The user explicitly declined the action. /// - [ElicitationAction.cancel]: The user dismissed without making an /// explicit choice. ElicitationAction get action { - final action = _value['action'] as String?; + var action = _value['action'] as String?; if (action == null) { throw ArgumentError('Missing required action field in $ElicitResult'); } + // There was a bug in the initial schema, where the `decline` action was + // named `reject` instead. Handle using that as an alias for `decline` in + // case some clients use the old name. + if (action == 'reject') action = 'decline'; + return ElicitationAction.values.byName(action); } @@ -131,8 +136,11 @@ enum ElicitationAction { accept, /// The user explicitly declined the action. - reject, + decline, /// The user dismissed without making an explicit choice. - cancel, + cancel; + + @Deprecated('Use `ElicitationAction.decline` instead.') + static const reject = decline; }