narwhal_mcp/lib.rs
1//! Model Context Protocol (MCP) server for narwhal.
2//!
3//! Exposes narwhal's configured database connections to AI agents (Claude
4//! Desktop, Cursor, Continue, Aider, …) over the JSON-RPC 2.0 stdio
5//! transport defined by the MCP spec.
6//!
7//! # Quick start
8//!
9//! ```no_run
10//! use std::sync::Arc;
11//! use narwhal_config::{ConfigPaths, ConnectionsFile, KeyringStore, DynCredentialStore};
12//! use narwhal_mcp::{DriverRegistry, McpServer, ServerContext};
13//!
14//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
15//! let paths = ConfigPaths::discover()?;
16//! let connections = ConnectionsFile::load(&paths.connections_file())?;
17//! let drivers = Arc::new(DriverRegistry::with_defaults());
18//! let credentials: Arc<dyn DynCredentialStore> = Arc::new(KeyringStore::new());
19//! let ctx = ServerContext::new(drivers, Arc::new(connections), credentials);
20//! McpServer::new(ctx).serve_stdio().await?;
21//! # Ok(())
22//! # }
23//! ```
24//!
25//! # Wire-up for Claude Desktop
26//!
27//! ```jsonc
28//! // ~/.config/Claude/claude_desktop_config.json
29//! {
30//! "mcpServers": {
31//! "narwhal": {
32//! "command": "narwhal",
33//! "args": ["mcp"]
34//! }
35//! }
36//! }
37//! ```
38//!
39//! # Tool surface (v0)
40//!
41//! - [`tools::ListConnectionsTool`] — metadata only, no IO.
42//! - [`tools::DescribeSchemaTool`] — opens a short-lived connection.
43//!
44//! `run_query` / `explain_query` land in v0.2 once we've validated the
45//! read-only enforcement story.
46
47#![forbid(unsafe_code)]
48
49pub mod context;
50pub mod error;
51pub mod json_value;
52pub mod protocol;
53pub mod registry;
54pub mod server;
55pub mod tools;
56pub mod workspace;
57
58pub use context::ServerContext;
59pub use error::McpError;
60pub use registry::DriverRegistry;
61pub use server::McpServer;
62pub use workspace::{Workspace, WorkspaceError, WorkspaceFile};