Add tests for MCPServer.read_resource exception handling (#1957)

This commit is contained in:
Marcelo Trylesinski 2026-01-27 13:49:06 +01:00 • committed by GitHub
commit 14744c66c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ import pytest
from mcp import Client
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.exceptions import ResourceError
from mcp.types import (
ListResourceTemplatesResult,
TextResourceContents,
@ -54,10 +55,10 @@ async def test_resource_template_edge_cases():
assert result_list[0].mime_type == "text/plain"
# Verify invalid parameters raise error
with pytest.raises(ValueError, match="Unknown resource"):
with pytest.raises(ResourceError, match="Unknown resource"):
await mcp.read_resource("resource://users/123/posts") # Missing post_id
with pytest.raises(ValueError, match="Unknown resource"):
with pytest.raises(ResourceError, match="Unknown resource"):
await mcp.read_resource("resource://users/123/posts/456/extra") # Extra path component