Remove deprecated dependencies parameter from FastMCP constructor (#2340)

This commit is contained in:
Jeremiah Lowin 2025-11-01 12:48:08 -07:00 committed by GitHub
commit 1c885c48e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 18 additions and 102 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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:

View file

@ -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
)

View file

@ -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