File tree Expand file tree Collapse file tree 3 files changed +7
-39
lines changed Expand file tree Collapse file tree 3 files changed +7
-39
lines changed Original file line number Diff line number Diff line change 2222 webdav ,
2323)
2424from basic_memory .config import ConfigManager
25- from basic_memory .services .initialization import initialize_file_sync
25+ from basic_memory .services .initialization import initialize_file_sync , initialize_app
2626
2727
2828@asynccontextmanager
2929async def lifespan (app : FastAPI ): # pragma: no cover
30- """Lifecycle manager for the FastAPI app."""
30+ """Lifecycle manager for the FastAPI app. Not called in stdio mcp mode """
3131
3232 app_config = ConfigManager ().config
3333 logger .info ("Starting Basic Memory API" )
34- print (f"fastapi { app_config .projects } " )
3534
36- # Cache database connections in app state for performance (no project reconciliation)
35+ await initialize_app (app_config )
36+
37+ # Cache database connections in app state for performance
3738 logger .info ("Initializing database and caching connections..." )
3839 engine , session_maker = await db .get_or_create_db (app_config .database_path )
3940 app .state .engine = engine
Original file line number Diff line number Diff line change 1717# Import prompts to register them
1818import basic_memory .mcp .prompts # noqa: F401 # pragma: no cover
1919from loguru import logger
20+ import threading
21+ from basic_memory .services .initialization import initialize_file_sync
2022
2123
2224@app .command ()
@@ -50,10 +52,6 @@ def mcp(
5052 os .environ ["BASIC_MEMORY_MCP_PROJECT" ] = project_name
5153 logger .info (f"MCP server constrained to project: { project_name } " )
5254
53- # Use unified thread-based sync approach for both transports
54- import threading
55- from basic_memory .services .initialization import initialize_file_sync
56-
5755 app_config = ConfigManager ().config
5856
5957 def run_file_sync ():
Original file line number Diff line number Diff line change 22Basic Memory FastMCP server.
33"""
44
5- import asyncio
6- from contextlib import asynccontextmanager
7- from dataclasses import dataclass
8- from typing import AsyncIterator , Optional , Any
9-
105from fastmcp import FastMCP
116
12- from basic_memory .config import ConfigManager
13- from basic_memory .services .initialization import initialize_app
14-
15-
16- @dataclass
17- class AppContext :
18- watch_task : Optional [asyncio .Task ]
19- migration_manager : Optional [Any ] = None
20-
21-
22- @asynccontextmanager
23- async def app_lifespan (server : FastMCP ) -> AsyncIterator [AppContext ]: # pragma: no cover
24- """ """
25- app_config = ConfigManager ().config
26- # Initialize on startup (now returns migration_manager)
27- migration_manager = await initialize_app (app_config )
28-
29- try :
30- yield AppContext (watch_task = None , migration_manager = migration_manager )
31- finally :
32- # Cleanup on shutdown - migration tasks will be cancelled automatically
33- pass
34-
35-
36- # Create the shared server instance with custom Stytch auth
377mcp = FastMCP (
388 name = "Basic Memory" ,
39- lifespan = app_lifespan ,
409)
You can’t perform that action at this time.
0 commit comments