Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 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,11 @@ 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() => PingRequest._(const {});
}

/// An out-of-band notification used to inform the receiver of a progress
Expand Down
2 changes: 0 additions & 2 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
37 changes: 37 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,39 @@ void main() {
);
});

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

await expectLater(
environment.serverConnection.sendRequest(PingRequest.methodName, null),
completes,
);
await expectLater(
environment.server.sendRequest(PingRequest.methodName, null),
completes,
);
});

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

await expectLater(
environment.serverConnection.sendRequest(
PingRequest.methodName,
_EmptyRequest(),
),
completes,
);
await expectLater(
environment.server.sendRequest(PingRequest.methodName, _EmptyRequest()),
completes,
);
});

test(
'server can handle initialized notification with null parameters',
() async {
Expand Down Expand Up @@ -438,3 +471,7 @@ final class TestUnrecognizedVersionMcpServer extends TestMCPServer {
return response;
}
}

extension type _EmptyRequest._(Map<String, Object?> _) implements Request {
factory _EmptyRequest() => _EmptyRequest._(const {});
}
Loading