mcp_memory/lib.rs
1pub mod actions;
2pub mod config;
3pub mod errors;
4pub mod http;
5pub mod kg;
6pub mod protocol;
7pub mod server;
8pub mod tools;
9pub mod types;
10
11use clap::{Parser, ValueEnum};
12
13/// Wire transport the server listens on. The JSON-RPC/MCP semantics are
14/// identical across all three — only the framing differs.
15#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
16#[clap(rename_all = "lowercase")]
17pub enum Transport {
18 /// Newline-delimited JSON-RPC over stdin/stdout (default; for Claude
19 /// Desktop / Claude Code and other process-spawning clients).
20 Stdio,
21 /// Newline-delimited JSON-RPC over a TCP socket (one message per line),
22 /// accepting many concurrent connections.
23 Tcp,
24 /// MCP Streamable HTTP: POST JSON-RPC to `/mcp` (responses as JSON or, when
25 /// the client `Accept`s it, an SSE stream), plus `GET /mcp` for a standalone
26 /// server→client SSE stream.
27 Http,
28}
29
30#[derive(Parser, Debug)]
31#[command(name = "MCP Memory Server")]
32#[command(about = "Knowledge graph memory server for MCP — entities, relations, and observations persisted in SQLite with FTS5 search", long_about = None)]
33pub struct Args {
34 /// Path to the memory file
35 #[arg(short = 'f', long = "memory-file")]
36 pub memory_file: Option<String>,
37
38 /// Transport to listen on: stdio, tcp, or http
39 #[arg(short = 't', long = "transport", value_enum, default_value_t = Transport::Stdio)]
40 pub transport: Transport,
41
42 /// Address to bind for the `tcp` and `http` transports
43 #[arg(short = 'b', long = "bind", default_value = "127.0.0.1:8080")]
44 pub bind: String,
45
46 /// Log level
47 #[arg(short, long, default_value = "info")]
48 pub log_level: String,
49
50 /// Bearer token required on the `tcp` (first line) and `http`
51 /// (`Authorization` header) transports. Overrides `--auth-token-file` and
52 /// the `MCP_MEMORY_AUTH_TOKEN` env var. stdio is never authenticated.
53 #[arg(long = "auth-token")]
54 pub auth_token: Option<String>,
55
56 /// Path to a file whose trimmed contents are the bearer token. An empty
57 /// file is rejected (fail closed). Ignored if `--auth-token` is set.
58 #[arg(long = "auth-token-file")]
59 pub auth_token_file: Option<String>,
60
61 /// SQLite mmap size in bytes (default: 256 MiB).
62 #[arg(long = "mmap-size", default_value_t = 268435456)]
63 pub mmap_size: i64,
64
65 /// Entity-metadata LRU cache capacity (0 = unbounded).
66 #[arg(long = "lru-cache-size", default_value_t = 10000)]
67 pub lru_cache_size: usize,
68
69 /// Number of read-only SQLite connections backing concurrent reads. WAL
70 /// mode allows readers to run in parallel with each other and the single
71 /// writer; a larger pool raises read concurrency at the cost of a little
72 /// memory. Clamped to at least 1.
73 #[arg(long = "read-pool-size", default_value_t = 4)]
74 pub read_pool_size: usize,
75}