@@ -386,49 +386,55 @@ const runServer = async (options: ServerOptions = getOptions(), {
386386 const isZod = isZodSchema ( schema ?. inputSchema ) || isZodRawShape ( schema ?. inputSchema ) ;
387387 const isSchemaDefined = schema ?. inputSchema !== undefined ;
388388
389- log . info ( `Registered tool: ${ name } ` ) ;
390-
391389 if ( ! isZod ) {
392- log . warn ( `Tool "${ name } " has a non Zod inputSchema. This may cause unexpected issues .` ) ;
390+ log . warn ( `Tool "${ name } " has a non Zod inputSchema. Skipping registration .` ) ;
393391 log . debug (
394392 `Tool "${ name } " has received a non Zod inputSchema from the tool pipeline.` ,
395393 `This will cause unexpected issues, such as failure to pass arguments.` ,
396394 `MCP SDK requires Zod. Kneel before Zod.`
397395 ) ;
396+
397+ return ;
398398 }
399399
400400 // Lightweight check for malformed schemas that bypass validation.
401401 const isContextLike = ( value : unknown ) => isPlainObject ( value ) && 'requestId' in value && 'signal' in value ;
402402
403- server ?. registerTool ( name , schema , ( args : unknown = { } , ..._args : unknown [ ] ) =>
404- runWithSession ( session , async ( ) =>
405- runWithOptions ( options , async ( ) => {
406- // Basic track for remaining args to account for future MCP SDK alterations.
407- log . debug (
408- `Running tool "${ name } "` ,
409- `isArgs = ${ args !== undefined } ` ,
410- `isRemainingArgs = ${ _args ?. length > 0 } `
411- ) ;
412-
413- const timedReport = stat . traffic ( ) ;
414- const isContextLikeArgs = isContextLike ( args ) ;
415-
416- // Log potential Zod validation errors triggered by context fail.
417- if ( isContextLikeArgs ) {
403+ try {
404+ server ?. registerTool ( name , schema , ( args : unknown = { } , ..._args : unknown [ ] ) =>
405+ runWithSession ( session , async ( ) =>
406+ runWithOptions ( options , async ( ) => {
407+ // Basic track for remaining args to account for future MCP SDK alterations.
418408 log . debug (
419- `Tool "${ name } " handler received a context like object as the first parameter.` ,
420- 'If this is unexpected this is likely an undefined schema or a schema not registering as Zod.' ,
421- 'Review the related schema definition and ensure it is defined and valid.' ,
422- `Schema is Defined = ${ isSchemaDefined } ; Schema is Zod = ${ isZod } ; Context like = ${ isContextLikeArgs } ;`
409+ `Running tool "${ name } "` ,
410+ `isArgs = ${ args !== undefined } ` ,
411+ `isRemainingArgs = ${ _args ?. length > 0 } `
423412 ) ;
424- }
425413
426- const toolResult = await callback ( args ) ;
414+ const timedReport = stat . traffic ( ) ;
415+ const isContextLikeArgs = isContextLike ( args ) ;
416+
417+ // Log potential Zod validation errors triggered by context fail.
418+ if ( isContextLikeArgs ) {
419+ log . debug (
420+ `Tool "${ name } " handler received a context like object as the first parameter.` ,
421+ 'If this is unexpected this is likely an undefined schema or a schema not registering as Zod.' ,
422+ 'Review the related schema definition and ensure it is defined and valid.' ,
423+ `Schema is Defined = ${ isSchemaDefined } ; Schema is Zod = ${ isZod } ; Context like = ${ isContextLikeArgs } ;`
424+ ) ;
425+ }
426+
427+ const toolResult = await callback ( args ) ;
427428
428- timedReport ( { tool : name } ) ;
429+ timedReport ( { tool : name } ) ;
429430
430- return toolResult ;
431- } ) ) ) ;
431+ return toolResult ;
432+ } ) ) ) ;
433+
434+ log . info ( `Registered tool: ${ name } ` ) ;
435+ } catch ( error ) {
436+ log . error ( `Failed to register tool "${ name } ":` , error ) ;
437+ }
432438 } ) ;
433439
434440 if ( enableSigint && ! sigintHandler ) {
0 commit comments