From e408f9759eec5a9aac2ac64c71465593eb91772a Mon Sep 17 00:00:00 2001 From: cliffhall Date: Fri, 29 Aug 2025 09:58:55 -0400 Subject: [PATCH 1/3] =?UTF-8?q?*=20In=20jest.config.js,=20=20=20-=20Omit?= =?UTF-8?q?=20spec.types.test.ts=20for=20now=20unti=20we=20can=20figure=20?= =?UTF-8?q?out=20how=20to=20make=20it=20work.=20=20=20-=20Changes=20in=20t?= =?UTF-8?q?he=20spec=20file=20are=20causing=20it=20to=20fail=20vis-=C3=A0-?= =?UTF-8?q?vis=20JSONRPCNotification=20vs=20Notification=20=20=20-=20see?= =?UTF-8?q?=20https://github.com/modelcontextprotocol/modelcontextprotocol?= =?UTF-8?q?/pull/1026?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jest.config.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index f8f621c8b..9367097b0 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,5 +12,11 @@ export default { transformIgnorePatterns: [ "/node_modules/(?!eventsource)/" ], - testPathIgnorePatterns: ["/node_modules/", "/dist/"], + /* + * Omit spec.types.test.ts for now until we can figure out how to make it work + * Changes in the spec file are causing it to fail vis-à-vis + * JSONRPCNotification vs Notification. + * See: https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1026 + */ + testPathIgnorePatterns: ["/node_modules/", "/dist/", "/src/spec.types.test.ts"], }; From 40282aa50e57a210779206a9a015fd0319fb9177 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Fri, 29 Aug 2025 11:47:37 -0400 Subject: [PATCH 2/3] * In jest.config.js, - Remove the previous ommision of spec.types.test.ts * In spec.types.test.ts - Added two types WithJSONRPC and WithJSONRPCRequest - in test function arguments for notifications, make sdk argument type wrapped by WithJSONRPC - in test function arguments for requests, make sdk argument type wrapped by WithJSONRPCRequest - Add 'Error' to MISSING_SDK_TYPES array (inner error object of a JSONRPCError) - Adjusted specTypes length check to match current actual length (92) --- jest.config.js | 2 +- src/spec.types.test.ts | 69 +++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/jest.config.js b/jest.config.js index 9367097b0..02eb1f4cb 100644 --- a/jest.config.js +++ b/jest.config.js @@ -18,5 +18,5 @@ export default { * JSONRPCNotification vs Notification. * See: https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1026 */ - testPathIgnorePatterns: ["/node_modules/", "/dist/", "/src/spec.types.test.ts"], + testPathIgnorePatterns: ["/node_modules/", "/dist/"], }; diff --git a/src/spec.types.test.ts b/src/spec.types.test.ts index 09cd6c2d0..09e411894 100644 --- a/src/spec.types.test.ts +++ b/src/spec.types.test.ts @@ -21,6 +21,12 @@ type RemovePassthrough = T extends object : {[K in keyof T as string extends K ? never : K]: RemovePassthrough} : T; +// Adds the `jsonrpc` property to a type, to match the on-wire format of notifications. +type WithJSONRPC = T & { jsonrpc: "2.0" }; + +// Adds the `jsonrpc` and `id` properties to a type, to match the on-wire format of requests. +type WithJSONRPCRequest = T & { jsonrpc: "2.0"; id: SDKTypes.RequestId }; + type IsUnknown = [unknown] extends [T] ? [T] extends [unknown] ? true : false : false; // 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); function checkCancelledNotification( - sdk: SDKTypes.CancelledNotification, + sdk: WithJSONRPC, spec: SpecTypes.CancelledNotification ) { sdk = spec; @@ -69,7 +75,7 @@ function checkImplementation( spec = sdk; } function checkProgressNotification( - sdk: SDKTypes.ProgressNotification, + sdk: WithJSONRPC, spec: SpecTypes.ProgressNotification ) { sdk = spec; @@ -77,21 +83,21 @@ function checkProgressNotification( } function checkSubscribeRequest( - sdk: SDKTypes.SubscribeRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.SubscribeRequest ) { sdk = spec; spec = sdk; } function checkUnsubscribeRequest( - sdk: SDKTypes.UnsubscribeRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.UnsubscribeRequest ) { sdk = spec; spec = sdk; } function checkPaginatedRequest( - sdk: SDKTypes.PaginatedRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.PaginatedRequest ) { sdk = spec; @@ -105,7 +111,7 @@ function checkPaginatedResult( spec = sdk; } function checkListRootsRequest( - sdk: SDKTypes.ListRootsRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.ListRootsRequest ) { sdk = spec; @@ -126,7 +132,7 @@ function checkRoot( spec = sdk; } function checkElicitRequest( - sdk: RemovePassthrough, + sdk: WithJSONRPCRequest>, spec: SpecTypes.ElicitRequest ) { sdk = spec; @@ -140,7 +146,7 @@ function checkElicitResult( spec = sdk; } function checkCompleteRequest( - sdk: RemovePassthrough, + sdk: WithJSONRPCRequest>, spec: SpecTypes.CompleteRequest ) { sdk = spec; @@ -231,7 +237,7 @@ function checkClientResult( spec = sdk; } function checkClientNotification( - sdk: SDKTypes.ClientNotification, + sdk: WithJSONRPC, spec: SpecTypes.ClientNotification ) { sdk = spec; @@ -273,7 +279,7 @@ function checkTool( spec = sdk; } function checkListToolsRequest( - sdk: SDKTypes.ListToolsRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.ListToolsRequest ) { sdk = spec; @@ -294,42 +300,42 @@ function checkCallToolResult( spec = sdk; } function checkCallToolRequest( - sdk: SDKTypes.CallToolRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.CallToolRequest ) { sdk = spec; spec = sdk; } function checkToolListChangedNotification( - sdk: SDKTypes.ToolListChangedNotification, + sdk: WithJSONRPC, spec: SpecTypes.ToolListChangedNotification ) { sdk = spec; spec = sdk; } function checkResourceListChangedNotification( - sdk: SDKTypes.ResourceListChangedNotification, + sdk: WithJSONRPC, spec: SpecTypes.ResourceListChangedNotification ) { sdk = spec; spec = sdk; } function checkPromptListChangedNotification( - sdk: SDKTypes.PromptListChangedNotification, + sdk: WithJSONRPC, spec: SpecTypes.PromptListChangedNotification ) { sdk = spec; spec = sdk; } function checkRootsListChangedNotification( - sdk: SDKTypes.RootsListChangedNotification, + sdk: WithJSONRPC, spec: SpecTypes.RootsListChangedNotification ) { sdk = spec; spec = sdk; } function checkResourceUpdatedNotification( - sdk: SDKTypes.ResourceUpdatedNotification, + sdk: WithJSONRPC, spec: SpecTypes.ResourceUpdatedNotification ) { sdk = spec; @@ -350,28 +356,28 @@ function checkCreateMessageResult( spec = sdk; } function checkSetLevelRequest( - sdk: SDKTypes.SetLevelRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.SetLevelRequest ) { sdk = spec; spec = sdk; } function checkPingRequest( - sdk: SDKTypes.PingRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.PingRequest ) { sdk = spec; spec = sdk; } function checkInitializedNotification( - sdk: SDKTypes.InitializedNotification, + sdk: WithJSONRPC, spec: SpecTypes.InitializedNotification ) { sdk = spec; spec = sdk; } function checkListResourcesRequest( - sdk: SDKTypes.ListResourcesRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.ListResourcesRequest ) { sdk = spec; @@ -385,7 +391,7 @@ function checkListResourcesResult( spec = sdk; } function checkListResourceTemplatesRequest( - sdk: SDKTypes.ListResourceTemplatesRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.ListResourceTemplatesRequest ) { sdk = spec; @@ -399,7 +405,7 @@ function checkListResourceTemplatesResult( spec = sdk; } function checkReadResourceRequest( - sdk: SDKTypes.ReadResourceRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.ReadResourceRequest ) { sdk = spec; @@ -462,7 +468,7 @@ function checkPrompt( spec = sdk; } function checkListPromptsRequest( - sdk: SDKTypes.ListPromptsRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.ListPromptsRequest ) { sdk = spec; @@ -476,7 +482,7 @@ function checkListPromptsResult( spec = sdk; } function checkGetPromptRequest( - sdk: SDKTypes.GetPromptRequest, + sdk: WithJSONRPCRequest, spec: SpecTypes.GetPromptRequest ) { sdk = spec; @@ -588,14 +594,14 @@ function checkJSONRPCMessage( spec = sdk; } function checkCreateMessageRequest( - sdk: RemovePassthrough, + sdk: WithJSONRPCRequest>, spec: SpecTypes.CreateMessageRequest ) { sdk = spec; spec = sdk; } function checkInitializeRequest( - sdk: RemovePassthrough, + sdk: WithJSONRPCRequest>, spec: SpecTypes.InitializeRequest ) { sdk = spec; @@ -623,28 +629,28 @@ function checkServerCapabilities( spec = sdk; } function checkClientRequest( - sdk: RemovePassthrough, + sdk: WithJSONRPCRequest>, spec: SpecTypes.ClientRequest ) { sdk = spec; spec = sdk; } function checkServerRequest( - sdk: RemovePassthrough, + sdk: WithJSONRPCRequest>, spec: SpecTypes.ServerRequest ) { sdk = spec; spec = sdk; } function checkLoggingMessageNotification( - sdk: MakeUnknownsNotOptional, + sdk: MakeUnknownsNotOptional>, spec: SpecTypes.LoggingMessageNotification ) { sdk = spec; spec = sdk; } function checkServerNotification( - sdk: MakeUnknownsNotOptional, + sdk: MakeUnknownsNotOptional>, spec: SpecTypes.ServerNotification ) { sdk = spec; @@ -665,6 +671,7 @@ const SDK_TYPES_FILE = 'src/types.ts'; const MISSING_SDK_TYPES = [ // These are inlined in the SDK: 'Role', + 'Error', // The inner error object of a JSONRPCError // These aren't supported by the SDK yet: // TODO: Add definitions to the SDK @@ -685,7 +692,7 @@ describe('Spec Types', () => { it('should define some expected types', () => { expect(specTypes).toContain('JSONRPCNotification'); expect(specTypes).toContain('ElicitResult'); - expect(specTypes).toHaveLength(91); + expect(specTypes).toHaveLength(92); }); it('should have up to date list of missing sdk types', () => { From 52fb76015548487777affdb10a86fc06192347e9 Mon Sep 17 00:00:00 2001 From: cliffhall Date: Fri, 29 Aug 2025 13:59:46 -0400 Subject: [PATCH 3/3] Remove comment from jest.config.js --- jest.config.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/jest.config.js b/jest.config.js index 02eb1f4cb..f8f621c8b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,11 +12,5 @@ export default { transformIgnorePatterns: [ "/node_modules/(?!eventsource)/" ], - /* - * Omit spec.types.test.ts for now until we can figure out how to make it work - * Changes in the spec file are causing it to fail vis-à-vis - * JSONRPCNotification vs Notification. - * See: https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1026 - */ testPathIgnorePatterns: ["/node_modules/", "/dist/"], };