@@ -1831,22 +1831,59 @@ describe('Zod v4', () => {
18311831
18321832 await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
18331833
1834- const result = await client . request ( {
1835- method : 'tools/call' ,
1836- params : {
1837- name : 'nonexistent-tool'
1838- }
1834+ await expect (
1835+ client . request ( {
1836+ method : 'tools/call' ,
1837+ params : {
1838+ name : 'nonexistent-tool'
1839+ }
1840+ } )
1841+ ) . rejects . toMatchObject ( {
1842+ code : ProtocolErrorCode . InvalidParams ,
1843+ message : expect . stringContaining ( 'nonexistent-tool' )
18391844 } ) ;
1845+ } ) ;
18401846
1841- expect ( result . isError ) . toBe ( true ) ;
1842- expect ( result . content ) . toEqual (
1843- expect . arrayContaining ( [
1847+ /***
1848+ * Test: ProtocolError for Disabled Tool
1849+ */
1850+ test ( 'should throw ProtocolError for disabled tool' , async ( ) => {
1851+ const mcpServer = new McpServer ( {
1852+ name : 'test server' ,
1853+ version : '1.0'
1854+ } ) ;
1855+
1856+ const client = new Client ( {
1857+ name : 'test client' ,
1858+ version : '1.0'
1859+ } ) ;
1860+
1861+ const tool = mcpServer . registerTool ( 'test-tool' , { } , async ( ) => ( {
1862+ content : [
18441863 {
18451864 type : 'text' ,
1846- text : expect . stringContaining ( 'Tool nonexistent-tool not found' )
1865+ text : 'Test response'
18471866 }
1848- ] )
1849- ) ;
1867+ ]
1868+ } ) ) ;
1869+
1870+ tool . disable ( ) ;
1871+
1872+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
1873+
1874+ await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
1875+
1876+ await expect (
1877+ client . request ( {
1878+ method : 'tools/call' ,
1879+ params : {
1880+ name : 'test-tool'
1881+ }
1882+ } )
1883+ ) . rejects . toMatchObject ( {
1884+ code : ProtocolErrorCode . InvalidParams ,
1885+ message : expect . stringContaining ( 'disabled' )
1886+ } ) ;
18501887 } ) ;
18511888
18521889 /***
@@ -2851,7 +2888,51 @@ describe('Zod v4', () => {
28512888 uri : 'test://nonexistent'
28522889 }
28532890 } )
2854- ) . 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 / ) ;
2891+ ) . rejects . toMatchObject ( {
2892+ code : ProtocolErrorCode . ResourceNotFound ,
2893+ message : expect . stringContaining ( 'not found' )
2894+ } ) ;
2895+ } ) ;
2896+
2897+ /***
2898+ * Test: ProtocolError for Disabled Resource
2899+ */
2900+ test ( 'should throw ProtocolError for disabled resource' , async ( ) => {
2901+ const mcpServer = new McpServer ( {
2902+ name : 'test server' ,
2903+ version : '1.0'
2904+ } ) ;
2905+ const client = new Client ( {
2906+ name : 'test client' ,
2907+ version : '1.0'
2908+ } ) ;
2909+
2910+ const resource = mcpServer . registerResource ( 'test' , 'test://resource' , { } , async ( ) => ( {
2911+ contents : [
2912+ {
2913+ uri : 'test://resource' ,
2914+ text : 'Test content'
2915+ }
2916+ ]
2917+ } ) ) ;
2918+
2919+ resource . disable ( ) ;
2920+
2921+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
2922+
2923+ await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
2924+
2925+ await expect (
2926+ client . request ( {
2927+ method : 'resources/read' ,
2928+ params : {
2929+ uri : 'test://resource'
2930+ }
2931+ } )
2932+ ) . rejects . toMatchObject ( {
2933+ code : ProtocolErrorCode . InvalidParams ,
2934+ message : expect . stringContaining ( 'disabled' )
2935+ } ) ;
28552936 } ) ;
28562937
28572938 /***
@@ -3747,7 +3828,10 @@ describe('Zod v4', () => {
37473828 name : 'nonexistent-prompt'
37483829 }
37493830 } )
3750- ) . 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 / ) ;
3831+ ) . rejects . toMatchObject ( {
3832+ code : ProtocolErrorCode . InvalidParams ,
3833+ message : expect . stringContaining ( 'not found' )
3834+ } ) ;
37513835 } ) ;
37523836
37533837 /***
0 commit comments