π The fast, Pythonic way to build MCP servers and clients.
Remove deprecated decorator_mode setting and object-mode machinery
Jeremiah Lowin805ce9668913
diff --git a/docs/getting-started/upgrading/from-fastmcp-2.mdx b/docs/getting-started/upgrading/from-fastmcp-2.mdxindex dc6a0fced..f661cb944 100644--- a/docs/getting-started/upgrading/from-fastmcp-2.mdx+++ b/docs/getting-started/upgrading/from-fastmcp-2.mdx@@ -75,7 +75,7 @@ BREAKING CHANGES (will crash at import or runtime):9. ENV VAR: FASTMCP_SHOW_CLI_BANNER renamed to FASTMCP_SHOW_SERVER_BANNER.10. DECORATORS: @mcp.tool, @mcp.resource, @mcp.prompt now return the original function, not a component object. Code that accesses .name, .description, or other component attributes on the decorated result will crash with AttributeError.- Fix: set FASTMCP_DECORATOR_MODE=object for v2 compat (itself deprecated).+ Fix: access component objects via the server (e.g. await mcp.get_tool("name")) instead of the decorated function. The FASTMCP_DECORATOR_MODE=object escape hatch that existed in v3 was removed in FastMCP 4.0.11. OAUTH STORAGE: Default OAuth client storage changed from DiskStore to FileTreeStore due to pickle deserialization vulnerability in diskcache (CVE-2025-69872). Clients using default storage will re-register automatically on first connection. If using DiskStore explicitly, switch to FileTreeStore (with key/collection sanitization strategies) or add pip install 'py-key-value-aio[disk]'.@@ -317,7 +317,7 @@ def greet(name: str) -> str:greet("World") # Works! Returns "Hello, World!"```-If you have code that treats the decorated result as a `FunctionTool` (e.g., accessing `.name` or `.description`), set `FASTMCP_DECORATOR_MODE=object` for v2 compatibility. This escape hatch is itself deprecated and will be removed in a future release.+If you have code that treats the decorated result as a `FunctionTool` (e.g., accessing `.name` or `.description`), the v2-compatible object-returning behavior was available in v3 via `FASTMCP_DECORATOR_MODE=object`. That escape hatch was removed in FastMCP 4.0 β decorators always return the original function now.**Background tasks require optional dependency**diff --git a/docs/more/settings.mdx b/docs/more/settings.mdxindex b21221183..fab6117a9 100644--- a/docs/more/settings.mdx+++ b/docs/more/settings.mdx@@ -97,5 +97,4 @@ When setting Docket values in a `.env` file, use a **double** underscore: `FASTM| `FASTMCP_HOME` | `Path` | Platform default | Data directory for FastMCP. Defaults to the platform-specific user data directory. || `FASTMCP_ENV_FILE` | `str` | `.env` | Path to the `.env` file to load settings from. Must be set as an environment variable (see above). || `FASTMCP_SERVER_DEPENDENCIES` | `list[str]` | `[]` | Additional dependencies to install in the server environment. |-| `FASTMCP_DECORATOR_MODE` | `Literal["function", "object"]` | `function` | Controls what `@tool`, `@resource`, and `@prompt` decorators return. `function` returns the original function (default); `object` returns component objects (deprecated, will be removed). || `FASTMCP_TEST_MODE` | `bool` | `false` | Enable test mode. |diff --git a/fastmcp_slim/fastmcp/prompts/function_prompt.py b/fastmcp_slim/fastmcp/prompts/function_prompt.pyindex c85203b87..959bebd06 100644--- a/fastmcp_slim/fastmcp/prompts/function_prompt.py+++ b/fastmcp_slim/fastmcp/prompts/function_prompt.py@@ -5,7 +5,6 @@ from __future__ import annotationsimport functoolsimport inspectimport json-import warningsfrom collections.abc import Callablefrom dataclasses import dataclass, fieldfrom types import MethodType@@ -24,9 +23,7 @@ import pydantic_corefrom mcp_types import Iconfrom pydantic.json_schema import SkipJsonSchema-import fastmcp-from fastmcp.decorators import resolve_task_config-from fastmcp.exceptions import FastMCPDeprecationWarning, FastMCPError, PromptError+from fastmcp.exceptions import FastMCPError, PromptErrorfrom fastmcp.prompts.base import Prompt, PromptArgument, PromptResultfrom fastmcp.utilities.async_utils import (call_sync_fn_in_threadpool,@@ -457,23 +454,6 @@ def prompt("See https://gofastmcp.com/servers/prompts#using-with-methods")- def create_prompt(- fn: Callable[..., Any], prompt_name: str | None- ) -> FunctionPrompt:- # Create metadata first, then pass it- prompt_meta = PromptMeta(- name=prompt_name,- version=version,- title=title,- description=description,- icons=icons,- tags=tags,- meta=meta,- task=resolve_task_config(task),- auth=auth,- )- return FunctionPrompt.from_function(fn, metadata=prompt_meta)-def attach_metadata(fn: F, prompt_name: str | None) -> F:metadata = PromptMeta(name=prompt_name,@@ -491,14 +471,6 @@ def prompt(return fndef decorator(fn: F, prompt_name: str | None) -> F:- if fastmcp.settings.decorator_mode == "object":- warnings.warn(- "decorator_mode='object' is deprecated and will be removed in a future version. "- "Decorators now return the original function with metadata attached.",- FastMCPDeprecationWarning,- stacklevel=4,- )- return create_prompt(fn, prompt_name) # type: ignore[return-value] # ty:ignore[invalid-return-type]return attach_metadata(fn, prompt_name)if inspect.isroutine(name_or_fn):diff --git a/fastmcp_slim/fastmcp/resources/function_resource.py b/fastmcp_slim/fastmcp/resources/function_resource.pyindex 833bc81d4..71817f835 100644--- a/fastmcp_slim/fastmcp/resources/function_resource.py+++ b/fastmcp_slim/fastmcp/resources/function_resource.py@@ -4,7 +4,6 @@ from __future__ import annotationsimport functoolsimport inspect-import warningsfrom collections.abc import Callablefrom dataclasses import dataclass, fieldfrom types import MethodType@@ -22,9 +21,6 @@ from mcp_types import Annotations, Iconfrom pydantic import AnyUrlfrom pydantic.json_schema import SkipJsonSchema-import fastmcp-from fastmcp.decorators import resolve_task_config-from fastmcp.exceptions import FastMCPDeprecationWarningfrom fastmcp.resources.base import Resource, ResourceResultfrom fastmcp.utilities.async_utils import (call_sync_fn_in_threadpool,@@ -37,7 +33,6 @@ from fastmcp.utilities.tasks import TaskConfigif TYPE_CHECKING:from docket import Docket- from fastmcp.resources.template import ResourceTemplateF = TypeVar("F", bound=Callable[..., Any])@@ -275,51 +270,6 @@ def resource("Use @resource('uri') instead of @resource")- def create_resource(fn: Callable[..., Any]) -> FunctionResource | ResourceTemplate:- from fastmcp.resources.template import ResourceTemplate- from fastmcp.server.dependencies import without_injected_parameters-- resolved = resolve_task_config(task)- has_uri_params = "{" in uri and "}" in uri- wrapper_fn = without_injected_parameters(fn)- has_func_params = bool(inspect.signature(wrapper_fn).parameters)-- # Create metadata first- resource_meta = ResourceMeta(- uri=uri,- name=name,- version=version,- title=title,- description=description,- icons=icons,- tags=tags,- mime_type=mime_type,- annotations=annotations,- meta=meta,- task=resolved,- auth=auth,- )-- if has_uri_params or has_func_params:- # ResourceTemplate doesn't have metadata support yet, so pass individual params- return ResourceTemplate.from_function(- fn=fn,- uri_template=uri,- name=name,- version=version,- title=title,- description=description,- icons=icons,- mime_type=mime_type,- tags=tags,- annotations=annotations,- meta=meta,- task=resolved,- auth=auth,- )- else:- return FunctionResource.from_function(fn, metadata=resource_meta)-def attach_metadata(fn: F) -> F:metadata = ResourceMeta(uri=uri,@@ -340,14 +290,6 @@ def resource(return fndef decorator(fn: F) -> F:- if fastmcp.settings.decorator_mode == "object":- warnings.warn(- "decorator_mode='object' is deprecated and will be removed in a future version. "- "Decorators now return the original function with metadata attached.",- FastMCPDeprecationWarning,- stacklevel=3,- )- return create_resource(fn) # type: ignore[return-value] # ty:ignore[invalid-return-type]return attach_metadata(fn)return decoratordiff --git a/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py b/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.pyindex 5564df32d..ba1621875 100644--- a/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py+++ b/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py@@ -13,7 +13,6 @@ from typing import TYPE_CHECKING, Any, TypeVar, overloadimport mcp_types-import fastmcpfrom fastmcp.prompts.base import Promptfrom fastmcp.prompts.function_prompt import FunctionPromptfrom fastmcp.server.auth.authorization import AuthCheck@@ -189,44 +188,24 @@ class PromptDecoratorMixin:f"See https://gofastmcp.com/servers/prompts#using-with-methods")- resolved_task: bool | TaskConfig = task if task is not None else False-- if fastmcp.settings.decorator_mode == "object":- prompt_obj = Prompt.from_function(- fn,- name=prompt_name,- version=version,- title=title,- description=description,- icons=icons,- tags=tags,- meta=meta,- task=resolved_task,- auth=auth,- )- self._add_component(prompt_obj)- if not enabled:- self.disable(keys={prompt_obj.key})- return prompt_obj- else:- from fastmcp.prompts.function_prompt import PromptMeta+ from fastmcp.prompts.function_prompt import PromptMeta- metadata = PromptMeta(- name=prompt_name,- version=version,- title=title,- description=description,- icons=icons,- tags=tags,- meta=meta,- task=task,- auth=auth,- enabled=enabled,- )- target = fn.__func__ if hasattr(fn, "__func__") else fn- target.__fastmcp__ = metadata # type: ignore[attr-defined] # ty:ignore[unresolved-attribute]- self.add_prompt(fn)- return fn+ metadata = PromptMeta(+ name=prompt_name,+ version=version,+ title=title,+ description=description,+ icons=icons,+ tags=tags,+ meta=meta,+ task=task,+ auth=auth,+ enabled=enabled,+ )+ target = fn.__func__ if hasattr(fn, "__func__") else fn+ target.__fastmcp__ = metadata # type: ignore[attr-defined] # ty:ignore[unresolved-attribute]+ self.add_prompt(fn)+ return fnif inspect.isroutine(name_or_fn):return decorate_and_register(name_or_fn, name)diff --git a/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/resources.py b/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/resources.pyindex cfbf3e40e..c9cb475ac 100644--- a/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/resources.py+++ b/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/resources.py@@ -13,9 +13,7 @@ from typing import TYPE_CHECKING, Any, TypeVarimport mcp_typesfrom mcp_types import Annotations-import fastmcpfrom fastmcp.resources.base import Resource-from fastmcp.resources.function_resource import resource as standalone_resourcefrom fastmcp.resources.template import ResourceTemplatefrom fastmcp.server.auth.authorization import AuthCheckfrom fastmcp.server.tasks.config import TaskConfig@@ -167,8 +165,6 @@ class ResourceDecoratorMixin:"Use @resource('uri') instead of @resource")- resolved_task: bool | TaskConfig = task if task is not None else False-def decorator(fn: AnyFunction) -> Any:# Check for unbound methodtry:@@ -190,54 +186,26 @@ class ResourceDecoratorMixin:f"See https://gofastmcp.com/servers/resources#using-with-methods")- if fastmcp.settings.decorator_mode == "object":- create_resource = standalone_resource(- uri,- name=name,- version=version,- title=title,- description=description,- icons=icons,- mime_type=mime_type,- tags=tags,- annotations=annotations,- meta=meta,- task=resolved_task,- auth=auth,- )- obj = create_resource(fn)- # In legacy mode, standalone_resource always returns a component- assert isinstance(obj, (Resource, ResourceTemplate))- if isinstance(obj, ResourceTemplate):- self.add_template(obj)- if not enabled:- self.disable(keys={obj.key})- else:- self.add_resource(obj)- if not enabled:- self.disable(keys={obj.key})- return obj- else:- from fastmcp.resources.function_resource import ResourceMeta-- metadata = ResourceMeta(- uri=uri,- name=name,- version=version,- title=title,- description=description,- icons=icons,- tags=tags,- mime_type=mime_type,- annotations=annotations,- meta=meta,- task=task,- auth=auth,- enabled=enabled,- )- target = fn.__func__ if hasattr(fn, "__func__") else fn- target.__fastmcp__ = metadata # type: ignore[attr-defined] # ty:ignore[unresolved-attribute]- self.add_resource(fn)- return fn+ from fastmcp.resources.function_resource import ResourceMeta++ metadata = ResourceMeta(+ uri=uri,+ name=name,+ version=version,+ title=title,+ description=description,+ icons=icons,+ tags=tags,+ mime_type=mime_type,+ annotations=annotations,+ meta=meta,+ task=task,+ auth=auth,+ enabled=enabled,+ )+ target = fn.__func__ if hasattr(fn, "__func__") else fn+ target.__fastmcp__ = metadata # type: ignore[attr-defined] # ty:ignore[unresolved-attribute]+ self.add_resource(fn)+ return fnreturn decoratordiff --git a/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/tools.py b/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/tools.pyindex ee61b5a14..dcf1c0a2d 100644--- a/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/tools.py+++ b/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/tools.py@@ -25,7 +25,6 @@ from typing import (import mcp_typesfrom mcp_types import ToolAnnotations-import fastmcpfrom fastmcp.server.auth.authorization import AuthCheckfrom fastmcp.server.tasks.config import TaskConfigfrom fastmcp.tools.base import Tool@@ -308,53 +307,28 @@ class ToolDecoratorMixin:f"See https://gofastmcp.com/servers/tools#using-with-methods")- resolved_task: bool | TaskConfig = task if task is not None else False-- if fastmcp.settings.decorator_mode == "object":- tool_obj = Tool.from_function(- fn,- name=tool_name,- version=version,- title=title,- description=description,- icons=icons,- tags=tags,- output_schema=output_schema,- annotations=annotations,- meta=meta,- task=resolved_task,- timeout=timeout,- auth=auth,- run_in_thread=run_in_thread,- )- self._add_component(tool_obj)- if not enabled:- self.disable(keys={tool_obj.key})- _maybe_apply_prefab_ui(self, tool_obj)- return tool_obj- else:- from fastmcp.tools.function_tool import ToolMeta-- metadata = ToolMeta(- name=tool_name,- version=version,- title=title,- description=description,- icons=icons,- tags=tags,- output_schema=output_schema,- annotations=annotations,- meta=meta,- task=task,- timeout=timeout,- auth=auth,- enabled=enabled,- run_in_thread=run_in_thread,- )- target = fn.__func__ if hasattr(fn, "__func__") else fn- target.__fastmcp__ = metadata # type: ignore[attr-defined] # ty:ignore[unresolved-attribute]- tool_obj = self.add_tool(fn)- return fn+ from fastmcp.tools.function_tool import ToolMeta++ metadata = ToolMeta(+ name=tool_name,+ version=version,+ title=title,+ description=description,+ icons=icons,+ tags=tags,+ output_schema=output_schema,+ annotations=annotations,+ meta=meta,+ task=task,+ timeout=timeout,+ auth=auth,+ enabled=enabled,+ run_in_thread=run_in_thread,+ )+ target = fn.__func__ if hasattr(fn, "__func__") else fn+ target.__fastmcp__ = metadata # type: ignore[attr-defined] # ty:ignore[unresolved-attribute]+ self.add_tool(fn)+ return fnif inspect.isroutine(name_or_fn):return decorate_and_register(name_or_fn, name)diff --git a/fastmcp_slim/fastmcp/settings.py b/fastmcp_slim/fastmcp/settings.pyindex 03a61f011..be933ee56 100644--- a/fastmcp_slim/fastmcp/settings.py+++ b/fastmcp_slim/fastmcp/settings.py@@ -396,20 +396,3 @@ class Settings(BaseSettings):),),] = "stable"-- decorator_mode: Annotated[- Literal["function", "object"],- Field(- description=inspect.cleandoc(- """- Controls what decorators (@tool, @resource, @prompt) return.-- - "function" (default): Decorators return the original function unchanged.- The function remains callable and is registered with the server normally.- - "object" (deprecated): Decorators return component objects (FunctionTool,- FunctionResource, FunctionPrompt). This was the default behavior in v2 and- will be removed in a future version.- """- ),- ),- ] = "function"diff --git a/fastmcp_slim/fastmcp/tools/function_tool.py b/fastmcp_slim/fastmcp/tools/function_tool.pyindex bfe8b9c0a..dd4c236e1 100644--- a/fastmcp_slim/fastmcp/tools/function_tool.py+++ b/fastmcp_slim/fastmcp/tools/function_tool.py@@ -5,7 +5,6 @@ from __future__ import annotationsimport functoolsimport inspectimport logging-import warningsfrom collections.abc import Callablefrom dataclasses import dataclass, fieldfrom functools import lru_cache@@ -30,9 +29,8 @@ from pydantic import Field, TypeAdapterfrom pydantic import ValidationError as PydanticValidationErrorfrom pydantic.json_schema import SkipJsonSchema-import fastmcp-from fastmcp.decorators import get_fastmcp_meta, resolve_task_config-from fastmcp.exceptions import FastMCPDeprecationWarning, ValidationError+from fastmcp.decorators import get_fastmcp_meta+from fastmcp.exceptions import ValidationErrorfrom fastmcp.tools.base import (Tool,ToolResult,@@ -643,25 +641,6 @@ def tool("See https://gofastmcp.com/servers/tools#using-with-methods")- def create_tool(fn: Callable[..., Any], tool_name: str | None) -> FunctionTool:- # Create metadata first, then pass it- tool_meta = ToolMeta(- name=tool_name,- version=version,- title=title,- description=description,- icons=icons,- tags=tags,- output_schema=output_schema,- annotations=annotations,- meta=meta,- task=resolve_task_config(task),- timeout=timeout,- auth=auth,- run_in_thread=run_in_thread,- )- return FunctionTool.from_function(fn, metadata=tool_meta)-def attach_metadata(fn: F, tool_name: str | None) -> F:metadata = ToolMeta(name=tool_name,@@ -683,14 +662,6 @@ def tool(return fndef decorator(fn: F, tool_name: str | None) -> F:- if fastmcp.settings.decorator_mode == "object":- warnings.warn(- "decorator_mode='object' is deprecated and will be removed in a future version. "- "Decorators now return the original function with metadata attached.",- FastMCPDeprecationWarning,- stacklevel=4,- )- return create_tool(fn, tool_name) # type: ignore[return-value] # ty:ignore[invalid-return-type]return attach_metadata(fn, tool_name)if inspect.isroutine(name_or_fn):