Skip to main content

mcpr_integrations/
lib.rs

1//! # mcpr-integrations
2//!
3//! External integrations and local persistence for the mcpr proxy.
4//!
5//! This crate connects mcpr to external services (cloud dashboard) and
6//! provides local request storage (SQLite) for CLI observability commands.
7//!
8//! ## Modules
9//!
10//! - [`cloud_client`]: HTTP client for the mcpr Cloud API. Handles
11//!   authentication, project/server/endpoint CRUD, and token management.
12//!   Used by the CLI setup flow (`mcpr proxy setup`).
13//!
14//! - [`sinks`]: `EventSink` implementations registered on the event bus.
15//!   - `StderrSink` — prints `ProxyEvent::Request` events to stderr
16//!     (json or pretty `LogFormat`).
17//!   - `SqliteSink` — adapts `ProxyEvent` → `StoreEvent` and forwards to
18//!     the SQLite `Store` for local persistence.
19//!   - `CloudSink` — batches proxy events and POSTs them to cloud.mcpr.app
20//!     with retry and exponential backoff.
21//!   - `CloudSinkConfig` — endpoint URL, token, server slug, batch/flush tuning.
22//!
23//! - [`store`]: SQLite persistence and query layer. Pure storage logic —
24//!   the `EventSink` adapter lives in [`sinks::sqlite_sink`].
25//!   - `Store` — background writer with async mpsc channel
26//!   - `QueryEngine` — read-only queries (logs, slow, stats, sessions, clients,
27//!     schema, session detail)
28//!   - `FileStoreConfig` — `[store]` TOML config with `ModuleConfig` validation
29//!
30//! ## Module Structure
31//!
32//! ```text
33//! mcpr-integrations/src/
34//! +-- lib.rs              # Crate root, re-exports
35//! +-- cloud_client.rs     # Cloud API client (auth, CRUD, tokens)
36//! +-- sinks/
37//! |   +-- mod.rs          # Module root, re-exports
38//! |   +-- stderr_sink.rs  # StderrSink (LogFormat: json|pretty)
39//! |   +-- sqlite_sink.rs  # SqliteSink (ProxyEvent → StoreEvent adapter)
40//! |   +-- cloud_sink.rs   # CloudSink (batched HTTP POST with retry)
41//! +-- store/              # Pure SQLite logic (no EventSink impl here)
42//!     +-- mod.rs          # Module root, re-exports
43//!     +-- config.rs       # FileStoreConfig, ModuleConfig impl
44//!     +-- db.rs           # SQLite connection, WAL setup, migrations
45//!     +-- duration.rs     # Human-friendly duration parsing (1h, 7d)
46//!     +-- engine.rs       # Store struct (open, record, shutdown)
47//!     +-- event.rs        # StoreEvent, RequestEvent, SessionEvent
48//!     +-- path.rs         # DB path resolution (config > env > platform)
49//!     +-- schema.rs       # SQL DDL, indexes, prepared statements
50//!     +-- writer.rs       # Background writer thread, batch flush
51//!     +-- query/          # Read-only query engine
52//!         +-- mod.rs      # QueryEngine struct
53//!         +-- logs.rs     # Request log queries
54//!         +-- slow.rs     # Slow call queries
55//!         +-- stats.rs    # Per-tool aggregation with p95
56//!         +-- sessions.rs # Session list with active filter
57//!         +-- session_detail.rs # Single-session drill-down
58//!         +-- clients.rs  # Client aggregation
59//!         +-- schema.rs   # MCP schema queries
60//!         +-- store_ops.rs# Store stats and vacuum
61//! ```
62
63pub mod cloud_client;
64pub mod sinks;
65pub mod store;
66
67pub use sinks::{
68    CloudSink, CloudSinkConfig, LogFormat, SqliteSink, StderrSink, SyncCallback, SyncStatus,
69};