You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Individual projects can be routed through the cloud while others stay local, using an API key:
358
+
359
+
```bash
360
+
# Save API key and set project to cloud mode
361
+
basic-memory cloud set-key bmc_abc123...
362
+
basic-memory project set-cloud research # route through cloud
363
+
basic-memory project set-local research # revert to local
364
+
```
365
+
366
+
MCP tools use `get_project_client()` which automatically routes based on the project's mode. Cloud projects use the `cloud_api_key` from config as Bearer token.
367
+
368
+
**CLI Routing Flags (Global Cloud Mode):**
333
369
334
-
When cloud mode is enabled, CLI commands route to the cloud API by default. Use `--local` and `--cloud` flags to override:
370
+
When global cloud mode is enabled, CLI commands route to the cloud API by default. Use `--local` and `--cloud` flags to override:
335
371
336
372
```bash
337
373
# Force local routing (ignore cloud mode)
@@ -348,6 +384,7 @@ Key behaviors:
348
384
- This allows simultaneous use of local Claude Desktop and cloud-based clients
349
385
- Some commands (like `project default`, `project sync-config`, `project move`) require `--local` in cloud mode since they modify local configuration
350
386
- Environment variable `BASIC_MEMORY_FORCE_LOCAL=true` forces local routing globally
387
+
- Per-project cloud routing via API key works independently of global cloud mode
**Note**: `RuntimeMode` determines global behavior (e.g., whether to start file sync). Per-project routing is orthogonal — individual projects can be set to `cloud` mode via `ProjectMode` in config, which affects client routing in `get_client(project_name=...)` without changing the global runtime mode.
`get_project_client()` from `mcp/project_context.py` is an async context manager that:
244
+
1. Resolves the project name from config (no network call)
245
+
2. Creates the correctly-routed client based on the project's mode (local ASGI or cloud HTTP with API key)
246
+
3. Validates the project via the API
247
+
4. Yields `(client, active_project)` tuple
248
+
249
+
This solves the bootstrap problem: you need the project name to choose the right client (local vs cloud), but you need the client to validate the project exists.
250
+
251
+
```python
252
+
from basic_memory.mcp.project_context import get_project_client
253
+
254
+
asyncwith get_project_client(project, context) as (client, active_project):
255
+
# client is routed based on project's mode (local or cloud)
0 commit comments