Skip to main content

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