@@ -21,6 +21,12 @@ type RemovePassthrough<T> = T extends object
21
21
: { [ K in keyof T as string extends K ? never : K ] : RemovePassthrough < T [ K ] > }
22
22
: T ;
23
23
24
+ // Adds the `jsonrpc` property to a type, to match the on-wire format of notifications.
25
+ type WithJSONRPC < T > = T & { jsonrpc : "2.0" } ;
26
+
27
+ // Adds the `jsonrpc` and `id` properties to a type, to match the on-wire format of requests.
28
+ type WithJSONRPCRequest < T > = T & { jsonrpc : "2.0" ; id : SDKTypes . RequestId } ;
29
+
24
30
type IsUnknown < T > = [ unknown ] extends [ T ] ? [ T ] extends [ unknown ] ? true : false : false ;
25
31
26
32
// Turns {x?: unknown} into {x: unknown} but keeps {_meta?: unknown} unchanged (and leaves other optional properties unchanged, e.g. {x?: string}).
@@ -48,7 +54,7 @@ type MakeUnknownsNotOptional<T> =
48
54
: T ) ;
49
55
50
56
function checkCancelledNotification (
51
- sdk : SDKTypes . CancelledNotification ,
57
+ sdk : WithJSONRPC < SDKTypes . CancelledNotification > ,
52
58
spec : SpecTypes . CancelledNotification
53
59
) {
54
60
sdk = spec ;
@@ -69,29 +75,29 @@ function checkImplementation(
69
75
spec = sdk ;
70
76
}
71
77
function checkProgressNotification (
72
- sdk : SDKTypes . ProgressNotification ,
78
+ sdk : WithJSONRPC < SDKTypes . ProgressNotification > ,
73
79
spec : SpecTypes . ProgressNotification
74
80
) {
75
81
sdk = spec ;
76
82
spec = sdk ;
77
83
}
78
84
79
85
function checkSubscribeRequest (
80
- sdk : SDKTypes . SubscribeRequest ,
86
+ sdk : WithJSONRPCRequest < SDKTypes . SubscribeRequest > ,
81
87
spec : SpecTypes . SubscribeRequest
82
88
) {
83
89
sdk = spec ;
84
90
spec = sdk ;
85
91
}
86
92
function checkUnsubscribeRequest (
87
- sdk : SDKTypes . UnsubscribeRequest ,
93
+ sdk : WithJSONRPCRequest < SDKTypes . UnsubscribeRequest > ,
88
94
spec : SpecTypes . UnsubscribeRequest
89
95
) {
90
96
sdk = spec ;
91
97
spec = sdk ;
92
98
}
93
99
function checkPaginatedRequest (
94
- sdk : SDKTypes . PaginatedRequest ,
100
+ sdk : WithJSONRPCRequest < SDKTypes . PaginatedRequest > ,
95
101
spec : SpecTypes . PaginatedRequest
96
102
) {
97
103
sdk = spec ;
@@ -105,7 +111,7 @@ function checkPaginatedResult(
105
111
spec = sdk ;
106
112
}
107
113
function checkListRootsRequest (
108
- sdk : SDKTypes . ListRootsRequest ,
114
+ sdk : WithJSONRPCRequest < SDKTypes . ListRootsRequest > ,
109
115
spec : SpecTypes . ListRootsRequest
110
116
) {
111
117
sdk = spec ;
@@ -126,7 +132,7 @@ function checkRoot(
126
132
spec = sdk ;
127
133
}
128
134
function checkElicitRequest (
129
- sdk : RemovePassthrough < SDKTypes . ElicitRequest > ,
135
+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . ElicitRequest > > ,
130
136
spec : SpecTypes . ElicitRequest
131
137
) {
132
138
sdk = spec ;
@@ -140,7 +146,7 @@ function checkElicitResult(
140
146
spec = sdk ;
141
147
}
142
148
function checkCompleteRequest (
143
- sdk : RemovePassthrough < SDKTypes . CompleteRequest > ,
149
+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . CompleteRequest > > ,
144
150
spec : SpecTypes . CompleteRequest
145
151
) {
146
152
sdk = spec ;
@@ -231,7 +237,7 @@ function checkClientResult(
231
237
spec = sdk ;
232
238
}
233
239
function checkClientNotification (
234
- sdk : SDKTypes . ClientNotification ,
240
+ sdk : WithJSONRPC < SDKTypes . ClientNotification > ,
235
241
spec : SpecTypes . ClientNotification
236
242
) {
237
243
sdk = spec ;
@@ -273,7 +279,7 @@ function checkTool(
273
279
spec = sdk ;
274
280
}
275
281
function checkListToolsRequest (
276
- sdk : SDKTypes . ListToolsRequest ,
282
+ sdk : WithJSONRPCRequest < SDKTypes . ListToolsRequest > ,
277
283
spec : SpecTypes . ListToolsRequest
278
284
) {
279
285
sdk = spec ;
@@ -294,42 +300,42 @@ function checkCallToolResult(
294
300
spec = sdk ;
295
301
}
296
302
function checkCallToolRequest (
297
- sdk : SDKTypes . CallToolRequest ,
303
+ sdk : WithJSONRPCRequest < SDKTypes . CallToolRequest > ,
298
304
spec : SpecTypes . CallToolRequest
299
305
) {
300
306
sdk = spec ;
301
307
spec = sdk ;
302
308
}
303
309
function checkToolListChangedNotification (
304
- sdk : SDKTypes . ToolListChangedNotification ,
310
+ sdk : WithJSONRPC < SDKTypes . ToolListChangedNotification > ,
305
311
spec : SpecTypes . ToolListChangedNotification
306
312
) {
307
313
sdk = spec ;
308
314
spec = sdk ;
309
315
}
310
316
function checkResourceListChangedNotification (
311
- sdk : SDKTypes . ResourceListChangedNotification ,
317
+ sdk : WithJSONRPC < SDKTypes . ResourceListChangedNotification > ,
312
318
spec : SpecTypes . ResourceListChangedNotification
313
319
) {
314
320
sdk = spec ;
315
321
spec = sdk ;
316
322
}
317
323
function checkPromptListChangedNotification (
318
- sdk : SDKTypes . PromptListChangedNotification ,
324
+ sdk : WithJSONRPC < SDKTypes . PromptListChangedNotification > ,
319
325
spec : SpecTypes . PromptListChangedNotification
320
326
) {
321
327
sdk = spec ;
322
328
spec = sdk ;
323
329
}
324
330
function checkRootsListChangedNotification (
325
- sdk : SDKTypes . RootsListChangedNotification ,
331
+ sdk : WithJSONRPC < SDKTypes . RootsListChangedNotification > ,
326
332
spec : SpecTypes . RootsListChangedNotification
327
333
) {
328
334
sdk = spec ;
329
335
spec = sdk ;
330
336
}
331
337
function checkResourceUpdatedNotification (
332
- sdk : SDKTypes . ResourceUpdatedNotification ,
338
+ sdk : WithJSONRPC < SDKTypes . ResourceUpdatedNotification > ,
333
339
spec : SpecTypes . ResourceUpdatedNotification
334
340
) {
335
341
sdk = spec ;
@@ -350,28 +356,28 @@ function checkCreateMessageResult(
350
356
spec = sdk ;
351
357
}
352
358
function checkSetLevelRequest (
353
- sdk : SDKTypes . SetLevelRequest ,
359
+ sdk : WithJSONRPCRequest < SDKTypes . SetLevelRequest > ,
354
360
spec : SpecTypes . SetLevelRequest
355
361
) {
356
362
sdk = spec ;
357
363
spec = sdk ;
358
364
}
359
365
function checkPingRequest (
360
- sdk : SDKTypes . PingRequest ,
366
+ sdk : WithJSONRPCRequest < SDKTypes . PingRequest > ,
361
367
spec : SpecTypes . PingRequest
362
368
) {
363
369
sdk = spec ;
364
370
spec = sdk ;
365
371
}
366
372
function checkInitializedNotification (
367
- sdk : SDKTypes . InitializedNotification ,
373
+ sdk : WithJSONRPC < SDKTypes . InitializedNotification > ,
368
374
spec : SpecTypes . InitializedNotification
369
375
) {
370
376
sdk = spec ;
371
377
spec = sdk ;
372
378
}
373
379
function checkListResourcesRequest (
374
- sdk : SDKTypes . ListResourcesRequest ,
380
+ sdk : WithJSONRPCRequest < SDKTypes . ListResourcesRequest > ,
375
381
spec : SpecTypes . ListResourcesRequest
376
382
) {
377
383
sdk = spec ;
@@ -385,7 +391,7 @@ function checkListResourcesResult(
385
391
spec = sdk ;
386
392
}
387
393
function checkListResourceTemplatesRequest (
388
- sdk : SDKTypes . ListResourceTemplatesRequest ,
394
+ sdk : WithJSONRPCRequest < SDKTypes . ListResourceTemplatesRequest > ,
389
395
spec : SpecTypes . ListResourceTemplatesRequest
390
396
) {
391
397
sdk = spec ;
@@ -399,7 +405,7 @@ function checkListResourceTemplatesResult(
399
405
spec = sdk ;
400
406
}
401
407
function checkReadResourceRequest (
402
- sdk : SDKTypes . ReadResourceRequest ,
408
+ sdk : WithJSONRPCRequest < SDKTypes . ReadResourceRequest > ,
403
409
spec : SpecTypes . ReadResourceRequest
404
410
) {
405
411
sdk = spec ;
@@ -462,7 +468,7 @@ function checkPrompt(
462
468
spec = sdk ;
463
469
}
464
470
function checkListPromptsRequest (
465
- sdk : SDKTypes . ListPromptsRequest ,
471
+ sdk : WithJSONRPCRequest < SDKTypes . ListPromptsRequest > ,
466
472
spec : SpecTypes . ListPromptsRequest
467
473
) {
468
474
sdk = spec ;
@@ -476,7 +482,7 @@ function checkListPromptsResult(
476
482
spec = sdk ;
477
483
}
478
484
function checkGetPromptRequest (
479
- sdk : SDKTypes . GetPromptRequest ,
485
+ sdk : WithJSONRPCRequest < SDKTypes . GetPromptRequest > ,
480
486
spec : SpecTypes . GetPromptRequest
481
487
) {
482
488
sdk = spec ;
@@ -588,14 +594,14 @@ function checkJSONRPCMessage(
588
594
spec = sdk ;
589
595
}
590
596
function checkCreateMessageRequest (
591
- sdk : RemovePassthrough < SDKTypes . CreateMessageRequest > ,
597
+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . CreateMessageRequest > > ,
592
598
spec : SpecTypes . CreateMessageRequest
593
599
) {
594
600
sdk = spec ;
595
601
spec = sdk ;
596
602
}
597
603
function checkInitializeRequest (
598
- sdk : RemovePassthrough < SDKTypes . InitializeRequest > ,
604
+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . InitializeRequest > > ,
599
605
spec : SpecTypes . InitializeRequest
600
606
) {
601
607
sdk = spec ;
@@ -623,28 +629,28 @@ function checkServerCapabilities(
623
629
spec = sdk ;
624
630
}
625
631
function checkClientRequest (
626
- sdk : RemovePassthrough < SDKTypes . ClientRequest > ,
632
+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . ClientRequest > > ,
627
633
spec : SpecTypes . ClientRequest
628
634
) {
629
635
sdk = spec ;
630
636
spec = sdk ;
631
637
}
632
638
function checkServerRequest (
633
- sdk : RemovePassthrough < SDKTypes . ServerRequest > ,
639
+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . ServerRequest > > ,
634
640
spec : SpecTypes . ServerRequest
635
641
) {
636
642
sdk = spec ;
637
643
spec = sdk ;
638
644
}
639
645
function checkLoggingMessageNotification (
640
- sdk : MakeUnknownsNotOptional < SDKTypes . LoggingMessageNotification > ,
646
+ sdk : MakeUnknownsNotOptional < WithJSONRPC < SDKTypes . LoggingMessageNotification > > ,
641
647
spec : SpecTypes . LoggingMessageNotification
642
648
) {
643
649
sdk = spec ;
644
650
spec = sdk ;
645
651
}
646
652
function checkServerNotification (
647
- sdk : MakeUnknownsNotOptional < SDKTypes . ServerNotification > ,
653
+ sdk : MakeUnknownsNotOptional < WithJSONRPC < SDKTypes . ServerNotification > > ,
648
654
spec : SpecTypes . ServerNotification
649
655
) {
650
656
sdk = spec ;
@@ -665,6 +671,7 @@ const SDK_TYPES_FILE = 'src/types.ts';
665
671
const MISSING_SDK_TYPES = [
666
672
// These are inlined in the SDK:
667
673
'Role' ,
674
+ 'Error' , // The inner error object of a JSONRPCError
668
675
669
676
// These aren't supported by the SDK yet:
670
677
// TODO: Add definitions to the SDK
@@ -685,7 +692,7 @@ describe('Spec Types', () => {
685
692
it ( 'should define some expected types' , ( ) => {
686
693
expect ( specTypes ) . toContain ( 'JSONRPCNotification' ) ;
687
694
expect ( specTypes ) . toContain ( 'ElicitResult' ) ;
688
- expect ( specTypes ) . toHaveLength ( 91 ) ;
695
+ expect ( specTypes ) . toHaveLength ( 92 ) ;
689
696
} ) ;
690
697
691
698
it ( 'should have up to date list of missing sdk types' , ( ) => {
0 commit comments