π The fast, Pythonic way to build MCP servers and clients.
Deprecate top-level import
Jeremiah Lowin46ab813de613
diff --git a/docs/servers/tools.mdx b/docs/servers/tools.mdxindex cbd41e743..788b94d8a 100644--- a/docs/servers/tools.mdx+++ b/docs/servers/tools.mdx@@ -266,8 +266,10 @@ At this time, FastMCP responds only to your tool's return *value*, not its retur</Tip>```python-from fastmcp import FastMCP, Image+from fastmcp import FastMCP+from fastmcp.utilities.types import Imageimport io+try:from PIL import Image as PILImageexcept ImportError:diff --git a/examples/screenshot.py b/examples/screenshot.pyindex 92b2bdb01..3322c0325 100644--- a/examples/screenshot.py+++ b/examples/screenshot.py@@ -6,7 +6,8 @@ Give Claude a tool to capture and view screenshots.import io-from fastmcp import FastMCP, Image+from fastmcp import FastMCP+from fastmcp.utilities.types import Image# Create servermcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"])diff --git a/src/fastmcp/__init__.py b/src/fastmcp/__init__.pyindex 8685ee767..76038ca2d 100644--- a/src/fastmcp/__init__.py+++ b/src/fastmcp/__init__.py@@ -11,20 +11,40 @@ from fastmcp.server.context import Contextimport fastmcp.serverfrom fastmcp.client import Client-from fastmcp.utilities.types import Imagefrom . import client__version__ = version("fastmcp")+++# ensure deprecation warnings are displayed by default+if settings.deprecation_warnings:+ warnings.simplefilter("default", DeprecationWarning)+++def __getattr__(name: str):+ """+ Used to deprecate the module-level Image class; can be removed once it is no longer imported to root.+ """+ if name == "Image":+ # Deprecated in 2.8.1+ if settings.deprecation_warnings:+ warnings.warn(+ "The top-level `fastmcp.Image` import is deprecated "+ "and will be removed in a future version. "+ "Please use `fastmcp.utilities.types.Image` instead.",+ DeprecationWarning,+ stacklevel=2,+ )+ from fastmcp.utilities.types import Image++ return Image+ raise AttributeError(f"module '{__name__}' has no attribute '{name}'")++__all__ = ["FastMCP","Context","client","Client","settings",- "Image",]---# ensure deprecation warnings are displayedby default-if settings.deprecation_warnings:- warnings.simplefilter("default", DeprecationWarning)diff --git a/tests/tools/test_tool.py b/tests/tools/test_tool.pyindex ab2808fb7..1eb6e30eb 100644--- a/tests/tools/test_tool.py+++ b/tests/tools/test_tool.py@@ -2,11 +2,12 @@ import pytestfrom mcp.types import EmbeddedResource, ImageContent, TextContent, TextResourceContentsfrom pydantic import AnyUrl, BaseModel-from fastmcp import FastMCP, Image+from fastmcp import FastMCPfrom fastmcp.client import Clientfrom fastmcp.exceptions import ToolErrorfrom fastmcp.tools.tool import Tool, _convert_to_contentfrom fastmcp.utilities.tests import temporary_settings+from fastmcp.utilities.types import Imageclass TestToolFromFunction:diff --git a/tests/tools/test_tool_manager.py b/tests/tools/test_tool_manager.pyindex dadf3f000..b5cb15781 100644--- a/tests/tools/test_tool_manager.py+++ b/tests/tools/test_tool_manager.py@@ -8,11 +8,12 @@ import pytestfrom mcp.types import ImageContentfrom pydantic import BaseModel-from fastmcp import Context, FastMCP, Image+from fastmcp import Context, FastMCPfrom fastmcp.exceptions import NotFoundError, ToolErrorfrom fastmcp.tools import FunctionTool, ToolManagerfrom fastmcp.tools.tool import Toolfrom fastmcp.utilities.tests import temporary_settings+from fastmcp.utilities.types import Imageclass TestAddTools: