@@ -751,36 +751,6 @@ def failing_resource():
751751 with pytest .raises (MCPError , match = "Error reading resource resource://failing" ):
752752 await client .read_resource ("resource://failing" )
753753
754- async def test_read_resource_template_error (self ):
755- """Template-creation failure must surface as INTERNAL_ERROR, not INVALID_PARAMS (not-found)."""
756- mcp = MCPServer ()
757-
758- @mcp .resource ("resource://item/{item_id}" )
759- def get_item (item_id : str ) -> str :
760- raise RuntimeError ("backend unavailable" )
761-
762- async with Client (mcp ) as client :
763- with pytest .raises (MCPError , match = "Error creating resource from template" ) as exc_info :
764- await client .read_resource ("resource://item/42" )
765-
766- assert exc_info .value .error .code == INTERNAL_ERROR
767- assert exc_info .value .error .code != INVALID_PARAMS
768-
769- async def test_read_resource_template_not_found (self ):
770- """A template handler raising ResourceNotFoundError must surface as INVALID_PARAMS per SEP-2164."""
771- mcp = MCPServer ()
772-
773- @mcp .resource ("resource://users/{user_id}" )
774- def get_user (user_id : str ) -> str :
775- raise ResourceNotFoundError (f"no user { user_id } " )
776-
777- async with Client (mcp ) as client :
778- with pytest .raises (MCPError , match = "no user 999" ) as exc_info :
779- await client .read_resource ("resource://users/999" )
780-
781- assert exc_info .value .error .code == INVALID_PARAMS
782- assert exc_info .value .error .data == {"uri" : "resource://users/999" }
783-
784754 async def test_binary_resource (self ):
785755 mcp = MCPServer ()
786756
@@ -1551,3 +1521,35 @@ async def test_report_progress_passes_related_request_id():
15511521 message = "halfway" ,
15521522 related_request_id = "req-abc-123" ,
15531523 )
1524+
1525+
1526+ async def test_read_resource_template_error ():
1527+ """Template-creation failure must surface as INTERNAL_ERROR, not INVALID_PARAMS (not-found)."""
1528+ mcp = MCPServer ()
1529+
1530+ @mcp .resource ("resource://item/{item_id}" )
1531+ def get_item (item_id : str ) -> str :
1532+ raise RuntimeError ("backend unavailable" )
1533+
1534+ async with Client (mcp ) as client :
1535+ with pytest .raises (MCPError , match = "Error creating resource from template" ) as exc_info :
1536+ await client .read_resource ("resource://item/42" )
1537+
1538+ assert exc_info .value .error .code == INTERNAL_ERROR
1539+ assert exc_info .value .error .code != INVALID_PARAMS
1540+
1541+
1542+ async def test_read_resource_template_not_found ():
1543+ """A template handler raising ResourceNotFoundError must surface as INVALID_PARAMS per SEP-2164."""
1544+ mcp = MCPServer ()
1545+
1546+ @mcp .resource ("resource://users/{user_id}" )
1547+ def get_user (user_id : str ) -> str :
1548+ raise ResourceNotFoundError (f"no user { user_id } " )
1549+
1550+ async with Client (mcp ) as client :
1551+ with pytest .raises (MCPError , match = "no user 999" ) as exc_info :
1552+ await client .read_resource ("resource://users/999" )
1553+
1554+ assert exc_info .value .error .code == INVALID_PARAMS
1555+ assert exc_info .value .error .data == {"uri" : "resource://users/999" }
0 commit comments