Skip to content

Commit f2748d8

Browse files
authored
Add metadata to ElicitRequest objects, forward tool call metadata with with the requests. (#369)
Also prepares to publish dart_mcp version 0.5.0. Some clients require elicitation requests to be associated with a tool call, and they link it using the ProgressToken.
1 parent 1777aaf commit f2748d8

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

pkgs/dart_mcp/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.5.0-wip
1+
## 0.5.0
22

33
- Initial support for protocol version [2025-11-25](https://modelcontextprotocol.io/specification/2025-11-25/).
44
- Added support for `Icon`s in `Implementation`, `Tool`, `Resource`, `ResourceTemplate`, and `Prompt`.
@@ -22,6 +22,7 @@
2222
- Does **not** add support for Tasks yet.
2323
- Added support for `EnumSchema` subtypes, matching the spec. This includes
2424
multi select enums and enums with titles. Validation is also supported.
25+
- Added `Meta? meta` param to `ElicitRequest`.
2526
- Added `ConstSchema` type for constant values, with validation.
2627
- **BREAKING**:
2728
- Change many fields of `ResourceLink` to be nullable, and their associated

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extension type ElicitRequest._fromMap(Map<String, Object?> _value)
1919
factory ElicitRequest({
2020
required String message,
2121
required ObjectSchema requestedSchema,
22+
MetaWithProgressToken? meta,
2223
}) {
2324
assert(
2425
validateRequestedSchema(requestedSchema),
@@ -28,6 +29,7 @@ extension type ElicitRequest._fromMap(Map<String, Object?> _value)
2829
Keys.mode: ElicitationMode.form.name,
2930
Keys.message: message,
3031
Keys.requestedSchema: requestedSchema,
32+
if (meta != null) Keys.meta: meta,
3133
});
3234
}
3335

@@ -36,12 +38,14 @@ extension type ElicitRequest._fromMap(Map<String, Object?> _value)
3638
required String message,
3739
required String url,
3840
required String elicitationId,
41+
MetaWithProgressToken? meta,
3942
}) {
4043
return ElicitRequest._fromMap({
4144
Keys.mode: ElicitationMode.url.name,
4245
Keys.message: message,
4346
Keys.url: url,
4447
Keys.elicitationId: elicitationId,
48+
if (meta != null) Keys.meta: meta,
4549
});
4650
}
4751

pkgs/dart_mcp/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: dart_mcp
2-
version: 0.5.0-wip
2+
version: 0.5.0
33
description: A package for making MCP servers and clients.
44
repository: https://github.com/dart-lang/ai/tree/main/pkgs/dart_mcp
55
issue_tracker: https://github.com/dart-lang/ai/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Adart_mcp

pkgs/dart_mcp_server/lib/src/mixins/grep_packages.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ base mixin GrepSupport
4949
}
5050

5151
final ripGrepExecutable =
52-
await _checkForRipGrep() ?? await tryInstallRipGrep();
52+
await _checkForRipGrep() ??
53+
await tryInstallRipGrep(progressToken: request.meta?.progressToken);
5354
if (ripGrepExecutable == null) {
5455
return CallToolResult(
5556
content: [
@@ -202,15 +203,26 @@ base mixin GrepSupport
202203
///
203204
/// [installDir] is the directory to install ripgrep to. If null, the default
204205
/// install directory will be used.
206+
///
207+
/// If [progressToken] is passed, it will be added to the [ElicitRequest]
208+
/// metadata. This is primarily used to forward on progress tokens, which is
209+
/// required by some clients (it links the elicitation to a tool call).
205210
@visibleForTesting
206-
Future<String?> tryInstallRipGrep({Directory? installDir}) async {
211+
Future<String?> tryInstallRipGrep({
212+
Directory? installDir,
213+
ProgressToken? progressToken,
214+
}) async {
207215
// If the client does not support elicitation, we cannot install ripgrep
208216
// because we can't get consent.
209217
if (clientCapabilities.elicitation == null) return null;
218+
final meta = progressToken != null
219+
? MetaWithProgressToken(progressToken: progressToken)
220+
: null;
210221
final elicitResult = await elicit(
211222
ElicitRequest.form(
212223
message: 'Ripgrep is required to run this tool, can I install it?',
213224
requestedSchema: Schema.object(),
225+
meta: meta,
214226
),
215227
);
216228
// The user did not approve the installation.

0 commit comments

Comments
 (0)