π The fast, Pythonic way to build MCP servers and clients.
Respect cache setting, set default to 1
Jeremiah Lowinc89384784607
diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.pyindex 9928ad152..4395a7aca 100644--- a/src/fastmcp/server/server.py+++ b/src/fastmcp/server/server.py@@ -41,6 +41,7 @@ from starlette.requests import Requestfrom starlette.responses import Responsefrom starlette.routing import BaseRoute, Route+import fastmcpimport fastmcp.serverimport fastmcp.settingsfrom fastmcp.exceptions import NotFoundError@@ -131,6 +132,8 @@ class FastMCP(Generic[LifespanResultT]):tools: list[Tool | Callable[..., Any]] | None = None,**settings: Any,):+ if cache_expiration_seconds is not None:+ settings["cache_expiration_seconds"] = cache_expiration_secondsself.settings = fastmcp.settings.ServerSettings(**settings)# If mask_error_details is provided, override the settings value@@ -148,7 +151,9 @@ class FastMCP(Generic[LifespanResultT]):self.tags: set[str] = tags or set()self.dependencies = dependenciesself._cache = TimedCache(- expiration=datetime.timedelta(seconds=cache_expiration_seconds or 0)+ expiration=datetime.timedelta(+ seconds=self.settings.cache_expiration_seconds+ ))self._mounted_servers: dict[str, MountedServer] = {}self._additional_http_routes: list[BaseRoute] = []diff --git a/src/fastmcp/settings.py b/src/fastmcp/settings.pyindex 96939d11c..3c66ad3ae 100644--- a/src/fastmcp/settings.py+++ b/src/fastmcp/settings.py@@ -170,8 +170,8 @@ class ServerSettings(BaseSettings):),] = []- # cache settings (for checking mounted servers)- cache_expiration_seconds: float = 0+ # cache settings (for getting attributes from servers, used to avoid repeated calls)+ cache_expiration_seconds: float = 1# StreamableHTTP settingsjson_response: bool = False