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