From 1c885c48e7a4ff3d12ec92d965ded766242f40b7 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sat, 1 Nov 2025 12:48:08 -0700 Subject: [PATCH] Remove deprecated dependencies parameter from FastMCP constructor (#2340) --- examples/memory.py | 11 ++----- examples/screenshot.py | 7 ++++- .../src/smart_home/lights/server.py | 15 ++++++---- src/fastmcp/cli/cli.py | 22 +------------- src/fastmcp/cli/install/shared.py | 15 ---------- src/fastmcp/server/server.py | 20 ------------- tests/deprecated/test_dependencies.py | 30 ------------------- 7 files changed, 18 insertions(+), 102 deletions(-) delete mode 100644 tests/deprecated/test_dependencies.py diff --git a/examples/memory.py b/examples/memory.py index c5a3488a4..792bd48c6 100644 --- a/examples/memory.py +++ b/examples/memory.py @@ -34,15 +34,8 @@ REINFORCEMENT_FACTOR = 1.1 DEFAULT_LLM_MODEL = "openai:gpt-4o" DEFAULT_EMBEDDING_MODEL = "text-embedding-3-small" -mcp = FastMCP( - "memory", - dependencies=[ - "pydantic-ai-slim[openai]", - "asyncpg", - "numpy", - "pgvector", - ], -) +# Dependencies are configured in memory.fastmcp.json +mcp = FastMCP("memory") DB_DSN = "postgresql://postgres:postgres@localhost:54320/memory_db" # reset memory by deleting the profile directory diff --git a/examples/screenshot.py b/examples/screenshot.py index 3322c0325..866133733 100644 --- a/examples/screenshot.py +++ b/examples/screenshot.py @@ -1,3 +1,7 @@ +# /// script +# dependencies = ["pyautogui", "Pillow", "fastmcp"] +# /// + """ FastMCP Screenshot Example @@ -10,7 +14,8 @@ from fastmcp import FastMCP from fastmcp.utilities.types import Image # Create server -mcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"]) +# Dependencies are configured in screenshot.fastmcp.json +mcp = FastMCP("Screenshot Demo") @mcp.tool diff --git a/examples/smart_home/src/smart_home/lights/server.py b/examples/smart_home/src/smart_home/lights/server.py index 87e8d4455..aa559b68f 100644 --- a/examples/smart_home/src/smart_home/lights/server.py +++ b/examples/smart_home/src/smart_home/lights/server.py @@ -1,3 +1,10 @@ +# /// script +# dependencies = [ +# "smart_home@git+https://github.com/jlowin/fastmcp.git#subdirectory=examples/smart_home", +# "fastmcp", +# ] +# /// + from typing import Annotated, Any, Literal, TypedDict from phue2.exceptions import PhueException @@ -35,12 +42,8 @@ class HueAttributes(TypedDict, total=False): transitiontime: NotRequired[Annotated[int, Field(description="deciseconds")]] -lights_mcp = FastMCP( - "Hue Lights Service (phue2)", - dependencies=[ - "smart_home@git+https://github.com/jlowin/fastmcp.git#subdirectory=examples/smart_home", - ], -) +# Dependencies are configured in lights.fastmcp.json +lights_mcp = FastMCP("Hue Lights Service (phue2)") @lights_mcp.tool diff --git a/src/fastmcp/cli/cli.py b/src/fastmcp/cli/cli.py index 17d7e1c99..3ed5a3c01 100644 --- a/src/fastmcp/cli/cli.py +++ b/src/fastmcp/cli/cli.py @@ -19,7 +19,6 @@ from rich.table import Table import fastmcp from fastmcp.cli import run as run_module from fastmcp.cli.install import install_app -from fastmcp.server.server import FastMCP from fastmcp.utilities.cli import is_already_in_uv_subprocess, load_and_merge_config from fastmcp.utilities.inspect import ( InspectFormat, @@ -28,7 +27,6 @@ from fastmcp.utilities.inspect import ( ) from fastmcp.utilities.logging import get_logger from fastmcp.utilities.mcp_server_config import MCPServerConfig -from fastmcp.utilities.mcp_server_config.v1.environments.uv import UVEnvironment logger = get_logger("cli") console = Console() @@ -224,29 +222,11 @@ async def dev( ) try: - # Load server to check for deprecated dependencies if not config: logger.error("No configuration available") sys.exit(1) assert config is not None # For type checker - server: FastMCP = await config.source.load_server() - if server.dependencies: - import warnings - - warnings.warn( - f"Server '{server.name}' uses deprecated 'dependencies' parameter (deprecated in FastMCP 2.11.4). " - "Please migrate to fastmcp.json configuration file. " - "See https://gofastmcp.com/docs/deployment/server-configuration for details.", - DeprecationWarning, - stacklevel=2, - ) - # Merge server dependencies with environment dependencies - env_deps = config.environment.dependencies or [] - all_deps = list(set(env_deps + server.dependencies)) - if not config.environment: - config.environment = UVEnvironment(dependencies=all_deps) - else: - config.environment.dependencies = all_deps + await config.source.load_server() env_vars = {} if ui_port: diff --git a/src/fastmcp/cli/install/shared.py b/src/fastmcp/cli/install/shared.py index 3544a2b6b..8e183562a 100644 --- a/src/fastmcp/cli/install/shared.py +++ b/src/fastmcp/cli/install/shared.py @@ -105,21 +105,6 @@ async def process_common_args( ) name = file.stem - # Get server dependencies if available - # TODO: Remove dependencies handling (deprecated in v2.11.4) - server_dependencies = getattr(server, "dependencies", []) if server else [] - if server_dependencies: - import warnings - - warnings.warn( - "Server uses deprecated 'dependencies' parameter (deprecated in FastMCP 2.11.4). " - "Please migrate to fastmcp.json configuration file. " - "See https://gofastmcp.com/docs/deployment/server-configuration for details.", - DeprecationWarning, - stacklevel=2, - ) - with_packages = list(set(with_packages + server_dependencies)) - # Process environment variables if provided env_dict: dict[str, str] | None = None if env_file or env_vars: diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.py index 224fd34cc..17da944c9 100644 --- a/src/fastmcp/server/server.py +++ b/src/fastmcp/server/server.py @@ -3,7 +3,6 @@ from __future__ import annotations import inspect -import json import re import secrets import warnings @@ -157,7 +156,6 @@ class FastMCP(Generic[LifespanResultT]): auth: AuthProvider | NotSetT | None = NotSet, middleware: Sequence[Middleware] | None = None, lifespan: LifespanCallable | None = None, - dependencies: list[str] | None = None, resource_prefix_format: Literal["protocol", "path"] | None = None, mask_error_details: bool | None = None, tools: Sequence[Tool | Callable[..., Any]] | None = None, @@ -258,24 +256,6 @@ class FastMCP(Generic[LifespanResultT]): # Set up MCP protocol handlers self._setup_handlers() - # Handle dependencies with deprecation warning - # TODO: Remove dependencies parameter (deprecated in v2.11.4) - if dependencies is not None: - import warnings - - warnings.warn( - "The 'dependencies' parameter is deprecated as of FastMCP 2.11.4 and will be removed in a future version. " - "Please specify dependencies in a fastmcp.json configuration file instead:\n" - '{\n "entrypoint": "your_server.py",\n "environment": {\n "dependencies": ' - f"{json.dumps(dependencies)}\n }}\n}}\n" - "See https://gofastmcp.com/docs/deployment/server-configuration for more information.", - DeprecationWarning, - stacklevel=2, - ) - self.dependencies: list[str] = ( - dependencies or fastmcp.settings.server_dependencies - ) # TODO: Remove (deprecated in v2.11.4) - self.sampling_handler: ServerSamplingHandler[LifespanResultT] | None = ( sampling_handler ) diff --git a/tests/deprecated/test_dependencies.py b/tests/deprecated/test_dependencies.py deleted file mode 100644 index b8dca71d8..000000000 --- a/tests/deprecated/test_dependencies.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Tests for deprecated dependencies parameter. - -This entire file can be deleted when the dependencies parameter is removed (deprecated in v2.11.4). -""" - -import warnings - -import pytest - -from fastmcp import FastMCP - - -def test_dependencies_parameter_deprecated(): - """Test that using the dependencies parameter raises a deprecation warning.""" - - with pytest.warns(DeprecationWarning, match="deprecated as of FastMCP 2.11.4"): - server = FastMCP("Test Server", dependencies=["pandas", "numpy"]) - - # Should still work for backward compatibility - assert server.dependencies == ["pandas", "numpy"] - - -def test_no_warning_without_dependencies(): - """Test that no warning is raised when dependencies are not used.""" - - with warnings.catch_warnings(): - warnings.simplefilter("error") # Turn warnings into errors - server = FastMCP("Test Server") # Should not raise - - assert server.dependencies == [] # Should use default empty list