@@ -1777,22 +1777,59 @@ describe('Zod v4', () => {
17771777
17781778 await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
17791779
1780- const result = await client . request ( {
1781- method : 'tools/call' ,
1782- params : {
1783- name : 'nonexistent-tool'
1784- }
1780+ await expect (
1781+ client . request ( {
1782+ method : 'tools/call' ,
1783+ params : {
1784+ name : 'nonexistent-tool'
1785+ }
1786+ } )
1787+ ) . rejects . toMatchObject ( {
1788+ code : ProtocolErrorCode . InvalidParams ,
1789+ message : expect . stringContaining ( 'nonexistent-tool' )
17851790 } ) ;
1791+ } ) ;
17861792
1787- expect ( result . isError ) . toBe ( true ) ;
1788- expect ( result . content ) . toEqual (
1789- expect . arrayContaining ( [
1793+ /***
1794+ * Test: ProtocolError for Disabled Tool
1795+ */
1796+ test ( 'should throw ProtocolError for disabled tool' , async ( ) => {
1797+ const mcpServer = new McpServer ( {
1798+ name : 'test server' ,
1799+ version : '1.0'
1800+ } ) ;
1801+
1802+ const client = new Client ( {
1803+ name : 'test client' ,
1804+ version : '1.0'
1805+ } ) ;
1806+
1807+ const tool = mcpServer . registerTool ( 'test-tool' , { } , async ( ) => ( {
1808+ content : [
17901809 {
17911810 type : 'text' ,
1792- text : expect . stringContaining ( 'Tool nonexistent-tool not found' )
1811+ text : 'Test response'
17931812 }
1794- ] )
1795- ) ;
1813+ ]
1814+ } ) ) ;
1815+
1816+ tool . disable ( ) ;
1817+
1818+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
1819+
1820+ await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
1821+
1822+ await expect (
1823+ client . request ( {
1824+ method : 'tools/call' ,
1825+ params : {
1826+ name : 'test-tool'
1827+ }
1828+ } )
1829+ ) . rejects . toMatchObject ( {
1830+ code : ProtocolErrorCode . InvalidParams ,
1831+ message : expect . stringContaining ( 'disabled' )
1832+ } ) ;
17961833 } ) ;
17971834
17981835 /***
@@ -2797,7 +2834,51 @@ describe('Zod v4', () => {
27972834 uri : 'test://nonexistent'
27982835 }
27992836 } )
2800- ) . rejects . toThrow ( / R e s o u r c e t e s t : \/ \/ n o n e x i s t e n t n o t f o u n d / ) ;
2837+ ) . rejects . toMatchObject ( {
2838+ code : ProtocolErrorCode . ResourceNotFound ,
2839+ message : expect . stringContaining ( 'not found' )
2840+ } ) ;
2841+ } ) ;
2842+
2843+ /***
2844+ * Test: ProtocolError for Disabled Resource
2845+ */
2846+ test ( 'should throw ProtocolError for disabled resource' , async ( ) => {
2847+ const mcpServer = new McpServer ( {
2848+ name : 'test server' ,
2849+ version : '1.0'
2850+ } ) ;
2851+ const client = new Client ( {
2852+ name : 'test client' ,
2853+ version : '1.0'
2854+ } ) ;
2855+
2856+ const resource = mcpServer . registerResource ( 'test' , 'test://resource' , { } , async ( ) => ( {
2857+ contents : [
2858+ {
2859+ uri : 'test://resource' ,
2860+ text : 'Test content'
2861+ }
2862+ ]
2863+ } ) ) ;
2864+
2865+ resource . disable ( ) ;
2866+
2867+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
2868+
2869+ await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
2870+
2871+ await expect (
2872+ client . request ( {
2873+ method : 'resources/read' ,
2874+ params : {
2875+ uri : 'test://resource'
2876+ }
2877+ } )
2878+ ) . rejects . toMatchObject ( {
2879+ code : ProtocolErrorCode . InvalidParams ,
2880+ message : expect . stringContaining ( 'disabled' )
2881+ } ) ;
28012882 } ) ;
28022883
28032884 /***
@@ -3693,7 +3774,10 @@ describe('Zod v4', () => {
36933774 name : 'nonexistent-prompt'
36943775 }
36953776 } )
3696- ) . rejects . toThrow ( / P r o m p t n o n e x i s t e n t - p r o m p t n o t f o u n d / ) ;
3777+ ) . rejects . toMatchObject ( {
3778+ code : ProtocolErrorCode . InvalidParams ,
3779+ message : expect . stringContaining ( 'not found' )
3780+ } ) ;
36973781 } ) ;
36983782
36993783 /***
0 commit comments