refactor: require explicit sqlite paths
This commit is contained in:
5 files changed
+20
-18
No files matched your search
@@ -57,16 +57,16 @@ app = App(store=SQLiteStore(Path(".agentmsgs.db")))
|
||||
|
||||
### MCP server
|
||||
|
||||
Start the MCP server over stdio:
|
||||
Start the MCP server over stdio with an explicit SQLite path:
|
||||
|
||||
```bash
|
||||
uv run agentmsgs-mcp --transport stdio
|
||||
uv run agentmsgs-mcp --transport stdio --db-path ./agentmsgs.db
|
||||
```
|
||||
|
||||
Or use HTTP:
|
||||
|
||||
```bash
|
||||
uv run agentmsgs-mcp --transport http
|
||||
uv run agentmsgs-mcp --transport http --db-path ./agentmsgs.db
|
||||
```
|
||||
|
||||
Choose a shared database file when separate clients or processes should communicate:
|
||||
@@ -81,7 +81,7 @@ For a temporary, process-local server, use the in-memory store:
|
||||
uv run agentmsgs-mcp --in-memory --transport stdio
|
||||
```
|
||||
|
||||
The in-memory mode is synchronized for concurrent calls within that server, but its data disappears on restart and is not shared with another server process. The default database is `.agentmsgs.db` in the workspace root.
|
||||
The in-memory mode is synchronized for concurrent calls within that server, but its data disappears on restart and is not shared with another server process. SQLite mode requires an explicit `--db-path`.
|
||||
|
||||
See all server options with:
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
from fastmcp import FastMCP
|
||||
from fastmcp.utilities.logging import get_logger
|
||||
@@ -9,7 +10,6 @@ from agentmsgs.core.app import App
|
||||
from agentmsgs.core.types import Agent, Message
|
||||
from agentmsgs.stores.memory import InMemoryStore
|
||||
from agentmsgs.stores.sqlite import SQLiteStore
|
||||
from agentmsgs.utils import WORKSPACE_ROOT
|
||||
|
||||
logger = get_logger(__name__) # WHY
|
||||
mcp = FastMCP("agentmsgs")
|
||||
@@ -162,7 +162,7 @@ def main() -> None:
|
||||
description="Run the AgentMsgs MCP server.",
|
||||
epilog=(
|
||||
"Examples:\n"
|
||||
" agentmsgs-mcp --transport stdio\n"
|
||||
" agentmsgs-mcp --transport stdio --db-path ./agentmsgs.db\n"
|
||||
" agentmsgs-mcp --transport stdio --db-path ./shared-agentmsgs.db\n"
|
||||
" agentmsgs-mcp --in-memory --transport stdio"
|
||||
),
|
||||
@@ -180,11 +180,11 @@ def main() -> None:
|
||||
|
||||
parser.add_argument(
|
||||
"--db-path",
|
||||
type=str,
|
||||
default=str(WORKSPACE_ROOT / ".agentmsgs.db"),
|
||||
type=Path,
|
||||
default=None,
|
||||
help=(
|
||||
"SQLite database path. Used unless --in-memory is set. "
|
||||
"Defaults to .agentmsgs.db in the workspace root."
|
||||
"SQLite database path. Required unless --in-memory is set. "
|
||||
"The path is used exactly as supplied."
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -203,6 +203,8 @@ def main() -> None:
|
||||
_app = App(store=InMemoryStore())
|
||||
logger.info("Using in-memory store for MCP server.")
|
||||
else:
|
||||
if args.db_path is None:
|
||||
parser.error("--db-path is required unless --in-memory is set")
|
||||
_app = App(store=SQLiteStore(args.db_path))
|
||||
logger.info("Using SQLite store at %s for MCP server.", args.db_path)
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
|
||||
from agentmsgs.core.types import Agent, Message, Thread, ThreadInfo, ThreadReadState
|
||||
from agentmsgs.utils import WORKSPACE_ROOT
|
||||
|
||||
_SCHEMA = """
|
||||
PRAGMA journal_mode=WAL;
|
||||
@@ -21,7 +20,7 @@ CREATE TABLE IF NOT EXISTS cursors (thread_id TEXT NOT NULL, agent_id TEXT NOT N
|
||||
|
||||
|
||||
class SQLiteStore:
|
||||
def __init__(self, path: Path = WORKSPACE_ROOT / ".agentmsgs.db") -> None:
|
||||
def __init__(self, path: Path) -> None:
|
||||
self.path = Path(path)
|
||||
# ensure parent exists
|
||||
if self.path.parent and not self.path.parent.exists():
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
from pathlib import Path
|
||||
|
||||
WORKSPACE_ROOT = Path(__file__).parent.parent.parent
|
||||
assert WORKSPACE_ROOT / "src" / "agentmsgs" / "utils.py" == Path(__file__), (
|
||||
"this file should be located at src/agentmsgs/utils.py"
|
||||
)
|
||||
@@ -2,9 +2,16 @@ import pathlib
|
||||
import tempfile
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from agentmsgs.stores.sqlite import SQLiteStore
|
||||
|
||||
|
||||
def test_sqlite_store_requires_explicit_path():
|
||||
with pytest.raises(TypeError):
|
||||
SQLiteStore()
|
||||
|
||||
|
||||
def test_sqlite_persists_across_handles():
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
p = pathlib.Path(d) / "test.db"
|
||||
|
||||
Reference in new issue
Block a user