@@ -21,6 +21,12 @@ type RemovePassthrough<T> = T extends object
2121 : { [ K in keyof T as string extends K ? never : K ] : RemovePassthrough < T [ K ] > }
2222 : T ;
2323
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+
2430type IsUnknown < T > = [ unknown ] extends [ T ] ? [ T ] extends [ unknown ] ? true : false : false ;
2531
2632// 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> =
4854 : T ) ;
4955
5056function checkCancelledNotification (
51- sdk : SDKTypes . CancelledNotification ,
57+ sdk : WithJSONRPC < SDKTypes . CancelledNotification > ,
5258 spec : SpecTypes . CancelledNotification
5359) {
5460 sdk = spec ;
@@ -69,29 +75,29 @@ function checkImplementation(
6975 spec = sdk ;
7076}
7177function checkProgressNotification (
72- sdk : SDKTypes . ProgressNotification ,
78+ sdk : WithJSONRPC < SDKTypes . ProgressNotification > ,
7379 spec : SpecTypes . ProgressNotification
7480) {
7581 sdk = spec ;
7682 spec = sdk ;
7783}
7884
7985function checkSubscribeRequest (
80- sdk : SDKTypes . SubscribeRequest ,
86+ sdk : WithJSONRPCRequest < SDKTypes . SubscribeRequest > ,
8187 spec : SpecTypes . SubscribeRequest
8288) {
8389 sdk = spec ;
8490 spec = sdk ;
8591}
8692function checkUnsubscribeRequest (
87- sdk : SDKTypes . UnsubscribeRequest ,
93+ sdk : WithJSONRPCRequest < SDKTypes . UnsubscribeRequest > ,
8894 spec : SpecTypes . UnsubscribeRequest
8995) {
9096 sdk = spec ;
9197 spec = sdk ;
9298}
9399function checkPaginatedRequest (
94- sdk : SDKTypes . PaginatedRequest ,
100+ sdk : WithJSONRPCRequest < SDKTypes . PaginatedRequest > ,
95101 spec : SpecTypes . PaginatedRequest
96102) {
97103 sdk = spec ;
@@ -105,7 +111,7 @@ function checkPaginatedResult(
105111 spec = sdk ;
106112}
107113function checkListRootsRequest (
108- sdk : SDKTypes . ListRootsRequest ,
114+ sdk : WithJSONRPCRequest < SDKTypes . ListRootsRequest > ,
109115 spec : SpecTypes . ListRootsRequest
110116) {
111117 sdk = spec ;
@@ -126,7 +132,7 @@ function checkRoot(
126132 spec = sdk ;
127133}
128134function checkElicitRequest (
129- sdk : RemovePassthrough < SDKTypes . ElicitRequest > ,
135+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . ElicitRequest > > ,
130136 spec : SpecTypes . ElicitRequest
131137) {
132138 sdk = spec ;
@@ -140,7 +146,7 @@ function checkElicitResult(
140146 spec = sdk ;
141147}
142148function checkCompleteRequest (
143- sdk : RemovePassthrough < SDKTypes . CompleteRequest > ,
149+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . CompleteRequest > > ,
144150 spec : SpecTypes . CompleteRequest
145151) {
146152 sdk = spec ;
@@ -231,7 +237,7 @@ function checkClientResult(
231237 spec = sdk ;
232238}
233239function checkClientNotification (
234- sdk : SDKTypes . ClientNotification ,
240+ sdk : WithJSONRPC < SDKTypes . ClientNotification > ,
235241 spec : SpecTypes . ClientNotification
236242) {
237243 sdk = spec ;
@@ -273,7 +279,7 @@ function checkTool(
273279 spec = sdk ;
274280}
275281function checkListToolsRequest (
276- sdk : SDKTypes . ListToolsRequest ,
282+ sdk : WithJSONRPCRequest < SDKTypes . ListToolsRequest > ,
277283 spec : SpecTypes . ListToolsRequest
278284) {
279285 sdk = spec ;
@@ -294,42 +300,42 @@ function checkCallToolResult(
294300 spec = sdk ;
295301}
296302function checkCallToolRequest (
297- sdk : SDKTypes . CallToolRequest ,
303+ sdk : WithJSONRPCRequest < SDKTypes . CallToolRequest > ,
298304 spec : SpecTypes . CallToolRequest
299305) {
300306 sdk = spec ;
301307 spec = sdk ;
302308}
303309function checkToolListChangedNotification (
304- sdk : SDKTypes . ToolListChangedNotification ,
310+ sdk : WithJSONRPC < SDKTypes . ToolListChangedNotification > ,
305311 spec : SpecTypes . ToolListChangedNotification
306312) {
307313 sdk = spec ;
308314 spec = sdk ;
309315}
310316function checkResourceListChangedNotification (
311- sdk : SDKTypes . ResourceListChangedNotification ,
317+ sdk : WithJSONRPC < SDKTypes . ResourceListChangedNotification > ,
312318 spec : SpecTypes . ResourceListChangedNotification
313319) {
314320 sdk = spec ;
315321 spec = sdk ;
316322}
317323function checkPromptListChangedNotification (
318- sdk : SDKTypes . PromptListChangedNotification ,
324+ sdk : WithJSONRPC < SDKTypes . PromptListChangedNotification > ,
319325 spec : SpecTypes . PromptListChangedNotification
320326) {
321327 sdk = spec ;
322328 spec = sdk ;
323329}
324330function checkRootsListChangedNotification (
325- sdk : SDKTypes . RootsListChangedNotification ,
331+ sdk : WithJSONRPC < SDKTypes . RootsListChangedNotification > ,
326332 spec : SpecTypes . RootsListChangedNotification
327333) {
328334 sdk = spec ;
329335 spec = sdk ;
330336}
331337function checkResourceUpdatedNotification (
332- sdk : SDKTypes . ResourceUpdatedNotification ,
338+ sdk : WithJSONRPC < SDKTypes . ResourceUpdatedNotification > ,
333339 spec : SpecTypes . ResourceUpdatedNotification
334340) {
335341 sdk = spec ;
@@ -350,28 +356,28 @@ function checkCreateMessageResult(
350356 spec = sdk ;
351357}
352358function checkSetLevelRequest (
353- sdk : SDKTypes . SetLevelRequest ,
359+ sdk : WithJSONRPCRequest < SDKTypes . SetLevelRequest > ,
354360 spec : SpecTypes . SetLevelRequest
355361) {
356362 sdk = spec ;
357363 spec = sdk ;
358364}
359365function checkPingRequest (
360- sdk : SDKTypes . PingRequest ,
366+ sdk : WithJSONRPCRequest < SDKTypes . PingRequest > ,
361367 spec : SpecTypes . PingRequest
362368) {
363369 sdk = spec ;
364370 spec = sdk ;
365371}
366372function checkInitializedNotification (
367- sdk : SDKTypes . InitializedNotification ,
373+ sdk : WithJSONRPC < SDKTypes . InitializedNotification > ,
368374 spec : SpecTypes . InitializedNotification
369375) {
370376 sdk = spec ;
371377 spec = sdk ;
372378}
373379function checkListResourcesRequest (
374- sdk : SDKTypes . ListResourcesRequest ,
380+ sdk : WithJSONRPCRequest < SDKTypes . ListResourcesRequest > ,
375381 spec : SpecTypes . ListResourcesRequest
376382) {
377383 sdk = spec ;
@@ -385,7 +391,7 @@ function checkListResourcesResult(
385391 spec = sdk ;
386392}
387393function checkListResourceTemplatesRequest (
388- sdk : SDKTypes . ListResourceTemplatesRequest ,
394+ sdk : WithJSONRPCRequest < SDKTypes . ListResourceTemplatesRequest > ,
389395 spec : SpecTypes . ListResourceTemplatesRequest
390396) {
391397 sdk = spec ;
@@ -399,7 +405,7 @@ function checkListResourceTemplatesResult(
399405 spec = sdk ;
400406}
401407function checkReadResourceRequest (
402- sdk : SDKTypes . ReadResourceRequest ,
408+ sdk : WithJSONRPCRequest < SDKTypes . ReadResourceRequest > ,
403409 spec : SpecTypes . ReadResourceRequest
404410) {
405411 sdk = spec ;
@@ -462,7 +468,7 @@ function checkPrompt(
462468 spec = sdk ;
463469}
464470function checkListPromptsRequest (
465- sdk : SDKTypes . ListPromptsRequest ,
471+ sdk : WithJSONRPCRequest < SDKTypes . ListPromptsRequest > ,
466472 spec : SpecTypes . ListPromptsRequest
467473) {
468474 sdk = spec ;
@@ -476,7 +482,7 @@ function checkListPromptsResult(
476482 spec = sdk ;
477483}
478484function checkGetPromptRequest (
479- sdk : SDKTypes . GetPromptRequest ,
485+ sdk : WithJSONRPCRequest < SDKTypes . GetPromptRequest > ,
480486 spec : SpecTypes . GetPromptRequest
481487) {
482488 sdk = spec ;
@@ -588,14 +594,14 @@ function checkJSONRPCMessage(
588594 spec = sdk ;
589595}
590596function checkCreateMessageRequest (
591- sdk : RemovePassthrough < SDKTypes . CreateMessageRequest > ,
597+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . CreateMessageRequest > > ,
592598 spec : SpecTypes . CreateMessageRequest
593599) {
594600 sdk = spec ;
595601 spec = sdk ;
596602}
597603function checkInitializeRequest (
598- sdk : RemovePassthrough < SDKTypes . InitializeRequest > ,
604+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . InitializeRequest > > ,
599605 spec : SpecTypes . InitializeRequest
600606) {
601607 sdk = spec ;
@@ -623,28 +629,28 @@ function checkServerCapabilities(
623629 spec = sdk ;
624630}
625631function checkClientRequest (
626- sdk : RemovePassthrough < SDKTypes . ClientRequest > ,
632+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . ClientRequest > > ,
627633 spec : SpecTypes . ClientRequest
628634) {
629635 sdk = spec ;
630636 spec = sdk ;
631637}
632638function checkServerRequest (
633- sdk : RemovePassthrough < SDKTypes . ServerRequest > ,
639+ sdk : WithJSONRPCRequest < RemovePassthrough < SDKTypes . ServerRequest > > ,
634640 spec : SpecTypes . ServerRequest
635641) {
636642 sdk = spec ;
637643 spec = sdk ;
638644}
639645function checkLoggingMessageNotification (
640- sdk : MakeUnknownsNotOptional < SDKTypes . LoggingMessageNotification > ,
646+ sdk : MakeUnknownsNotOptional < WithJSONRPC < SDKTypes . LoggingMessageNotification > > ,
641647 spec : SpecTypes . LoggingMessageNotification
642648) {
643649 sdk = spec ;
644650 spec = sdk ;
645651}
646652function checkServerNotification (
647- sdk : MakeUnknownsNotOptional < SDKTypes . ServerNotification > ,
653+ sdk : MakeUnknownsNotOptional < WithJSONRPC < SDKTypes . ServerNotification > > ,
648654 spec : SpecTypes . ServerNotification
649655) {
650656 sdk = spec ;
@@ -665,6 +671,7 @@ const SDK_TYPES_FILE = 'src/types.ts';
665671const MISSING_SDK_TYPES = [
666672 // These are inlined in the SDK:
667673 'Role' ,
674+ 'Error' , // The inner error object of a JSONRPCError
668675
669676 // These aren't supported by the SDK yet:
670677 // TODO: Add definitions to the SDK
@@ -685,7 +692,7 @@ describe('Spec Types', () => {
685692 it ( 'should define some expected types' , ( ) => {
686693 expect ( specTypes ) . toContain ( 'JSONRPCNotification' ) ;
687694 expect ( specTypes ) . toContain ( 'ElicitResult' ) ;
688- expect ( specTypes ) . toHaveLength ( 91 ) ;
695+ expect ( specTypes ) . toHaveLength ( 92 ) ;
689696 } ) ;
690697
691698 it ( 'should have up to date list of missing sdk types' , ( ) => {
0 commit comments