MCPcopy Index your code
hub / github.com/Nonanti/narwhal

github.com/Nonanti/narwhal @v2.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.3.0 ↗ · + Follow
4,672 symbols 17,168 edges 393 files 1,009 documented · 22%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

narwhal

# narwhal

The agent-native database workbench for the terminal. A DBA toolkit, an MCP server, and a vim-mode SQL editor — in one static binary.

CI Crates.io Downloads MSRV License

Install · Quick start · Why narwhal · Docs


narwhal demo

What is narwhal?

narwhal is a terminal database client built around two things every other client misses:

  1. DBA-grade tooling, not a toy REPL. Schema diff with dialect-aware DDL emit, append-only audit log, capability-gated plugin sandbox, streaming cancellable queries, ER diagrams, SSH tunnels, secret vault — the operational surface a real database day needs.
  2. First-class agent integration. A built-in MCP server exposes your connections, schema, and query execution to Claude, Cursor, Zed, and any MCP-aware client. No proxy, no adapter — narwhal mcp and you're wired.

Six engines (Postgres, MySQL, SQLite, DuckDB, ClickHouse, SQL Server), three editor modes (vim / basic / emacs), one static binary.

Install

curl -fsSL https://github.com/Nonanti/narwhal/releases/latest/download/install.sh | sh

Other channels — cargo install narwhaldb, Homebrew, AUR, Nix flake, prebuilt tarballs — are listed in docs/install.md.

Quick start

narwhal                                    # launches the TUI

Inside:

  1. :add — connection wizard, or :url postgres://user:pass@host/db
  2. :open <name> — connect; the sidebar fills with schemas and tables
  3. F6 — run the buffer; results stream into the lower pane
  4. F1 — full keymap

Headless:

narwhal exec --conn prod 'SELECT count(*) FROM orders' --format json

Agent-native: wire it to your editor

narwhal embeds an MCP server over stdio. Run it once and your AI assistant can browse schema, sample data, and run queries against your saved connections — with the same read-only / per-connection guards the TUI uses.

narwhal mcp --read-only

Claude Desktop (~/.config/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "narwhal": {
      "command": "narwhal",
      "args": ["mcp", "--read-only"]
    }
  }
}

Cursor, Zed, Continue, Aider, and custom clients work the same way. Full setup: docs/mcp.md.

Database support

Engine Driver TLS Streaming Cancel DDL emit
PostgreSQL tokio-postgres + rustls verify-full
MySQL / MariaDB mysql_async
SQLite rusqlite (bundled) n/a
DuckDB duckdb (bundled) n/a
ClickHouse HTTP + rustls
SQL Server tiberius + rustls buffered

Highlights

  • Six engines, one TUI. Switch with :open, every driver speaks the same Connection trait — same streaming, same cancellation, same schema introspection.
  • Three editor modes. vim (with motions, text objects, registers, marks, macros), basic (modeless), emacs — sharing one buffer.
  • Full mouse. Click, drag-select, double / triple-click word and line, middle-click paste, right-click context menu.
  • Schema tooling. ER diagrams in the terminal, :schema-diff between two connections with dialect-aware DDL emit (Postgres ↔ MySQL ↔ MSSQL ↔ generic).
  • Plugins. Lua (trusted, fast) and WASM (sandboxed, capability-gated filesystem / network / clipboard) — the same surface used by the built-ins.
  • Streaming, cancellable. Rows arrive incrementally; Ctrl-C cancels mid-run on every backend that supports it.
  • Secrets. Vault, 1Password, OS keyring, ~/.pgpass — no plaintext-on-disk fallback.
  • Audit log. Append-only JSONL with redaction rules, suitable as compliance evidence.
  • Inline output. Charts, pivot tables, JSON viewer, row detail pane, exports to CSV / JSON / Markdown / Parquet.
  • SSH tunnels. Single config block, no ~/.ssh/config plumbing required.

Documentation

