Merge branch 'main' into include-exclude

This commit is contained in:
Jeremiah Lowin 2025-06-07 18:40:38 -04:00 committed by GitHub
commit 7d2f51535f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View file

@ -41,6 +41,7 @@ from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import BaseRoute, Route
import fastmcp
import fastmcp.server
import fastmcp.settings
from fastmcp.exceptions import NotFoundError
@ -161,7 +162,9 @@ class FastMCP(Generic[LifespanResultT]):
self.dependencies = dependencies
self._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] = []

View file

@ -170,7 +170,7 @@ class ServerSettings(BaseSettings):
),
] = []
# cache settings (for checking mounted servers)
# cache settings (for getting attributes from servers, used to avoid repeated calls)
cache_expiration_seconds: float = 0
# StreamableHTTP settings

View file

@ -304,6 +304,19 @@ class TestDynamicChanges:
tools = await main_app.get_tools()
assert "sub_temp_tool" not in tools
async def test_cache_expiration(self):
main_app = FastMCP("MainApp", cache_expiration_seconds=2)
sub_app = FastMCP("SubApp")
tools = await main_app.get_tools()
assert len(tools) == 0
@sub_app.tool
def sub_tool():
return "sub_tool"
tools = await main_app.get_tools()
assert len(tools) == 0
class TestResourcesAndTemplates:
"""Test mounting with resources and resource templates."""