@@ -453,6 +453,95 @@ describe('tool()', () => {
453453 expect ( notifications ) . toHaveLength ( 0 ) ;
454454 } ) ;
455455
456+ /***
457+ * Test: Updating Tool with outputSchema
458+ */
459+ test ( 'should update tool with outputSchema' , async ( ) => {
460+ const mcpServer = new McpServer ( {
461+ name : 'test server' ,
462+ version : '1.0'
463+ } ) ;
464+ const notifications : Notification [ ] = [ ] ;
465+ const client = new Client ( {
466+ name : 'test client' ,
467+ version : '1.0'
468+ } ) ;
469+ client . fallbackNotificationHandler = async notification => {
470+ notifications . push ( notification ) ;
471+ } ;
472+
473+ // Register initial tool
474+ const tool = mcpServer . registerTool (
475+ 'test' ,
476+ {
477+ outputSchema : {
478+ result : z . number ( )
479+ }
480+ } ,
481+ async ( ) => ( {
482+ content : [ { type : 'text' , text : '' } ] ,
483+ structuredContent : {
484+ result : 42
485+ }
486+ } )
487+ ) ;
488+
489+ // Update the tool with a different outputSchema
490+ tool . update ( {
491+ outputSchema : {
492+ result : z . number ( ) ,
493+ sum : z . number ( )
494+ } ,
495+ callback : async ( ) => ( {
496+ content : [ { type : 'text' , text : '' } ] ,
497+ structuredContent : {
498+ result : 42 ,
499+ sum : 100
500+ }
501+ } )
502+ } ) ;
503+
504+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
505+
506+ await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . connect ( serverTransport ) ] ) ;
507+
508+ // Verify the outputSchema was updated
509+ const listResult = await client . request (
510+ {
511+ method : 'tools/list'
512+ } ,
513+ ListToolsResultSchema
514+ ) ;
515+
516+ expect ( listResult . tools [ 0 ] . outputSchema ) . toMatchObject ( {
517+ type : 'object' ,
518+ properties : {
519+ result : { type : 'number' } ,
520+ sum : { type : 'number' }
521+ }
522+ } ) ;
523+
524+ // Call the tool to verify it works with the updated outputSchema
525+ const callResult = await client . request (
526+ {
527+ method : 'tools/call' ,
528+ params : {
529+ name : 'test' ,
530+ arguments : { }
531+ }
532+ } ,
533+ CallToolResultSchema
534+ ) ;
535+
536+ expect ( callResult . structuredContent ) . toEqual ( {
537+ result : 42 ,
538+ sum : 100
539+ } ) ;
540+
541+ // Update happened before transport was connected, so no notifications should be expected
542+ expect ( notifications ) . toHaveLength ( 0 ) ;
543+ } ) ;
544+
456545 /***
457546 * Test: Tool List Changed Notifications
458547 */
0 commit comments