Topic File
Install (all methods) docs/install.md
Configuration docs/configuration.md
Editor modes docs/editor-modes.md
Mouse docs/mouse.md
MCP server docs/mcp.md
Headless exec docs/headless.md
Plugins (Lua + WASM) docs/plugins.md
Connection vault docs/vault.md
Audit log docs/audit.md
Schema diff docs/schema-diff.md
Architecture docs/ARCHITECTURE.md
Building from source docs/dev/build.md
Upgrading docs/upgrading.md

Contributing

Issues and PRs welcome. See CONTRIBUTING.md. Commit messages follow Conventional Commits; the four CI checks (fmt, clippy -D warnings, doc -D warnings, test) must pass.

License

Dual-licensed under MIT and Apache 2.0, at your option.

Extension points exported contracts — how you extend this code

DatabaseDriver (Interface)
Factory for [`crate::Connection`] instances of a particular database engine. Drivers are registered at application star [6 …
crates/narwhal-core/src/driver.rs
DdlEmitter (Interface)
One dialect's projection of a [`SchemaDiff`] into runnable DDL. Implementations return one big `String` (the whole migr [5 …
crates/narwhal-schema-diff/src/emit/mod.rs
AuditSink (Interface)
One audit sink. Writes are append-only and must not block beyond the inherent cost of the underlying I/O. The trait is [5 …
crates/narwhal-audit/src/sinks/mod.rs
Plugin (Interface)
(no doc) [9 implementers]
crates/narwhal-plugin/src/lib.rs
CredentialStore (Interface)
Storage abstraction for connection secrets. Concrete implementations include [`KeyringStore`], which delegates to the o [4 …
crates/narwhal-config/src/credentials.rs
Tool (Interface)
(no doc) [7 implementers]
crates/narwhal-mcp/src/tools/mod.rs
AuditSink (Interface)
Subscriber for denial audit events. Implemented by: [`TracingAuditSink`] — production. Forwards to `tracing::warn!`. [` [3 …
crates/narwhal-plugin-wasm/src/sandbox/audit.rs
Transport (Interface)
A bidirectional byte transport between the client and the server. Implemented for the stdio of a child process and for t [2 …
crates/narwhal-lsp/src/transport.rs

Core symbols most depended-on inside this repo

push
called by 551
crates/narwhal-commands/src/pending.rs
iter
called by 445
crates/narwhal-commands/src/pending.rs
handle_key
called by 400
crates/narwhal-app/src/core/dispatch/mod.rs
join
called by 385
crates/narwhal-lsp/src/client.rs
execute_command
called by 337
crates/narwhal-app/src/core/dispatch/mod.rs
path
called by 331
crates/narwhal-history/src/journal.rs
len
called by 249
crates/narwhal-core/src/schema.rs
execute
called by 214
crates/narwhal-drivers/src/mssql/mod.rs

Shape

Function 2,714
Method 1,419
Class 358
Enum 157
Interface 24

Languages

Rust100%
Ruby1%

Modules by API surface

crates/narwhal-domain/src/editor/mod.rs132 symbols
crates/narwhal-drivers/src/mssql/mod.rs78 symbols
crates/narwhal-drivers/src/clickhouse/mod.rs61 symbols
crates/narwhal-domain/src/result/actions.rs59 symbols
crates/narwhal-drivers/src/mysql/mod.rs57 symbols
crates/narwhal-drivers/src/duckdb/mod.rs56 symbols
crates/narwhal-commands/src/commands.rs56 symbols
crates/narwhal-commands/src/export/mod.rs55 symbols
crates/narwhal-plugin-lua/src/lib.rs52 symbols
crates/narwhal-history/src/journal.rs51 symbols
crates/narwhal-sql/src/lint.rs47 symbols
crates/narwhal-drivers/src/sqlite/mod.rs47 symbols

Datastores touched

(mysql)Database · 1 repos
dbDatabase · 1 repos
ordersDatabase · 1 repos
inventoryDatabase · 1 repos
invDatabase · 1 repos
postgresDatabase · 1 repos

For agents

$ claude mcp add narwhal \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page