> ## Documentation Index
> Fetch the complete documentation index at: https://moridb.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Get Mori running in under 5 minutes.

## Manual Setup

### Prerequisites

* **Docker** (for shadow containers -- required for all engines except SQLite and DuckDB)

### Install

<CodeGroup>
  ```bash curl (recommended) theme={null}
  curl -fsSL https://moridb.sh/install.sh | sh
  ```

  ```bash go install theme={null}
  go install github.com/psrth/mori/cmd/mori@latest
  ```

  ```bash build from source theme={null}
  git clone https://github.com/psrth/mori.git
  cd mori
  go build -o mori ./cmd/mori
  ```
</CodeGroup>

### Steps

<Steps>
  <Step title="Initialize a connection">
    Point Mori at your production database. The interactive setup walks you through engine, provider, and credentials.

    ```bash theme={null}
    mori init
    ```

    For a non-interactive setup, you can pass a connection string directly:

    <CodeGroup>
      ```bash PostgreSQL theme={null}
      mori init --from "postgres://user:pass@host:5432/mydb?sslmode=require"
      ```

      ```bash MySQL theme={null}
      mori init --from "mysql://user:pass@host:3306/mydb"
      ```

      ```bash Redis theme={null}
      mori init --from "redis://:password@host:6379/0"
      ```

      ```bash SQLite theme={null}
      mori init --from "/path/to/database.db"
      ```

      ```bash DuckDB theme={null}
      mori init --from "/path/to/analytics.duckdb"
      ```

      ```bash Firestore theme={null}
      mori init --from "firestore://my-project?credentials=./sa.json"
      ```

      ```bash MSSQL theme={null}
      mori init --from "sqlserver://sa:password@host:1433?database=mydb"
      ```

      ```bash CockroachDB theme={null}
      mori init --from "postgres://user:pass@host:26257/mydb?sslmode=require"
      ```
    </CodeGroup>

    This saves the connection config to `mori.yaml`. No containers or connections are created yet.
  </Step>

  <Step title="Start the proxy">
    ```bash theme={null}
    mori start
    ```

    On first run, Mori:

    1. Connects to your production database
    2. Discovers schema and structure (SQL engines dump tables/types/sequences; Firestore discovers collections; Redis scans key prefixes)
    3. Spins up a shadow database (Docker container, local file copy, or emulator)
    4. Replicates structure to shadow (SQL engines replay schema; Firestore seeds documents; Redis starts empty)
    5. Detects and replicates extensions to shadow (PostgreSQL — auto-installs via `apt-get` if needed; use `--image` on `mori init` for custom images)
    6. Offsets auto-increment sequences to prevent PK collisions (SQL engines only)
    7. Starts the proxy and listens on a local port

    Use `--port` to pick a specific port, or let Mori auto-assign. Subsequent starts are faster since the shadow already exists.

    If complex queries over large tables are slow, you can limit how many rows Mori hydrates from prod per query:

    ```bash theme={null}
    mori start --max-rows 10000
    ```
  </Step>

  <Step title="Point your app at Mori">
    Swap your application's connection string to point at `127.0.0.1` on the proxy port. Same driver, same protocol -- your app won't know the difference.

    <CodeGroup>
      ```bash PostgreSQL / MySQL / MSSQL theme={null}
      # Before (direct to prod)
      DATABASE_URL=postgres://user:pass@prod-host:5432/mydb

      # After (through Mori)
      DATABASE_URL=postgres://user:pass@127.0.0.1:5432/mydb
      ```

      ```bash Redis theme={null}
      # Before
      REDIS_URL=redis://:password@prod-host:6379/0

      # After
      REDIS_URL=redis://:password@127.0.0.1:6379/0
      ```

      ```bash Firestore theme={null}
      # Set the emulator host to point at Mori's proxy port
      FIRESTORE_EMULATOR_HOST=127.0.0.1:<proxy-port>
      ```
    </CodeGroup>
  </Step>

  <Step title="Stop Mori">
    Closes the connection to prod and spins down the shadow container. State is persisted for future runs.

    ```bash theme={null}
    mori stop
    ```
  </Step>

  <Step title="Soft reset between runs">
    Wipe all local state to quickly start fresh on the next run.

    ```bash theme={null}
    mori reset
    ```
  </Step>

  <Step title="Hard reset when schema changes">
    Wipes all local state and deletes the shadow container. Use this when the production schema has changed since the last init. This takes longer than a soft reset.

    ```bash theme={null}
    mori reinit
    ```
  </Step>
</Steps>

## Enabling the MCP Server

Start Mori with the MCP server for AI agent integration:

```bash theme={null}
mori start --mcp --mcp-port 9000
```

AI agents connect to `http://127.0.0.1:9000/mcp` and get engine-specific tools (SQL queries, Redis commands, or Firestore operations) -- all safely routed through the proxy.

## Lifecycle

```
mori init         Connect to prod, discover structure, spin up shadow
     |
mori start        Start proxy, load state, accept connections
     |
  [app runs]      CRUD operations routed transparently
     |
mori stop         Persist state, shut down proxy
     |
mori reset        Wipe shadow data + metadata, clean slate
```

## For AI Agents

If you're setting up Mori with an AI coding agent, download the [`skill.md`](https://moridb.sh/skill.md) file and add it to your project root. Point your agent at it -- it contains everything needed to install, initialize, and start Mori.

```bash theme={null}
curl -fsSL https://moridb.sh/skill.md -o skill.md
```

Your agent can read `skill.md` and handle the rest autonomously.
