1pub mod common;
2pub mod embeddings;
3pub mod engine;
4pub mod handlers;
5pub mod http;
6pub mod mcp_core;
7pub mod mcp_protocol;
8mod mcp_runtime;
9pub mod path_utils;
10pub mod preprocessing;
11pub mod query;
12pub mod rag;
13pub mod search;
14pub mod security;
15pub mod storage;
16#[cfg(test)]
17mod tests;
18pub mod tools;
19
20#[cfg(feature = "cli")]
22pub mod progress;
23#[cfg(feature = "cli")]
24pub mod tui;
25
26use anyhow::Result;
27use tracing::Level;
28
29pub use embeddings::{
31 DEFAULT_REQUIRED_DIMENSION, DimensionAdapter, EmbeddingClient, EmbeddingConfig, MLXBridge,
32 MlxConfig, MlxMergeOptions, ProviderConfig, RerankerConfig, TokenConfig,
33 cross_dimension_search_adapt, estimate_tokens, infer_embedding_dimension, safe_chunk_size,
34 truncate_to_token_limit, validate_batch_tokens, validate_chunk_tokens,
35};
36pub use handlers::{MCPServer, create_server};
37pub use mcp_core::{
38 McpCore, McpDispatch, McpTransport, shared_initialize_result, shared_tools_list_result,
39};
40pub use mcp_core::{dispatch_mcp_jsonrpc_request, dispatch_mcp_payload, dispatch_mcp_request};
41pub use mcp_runtime::build_mcp_core;
42pub use preprocessing::{
43 IntegrityRecommendation, Message, PreprocessingConfig, PreprocessingStats, Preprocessor,
44 TextIntegrityMetrics,
45};
46pub use query::{
47 LoctreeSuggestion, QueryIntent, QueryRouter, RecommendedSearchMode, RoutingDecision,
48 SearchModeRecommendation, TemporalHints, detect_intent,
49};
50pub use rag::{
51 Chunk as PipelineChunk,
52 ContextPrefixConfig,
53 EmbeddedChunk,
54 EnrichedChunk,
55 FileContent,
56 IndexResult,
57 OnionSlice,
58 OnionSliceConfig,
59 PipelineConfig,
60 PipelineResult,
61 PipelineStats,
62 RAGPipeline,
63 SearchOptions,
64 SearchResult,
65 SliceLayer,
66 SliceMode,
67 compute_content_hash,
68 create_enriched_chunks,
69 create_onion_slices,
70 run_pipeline,
72};
73pub use search::{
74 BM25Config, BM25Index, HybridConfig, HybridSearchResult, HybridSearcher, SearchMode,
75 StemLanguage,
76};
77pub use security::{NamespaceAccessManager, NamespaceSecurityConfig};
78pub use storage::{
79 ChromaDocument, GcConfig, GcStats, StorageManager, TableStats, parse_duration_string,
80};
81
82pub use engine::{BatchResult, MemexConfig, MemexEngine, MetaFilter, StoreItem};
84
85pub use tools::{
87 ToolDefinition, ToolResult, delete_document, delete_documents_by_filter, get_document,
88 search_documents, store_document, store_documents_batch, tool_definitions,
89};
90
91#[cfg(feature = "cli")]
93pub use progress::IndexProgressTracker;
94#[cfg(feature = "cli")]
95pub use tui::{
96 CheckStatus, HealthCheckItem, HealthCheckResult, HealthChecker, HostDetection, HostKind,
97 WizardConfig, detect_hosts, run_wizard,
98};
99
100#[derive(Debug, Clone)]
101pub struct ServerConfig {
102 pub cache_mb: usize,
104
105 pub db_path: String,
107
108 pub max_request_bytes: usize,
110
111 pub log_level: Level,
113
114 pub allowed_paths: Vec<String>,
118
119 pub security: NamespaceSecurityConfig,
121
122 pub embeddings: EmbeddingConfig,
124
125 pub hybrid: HybridConfig,
127}
128
129impl Default for ServerConfig {
130 fn default() -> Self {
131 Self {
132 cache_mb: 4096,
133 db_path: "~/.rmcp-servers/rmcp-memex/lancedb".to_string(),
134 max_request_bytes: 5 * 1024 * 1024,
135 log_level: Level::INFO,
136 allowed_paths: vec![],
137 security: NamespaceSecurityConfig::default(),
138 embeddings: EmbeddingConfig::default(),
139 hybrid: HybridConfig::default(),
140 }
141 }
142}
143
144impl ServerConfig {
145 #[doc(alias = "with_db_path")]
146 pub fn with_storage_path(mut self, db_path: impl Into<String>) -> Self {
147 self.db_path = db_path.into();
148 self
149 }
150
151 #[deprecated(note = "use with_storage_path")]
152 pub fn with_db_path(self, db_path: impl Into<String>) -> Self {
153 self.with_storage_path(db_path)
154 }
155}
156
157pub async fn run_stdio_server(config: ServerConfig) -> Result<()> {
159 let server = create_server(config).await?;
160 server.run_stdio().await
161}
162
163#[cfg(test)]
164mod lib_tests {
165 use super::*;
166
167 #[test]
168 fn default_config_has_expected_values() {
169 let cfg = ServerConfig::default();
170 assert_eq!(cfg.cache_mb, 4096);
171 assert_eq!(cfg.db_path, "~/.rmcp-servers/rmcp-memex/lancedb");
172 assert_eq!(cfg.max_request_bytes, 5 * 1024 * 1024);
173 }
174}