π The fast, Pythonic way to build MCP servers and clients.
Fix tests
Jeremiah Lowinfae91fa2f6f2
diff --git a/src/fastmcp/resources/types.py b/src/fastmcp/resources/types.pyindex c5363a6d3..0b13816ec 100644--- a/src/fastmcp/resources/types.py+++ b/src/fastmcp/resources/types.py@@ -8,7 +8,7 @@ from typing import Any, Callable, Unionimport httpximport pydantic.jsonimport pydantic_core-from pydantic import Field+from pydantic import Field, ValidationInfofrom fastmcp.resources.base import Resource@@ -91,6 +91,15 @@ class FileResource(Resource):raise ValueError("Path must be absolute")return path+ @pydantic.field_validator("is_binary")+ @classmethod+ def set_binary_from_mime_type(cls, is_binary: bool, info: ValidationInfo) -> bool:+ """Set is_binary based on mime_type if not explicitly set."""+ if is_binary:+ return True+ mime_type = info.data.get("mime_type", "text/plain")+ return not mime_type.startswith("text/")+async def read(self) -> Union[str, bytes]:"""Read the file content."""try:diff --git a/tests/resources/test_resource_template.py b/tests/resources/test_resource_template.pyindex af45e6bb3..9b459d7b1 100644--- a/tests/resources/test_resource_template.py+++ b/tests/resources/test_resource_template.py@@ -22,7 +22,8 @@ class TestResourceTemplate:assert template.uri_template == "test://{key}/{value}"assert template.name == "test"assert template.mime_type == "text/plain" # default- assert template.fn == my_func+ test_input = {"key": "test", "value": 42}+ assert template.fn(**test_input) == my_func(**test_input)def test_template_matches(self):"""Test matching URIs against a template."""