Skip to content

Commit 40607dc

Browse files
authored
rename ElicitationHandler.reject to ElicitationHandler.decline (#240)
There was initially a discrepancy between the Typescript and JSON schemas - looks like they reconciled that by going with the typescript version, so this aligns to that. I kept a deprecated constant called `reject` which is just the new `decline` one, which should be fully backwards compatible.
1 parent ec6efa4 commit 40607dc

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

pkgs/dart_mcp/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
## 0.3.3-wip
22

33
- Fix `PingRequest` handling when it is sent from a non-Dart client.
4+
- Deprecate `ElicitationAction.reject` and replace it with
5+
`ElicitationAction.decline`.
6+
- In the initial elicitations schema this was incorrectly listed as `reject`.
7+
- This package still allows `reject` and treats it as an alias for`decline`.
8+
- The old `reject` enum value was replaced with a static constant equal
9+
exactly to `decline`, so switches are not affected.
10+
411

512
## 0.3.2
613

pkgs/dart_mcp/example/elicitations_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ final class TestMCPClientWithElicitationSupport extends MCPClient
6767
print('''
6868
Elicitation received from server: ${request.message}
6969
70-
Do you want to accept (a), reject (r), or cancel (c) the elicitation?
70+
Do you want to accept (a), decline (d), or cancel (c) the elicitation?
7171
''');
7272
final answer = stdin.readLineSync();
7373
final action = switch (answer) {
7474
'a' => ElicitationAction.accept,
75-
'r' => ElicitationAction.reject,
75+
'd' => ElicitationAction.decline,
7676
'c' => ElicitationAction.cancel,
7777
_ => throw ArgumentError('Invalid answer: $answer'),
7878
};

pkgs/dart_mcp/example/elicitations_server.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ base class MCPServerWithElicitation extends MCPServer
5656
'Hello $name! I see that you are $age years '
5757
'old and identify as $gender',
5858
);
59-
case ElicitationAction.reject:
60-
log(LoggingLevel.warning, 'Request for name was rejected');
59+
case ElicitationAction.decline:
60+
log(LoggingLevel.warning, 'Request for name was declined');
6161
case ElicitationAction.cancel:
6262
log(LoggingLevel.warning, 'Request for name was cancelled');
6363
}

pkgs/dart_mcp/lib/src/api/elicitation.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,19 @@ extension type ElicitResult.fromMap(Map<String, Object?> _value)
105105
///
106106
/// - [ElicitationAction.accept]: The user accepted the request and provided
107107
/// the requested information.
108-
/// - [ElicitationAction.reject]: The user explicitly declined the action.
108+
/// - [ElicitationAction.decline]: The user explicitly declined the action.
109109
/// - [ElicitationAction.cancel]: The user dismissed without making an
110110
/// explicit choice.
111111
ElicitationAction get action {
112-
final action = _value['action'] as String?;
112+
var action = _value['action'] as String?;
113113
if (action == null) {
114114
throw ArgumentError('Missing required action field in $ElicitResult');
115115
}
116+
// There was a bug in the initial schema, where the `decline` action was
117+
// named `reject` instead. Handle using that as an alias for `decline` in
118+
// case some clients use the old name.
119+
if (action == 'reject') action = 'decline';
120+
116121
return ElicitationAction.values.byName(action);
117122
}
118123

@@ -131,8 +136,11 @@ enum ElicitationAction {
131136
accept,
132137

133138
/// The user explicitly declined the action.
134-
reject,
139+
decline,
135140

136141
/// The user dismissed without making an explicit choice.
137-
cancel,
142+
cancel;
143+
144+
@Deprecated('Use `ElicitationAction.decline` instead.')
145+
static const reject = decline;
138146
}

0 commit comments

Comments
 (0)