File tree Expand file tree Collapse file tree 5 files changed +32
-10
lines changed Expand file tree Collapse file tree 5 files changed +32
-10
lines changed Original file line number Diff line number Diff line change 1+ ## 0.3.3-wip
2+
3+ - Fix ` PingRequest ` handling when it is sent from a non-Dart client.
4+
15## 0.3.2
26
37- Deprecate the ` EnumSchema ` type in favor of the ` StringSchema ` with an
Original file line number Diff line number Diff line change @@ -225,9 +225,12 @@ extension type RequestId( /*String|int*/ Parameter _) {}
225225///
226226/// The receiver must promptly respond, or else may be disconnected.
227227///
228- /// The request itself has no parameters and should always be just `null` .
229- extension type PingRequest ._(Null _) {
228+ /// The request itself has no parameters.
229+ extension type PingRequest ._(Map < String , Object ?> _) implements Request {
230230 static const methodName = 'ping' ;
231+
232+ factory PingRequest ({MetaWithProgressToken ? meta}) =>
233+ PingRequest ._({if (meta != null ) '_meta' : meta});
231234}
232235
233236/// An out-of-band notification used to inform the receiver of a progress
Original file line number Diff line number Diff line change @@ -131,8 +131,6 @@ base class MCPBase {
131131
132132 /// The peer may ping us at any time, and we should respond with an empty
133133 /// response.
134- ///
135- /// Note that [PingRequest] is always actually just `null` .
136134 EmptyResult _handlePing ([PingRequest ? _]) => EmptyResult ();
137135
138136 /// Handles [ProgressNotification] s and forwards them to the streams returned
@@ -172,11 +170,13 @@ base class MCPBase {
172170 ///
173171 /// If the timeout is reached, future values or errors from the ping request
174172 /// are ignored.
175- Future <bool > ping ({Duration timeout = const Duration (seconds: 1 )}) =>
176- sendRequest <EmptyResult >(
177- PingRequest .methodName,
178- null ,
179- ).then ((_) => true ).timeout (timeout, onTimeout: () => false );
173+ Future <bool > ping ({
174+ Duration timeout = const Duration (seconds: 1 ),
175+ PingRequest ? request,
176+ }) => sendRequest <EmptyResult >(
177+ PingRequest .methodName,
178+ request,
179+ ).then ((_) => true ).timeout (timeout, onTimeout: () => false );
180180
181181 /// If [protocolLogSink] is non-null, emits messages to it for all messages
182182 /// sent over [channel] .
Original file line number Diff line number Diff line change 11name : dart_mcp
2- version : 0.3.2
2+ version : 0.3.3-wip
33description : A package for making MCP servers and clients.
44repository : https://github.com/dart-lang/ai/tree/main/pkgs/dart_mcp
55issue_tracker : https://github.com/dart-lang/ai/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Adart_mcp
Original file line number Diff line number Diff line change @@ -127,6 +127,21 @@ void main() {
127127 );
128128 });
129129
130+ // Regression test for https://github.com/dart-lang/ai/issues/238.
131+ test ('client and server can handle ping with non-null parameters' , () async {
132+ final environment = TestEnvironment (TestMCPClient (), TestMCPServer .new );
133+ await environment.initializeServer ();
134+
135+ await expectLater (
136+ environment.serverConnection.ping (request: PingRequest ()),
137+ completes,
138+ );
139+ await expectLater (
140+ environment.server.ping (request: PingRequest ()),
141+ completes,
142+ );
143+ });
144+
130145 test (
131146 'server can handle initialized notification with null parameters' ,
132147 () async {
You can’t perform that action at this time.
0 commit comments