Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkgs/dart_mcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.3-wip

- Fix `PingRequest` handling when it is sent from a non-Dart client.

## 0.3.2

- Deprecate the `EnumSchema` type in favor of the `StringSchema` with an
Expand Down
7 changes: 5 additions & 2 deletions pkgs/dart_mcp/lib/src/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ extension type RequestId( /*String|int*/ Parameter _) {}
///
/// The receiver must promptly respond, or else may be disconnected.
///
/// The request itself has no parameters and should always be just `null`.
extension type PingRequest._(Null _) {
/// The request itself has no parameters.
extension type PingRequest._(Map<String, Object?> _) implements Request {
static const methodName = 'ping';

factory PingRequest({MetaWithProgressToken? meta}) =>
PingRequest._({if (meta != null) '_meta': meta});
}

/// An out-of-band notification used to inform the receiver of a progress
Expand Down
14 changes: 7 additions & 7 deletions pkgs/dart_mcp/lib/src/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ base class MCPBase {

/// The peer may ping us at any time, and we should respond with an empty
/// response.
///
/// Note that [PingRequest] is always actually just `null`.
EmptyResult _handlePing([PingRequest? _]) => EmptyResult();

/// Handles [ProgressNotification]s and forwards them to the streams returned
Expand Down Expand Up @@ -172,11 +170,13 @@ base class MCPBase {
///
/// If the timeout is reached, future values or errors from the ping request
/// are ignored.
Future<bool> ping({Duration timeout = const Duration(seconds: 1)}) =>
sendRequest<EmptyResult>(
PingRequest.methodName,
null,
).then((_) => true).timeout(timeout, onTimeout: () => false);
Future<bool> ping({
Duration timeout = const Duration(seconds: 1),
PingRequest? request,
}) => sendRequest<EmptyResult>(
PingRequest.methodName,
request,
).then((_) => true).timeout(timeout, onTimeout: () => false);

/// If [protocolLogSink] is non-null, emits messages to it for all messages
/// sent over [channel].
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dart_mcp/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dart_mcp
version: 0.3.2
version: 0.3.3-wip
description: A package for making MCP servers and clients.
repository: https://github.com/dart-lang/ai/tree/main/pkgs/dart_mcp
issue_tracker: https://github.com/dart-lang/ai/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Adart_mcp
Expand Down
15 changes: 15 additions & 0 deletions pkgs/dart_mcp/test/client_and_server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ void main() {
);
});

// Regression test for https://github.com/dart-lang/ai/issues/238.
test('client and server can handle ping with non-null parameters', () async {
final environment = TestEnvironment(TestMCPClient(), TestMCPServer.new);
await environment.initializeServer();

await expectLater(
environment.serverConnection.ping(request: PingRequest()),
completes,
);
await expectLater(
environment.server.ping(request: PingRequest()),
completes,
);
});

test(
'server can handle initialized notification with null parameters',
() async {
Expand Down