|
1 | 1 | """MCP server command.""" |
2 | 2 |
|
3 | | -import asyncio |
4 | | -from loguru import logger |
5 | | - |
6 | 3 | import basic_memory |
7 | 4 | from basic_memory.cli.app import app |
8 | | -from basic_memory.config import config, config_manager |
9 | | -from basic_memory.services.initialization import initialize_app |
10 | 5 |
|
11 | 6 | # Import mcp instance |
12 | 7 | from basic_memory.mcp.server import mcp as mcp_server # pragma: no cover |
|
17 | 12 |
|
18 | 13 | @app.command() |
19 | 14 | def mcp(): # pragma: no cover |
20 | | - """Run the MCP server for Claude Desktop integration.""" |
21 | | - home_dir = config.home |
22 | | - project_name = config.project |
| 15 | + """Run the MCP server""" |
| 16 | + from basic_memory.config import config |
| 17 | + import asyncio |
| 18 | + from basic_memory.services.initialization import initialize_database |
| 19 | + |
| 20 | + # First, run just the database migrations synchronously |
| 21 | + asyncio.run(initialize_database(config)) |
| 22 | + |
| 23 | + # Load config to check if sync is enabled |
| 24 | + from basic_memory.config import config_manager |
23 | 25 |
|
24 | | - # app config |
25 | 26 | basic_memory_config = config_manager.load_config() |
26 | 27 |
|
27 | | - logger.info(f"Starting Basic Memory MCP server {basic_memory.__version__}") |
28 | | - logger.info(f"Project: {project_name}") |
29 | | - logger.info(f"Project directory: {home_dir}") |
30 | | - |
31 | | - # Run initialization before starting MCP server |
32 | | - # Note: Although we already run migrations via ensure_migrations in the CLI callback, |
33 | | - # we do a full initialization here to ensure file sync is properly set up too |
34 | | - try: |
35 | | - loop = asyncio.new_event_loop() |
36 | | - asyncio.set_event_loop(loop) |
37 | | - loop.run_until_complete(initialize_app(config)) |
38 | | - except Exception as e: |
39 | | - logger.error(f"Error during app initialization: {e}") |
40 | | - logger.info("Continuing with server startup despite initialization error") |
41 | | - |
42 | | - logger.info(f"Sync changes enabled: {basic_memory_config.sync_changes}") |
43 | | - logger.info( |
44 | | - f"Update permalinks on move enabled: {basic_memory_config.update_permalinks_on_move}" |
45 | | - ) |
| 28 | + if basic_memory_config.sync_changes: |
| 29 | + # For now, we'll just log that sync will be handled by the MCP server |
| 30 | + from loguru import logger |
| 31 | + |
| 32 | + logger.info("File sync will be handled by the MCP server") |
46 | 33 |
|
| 34 | + # Start the MCP server |
47 | 35 | mcp_server.run() |
0 commit comments