Skip to content
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
and tool object fields.
- Rejected non-JSON values in JSON-RPC envelope and remaining typed result
metadata fields.
- Rejected non-JSON JSON-RPC error `data` values at parse and serialize
boundaries.
- Prevented stateless MCP 2026 clients from sending core request and
notification methods removed from that protocol revision.
- Rejected server-initiated JSON-RPC requests received by stateless MCP 2026
Expand Down
6 changes: 4 additions & 2 deletions lib/src/types/json_rpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,15 @@ class JsonRpcErrorData {
JsonRpcErrorData(
code: json['code'] as int,
message: json['message'] as String,
data: json['data'],
data: json.containsKey('data')
? readJsonValue(json['data'], 'JsonRpcErrorData.data')
: null,
);

Map<String, dynamic> toJson() => {
'code': code,
'message': message,
if (data != null) 'data': data,
if (data != null) 'data': readJsonValue(data, 'JsonRpcErrorData.data'),
};
}

Expand Down
27 changes: 27 additions & 0 deletions test/types_edge_cases_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ void main() {
final restored = JsonRpcErrorData.fromJson(json);
expect(restored.data['nested']['level'], equals(2));
});

test('JsonRpcErrorData rejects non-JSON data values', () {
expect(
() => const JsonRpcErrorData(
code: -32600,
message: 'Bad data',
data: {'bad': Object()},
).toJson(),
throwsA(isA<FormatException>()),
);
expect(
() => const JsonRpcErrorData(
code: -32600,
message: 'Bad number',
data: {'score': double.infinity},
).toJson(),
throwsA(isA<FormatException>()),
);
expect(
() => JsonRpcErrorData.fromJson({
'code': -32600,
'message': 'Bad data',
'data': {'bad': Object()},
}),
throwsA(isA<FormatException>()),
);
});
});

group('JsonRpcCancelledNotification Edge Cases', () {
Expand Down