@@ -206,4 +206,83 @@ describe("createMcpServer", () => {
206206 const base = f . created [ 0 ] ;
207207 expect ( base . calls . filter ( ( n ) => n === "testset.test_tool" ) . length ) . toBe ( 1 ) ;
208208 } ) ;
209+
210+ it ( "rejects invalid startup properties with Zod validation" , async ( ) => {
211+ const { createServer } = makeFakeServerFactory ( ) ;
212+
213+ // Type cast to bypass TypeScript checking (simulates user with loose types)
214+ const invalidOptions = {
215+ catalog : { core : { name : "Core" , description : "" , tools : [ ] } } ,
216+ startup : { mode : "STATIC" , initialToolsets : [ "core" ] } , // Wrong property!
217+ createServer,
218+ } as any ;
219+
220+ await expect ( createMcpServer ( invalidOptions ) ) . rejects . toThrow (
221+ / I n v a l i d s t a r t u p c o n f i g u r a t i o n /
222+ ) ;
223+ } ) ;
224+
225+ it ( "successfully parses valid startup config with 'mode' and 'toolsets' properties" , async ( ) => {
226+ const f = makeFakeServerFactory ( ) ;
227+ const staticCatalog = {
228+ core : {
229+ name : "Core" ,
230+ description : "" ,
231+ tools : [
232+ {
233+ name : "ping" ,
234+ description : "" ,
235+ inputSchema : { } ,
236+ handler : async ( ) => ( { content : [ { type : "text" , text : "pong" } ] } ) ,
237+ } ,
238+ ] ,
239+ } ,
240+ } as any ;
241+
242+ await expect (
243+ createMcpServer ( {
244+ catalog : staticCatalog ,
245+ startup : { mode : "STATIC" , toolsets : [ "core" ] } ,
246+ createServer : f . createServer ,
247+ } )
248+ ) . resolves . toBeTruthy ( ) ;
249+
250+ const base = f . created [ 0 ] ;
251+ expect ( base . calls . filter ( ( n ) => n === "core.ping" ) . length ) . toBe ( 1 ) ;
252+ } ) ;
253+
254+ it ( "throws a Zod validation error for completely malformed startup config object" , async ( ) => {
255+ const { createServer } = makeFakeServerFactory ( ) ;
256+
257+ // Non-object startup value
258+ const bad1 = {
259+ catalog,
260+ startup : 42 as any ,
261+ createServer,
262+ } as any ;
263+
264+ // Object with wrong types for both fields
265+ const bad2 = {
266+ catalog,
267+ startup : { mode : 123 , toolsets : 555 } as any ,
268+ createServer,
269+ } as any ;
270+
271+ await expect ( createMcpServer ( bad1 ) ) . rejects . toThrow ( / I n v a l i d s t a r t u p c o n f i g u r a t i o n / ) ;
272+ await expect ( createMcpServer ( bad2 ) ) . rejects . toThrow ( / I n v a l i d s t a r t u p c o n f i g u r a t i o n / ) ;
273+ } ) ;
274+
275+ it ( "accepts missing startup config without error (defaults to DYNAMIC)" , async ( ) => {
276+ const f = makeFakeServerFactory ( ) ;
277+ await expect (
278+ createMcpServer ( {
279+ catalog,
280+ createServer : f . createServer ,
281+ } )
282+ ) . resolves . toBeTruthy ( ) ;
283+
284+ // Default behavior in DYNAMIC mode is to register meta-tools
285+ const base = f . created [ 0 ] ;
286+ expect ( base . calls . includes ( "list_tools" ) ) . toBe ( true ) ;
287+ } ) ;
209288} ) ;
0 commit comments