Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
6bf02ba
1
Parent(s): 6e546c4
Deprecate top-level import
Browse files- docs/servers/tools.mdx +3 -1
- examples/screenshot.py +2 -1
- src/fastmcp/__init__.py +27 -7
- tests/tools/test_tool.py +2 -1
- tests/tools/test_tool_manager.py +2 -1
docs/servers/tools.mdx
CHANGED
|
@@ -266,8 +266,10 @@ At this time, FastMCP responds only to your tool's return *value*, not its retur
|
|
| 266 |
</Tip>
|
| 267 |
|
| 268 |
```python
|
| 269 |
-
from fastmcp import FastMCP
|
|
|
|
| 270 |
import io
|
|
|
|
| 271 |
try:
|
| 272 |
from PIL import Image as PILImage
|
| 273 |
except ImportError:
|
|
|
|
| 266 |
</Tip>
|
| 267 |
|
| 268 |
```python
|
| 269 |
+
from fastmcp import FastMCP
|
| 270 |
+
from fastmcp.utilities.types import Image
|
| 271 |
import io
|
| 272 |
+
|
| 273 |
try:
|
| 274 |
from PIL import Image as PILImage
|
| 275 |
except ImportError:
|
examples/screenshot.py
CHANGED
|
@@ -6,7 +6,8 @@ Give Claude a tool to capture and view screenshots.
|
|
| 6 |
|
| 7 |
import io
|
| 8 |
|
| 9 |
-
from fastmcp import FastMCP
|
|
|
|
| 10 |
|
| 11 |
# Create server
|
| 12 |
mcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"])
|
|
|
|
| 6 |
|
| 7 |
import io
|
| 8 |
|
| 9 |
+
from fastmcp import FastMCP
|
| 10 |
+
from fastmcp.utilities.types import Image
|
| 11 |
|
| 12 |
# Create server
|
| 13 |
mcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"])
|
src/fastmcp/__init__.py
CHANGED
|
@@ -11,20 +11,40 @@ from fastmcp.server.context import Context
|
|
| 11 |
import fastmcp.server
|
| 12 |
|
| 13 |
from fastmcp.client import Client
|
| 14 |
-
from fastmcp.utilities.types import Image
|
| 15 |
from . import client
|
| 16 |
|
| 17 |
__version__ = version("fastmcp")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
__all__ = [
|
| 19 |
"FastMCP",
|
| 20 |
"Context",
|
| 21 |
"client",
|
| 22 |
"Client",
|
| 23 |
"settings",
|
| 24 |
-
"Image",
|
| 25 |
]
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
# ensure deprecation warnings are displayedby default
|
| 29 |
-
if settings.deprecation_warnings:
|
| 30 |
-
warnings.simplefilter("default", DeprecationWarning)
|
|
|
|
| 11 |
import fastmcp.server
|
| 12 |
|
| 13 |
from fastmcp.client import Client
|
|
|
|
| 14 |
from . import client
|
| 15 |
|
| 16 |
__version__ = version("fastmcp")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# ensure deprecation warnings are displayed by default
|
| 20 |
+
if settings.deprecation_warnings:
|
| 21 |
+
warnings.simplefilter("default", DeprecationWarning)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def __getattr__(name: str):
|
| 25 |
+
"""
|
| 26 |
+
Used to deprecate the module-level Image class; can be removed once it is no longer imported to root.
|
| 27 |
+
"""
|
| 28 |
+
if name == "Image":
|
| 29 |
+
# Deprecated in 2.8.1
|
| 30 |
+
if settings.deprecation_warnings:
|
| 31 |
+
warnings.warn(
|
| 32 |
+
"The top-level `fastmcp.Image` import is deprecated "
|
| 33 |
+
"and will be removed in a future version. "
|
| 34 |
+
"Please use `fastmcp.utilities.types.Image` instead.",
|
| 35 |
+
DeprecationWarning,
|
| 36 |
+
stacklevel=2,
|
| 37 |
+
)
|
| 38 |
+
from fastmcp.utilities.types import Image
|
| 39 |
+
|
| 40 |
+
return Image
|
| 41 |
+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
__all__ = [
|
| 45 |
"FastMCP",
|
| 46 |
"Context",
|
| 47 |
"client",
|
| 48 |
"Client",
|
| 49 |
"settings",
|
|
|
|
| 50 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/tools/test_tool.py
CHANGED
|
@@ -2,11 +2,12 @@ import pytest
|
|
| 2 |
from mcp.types import EmbeddedResource, ImageContent, TextContent, TextResourceContents
|
| 3 |
from pydantic import AnyUrl, BaseModel
|
| 4 |
|
| 5 |
-
from fastmcp import FastMCP
|
| 6 |
from fastmcp.client import Client
|
| 7 |
from fastmcp.exceptions import ToolError
|
| 8 |
from fastmcp.tools.tool import Tool, _convert_to_content
|
| 9 |
from fastmcp.utilities.tests import temporary_settings
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
class TestToolFromFunction:
|
|
|
|
| 2 |
from mcp.types import EmbeddedResource, ImageContent, TextContent, TextResourceContents
|
| 3 |
from pydantic import AnyUrl, BaseModel
|
| 4 |
|
| 5 |
+
from fastmcp import FastMCP
|
| 6 |
from fastmcp.client import Client
|
| 7 |
from fastmcp.exceptions import ToolError
|
| 8 |
from fastmcp.tools.tool import Tool, _convert_to_content
|
| 9 |
from fastmcp.utilities.tests import temporary_settings
|
| 10 |
+
from fastmcp.utilities.types import Image
|
| 11 |
|
| 12 |
|
| 13 |
class TestToolFromFunction:
|
tests/tools/test_tool_manager.py
CHANGED
|
@@ -8,11 +8,12 @@ import pytest
|
|
| 8 |
from mcp.types import ImageContent
|
| 9 |
from pydantic import BaseModel
|
| 10 |
|
| 11 |
-
from fastmcp import Context, FastMCP
|
| 12 |
from fastmcp.exceptions import NotFoundError, ToolError
|
| 13 |
from fastmcp.tools import FunctionTool, ToolManager
|
| 14 |
from fastmcp.tools.tool import Tool
|
| 15 |
from fastmcp.utilities.tests import temporary_settings
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
class TestAddTools:
|
|
|
|
| 8 |
from mcp.types import ImageContent
|
| 9 |
from pydantic import BaseModel
|
| 10 |
|
| 11 |
+
from fastmcp import Context, FastMCP
|
| 12 |
from fastmcp.exceptions import NotFoundError, ToolError
|
| 13 |
from fastmcp.tools import FunctionTool, ToolManager
|
| 14 |
from fastmcp.tools.tool import Tool
|
| 15 |
from fastmcp.utilities.tests import temporary_settings
|
| 16 |
+
from fastmcp.utilities.types import Image
|
| 17 |
|
| 18 |
|
| 19 |
class TestAddTools:
|