mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 13:04:18 +02:00
Merge branch 'main' into include-exclude
This commit is contained in:
commit
7d2f51535f
3 changed files with 18 additions and 2 deletions
|
|
@ -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] = []
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue