Skip to content

CSDb Deployment Cloudflare Workers CLI Setup

elb-pr edited this page Apr 7, 2026 · 2 revisions

CSDb Deployment: Cloudflare Workers & CLI Setup

The CSDb (Claude Sleuth Database) is a persistent investigation database implemented as an MCP (Model Context Protocol) server. It leverages Cloudflare Workers and Cloudflare D1 (a distributed SQLite database) to provide cross-session persistence for entities, relationships, timelines, and investigation notebooks. This allows a Claude-based investigator to maintain a "source of truth" that survives beyond the context window of a single chat session.

Deployment Options

The CSDb can be deployed using a simplified one-click web interface or via the wrangler CLI for more granular control.

1. One-Click Deployment

For rapid setup, the repository provides a pre-configured deployment button that automates the creation of the Worker and the D1 database instance.

  • Process:
    1. Navigate to the server/ directory in the repository.
    2. Click the Deploy to Cloudflare Workers button.
    3. Authorize the Cloudflare account.
    4. The tables are initialized automatically upon the first tool execution.

2. CLI Setup (setup.sh)

The setup.sh script provides an automated command-line workflow for users who prefer using the wrangler toolchain.

  • Key Functions of setup.sh:
    • Database Creation: Executes wrangler d1 create sleuth-db to initialize the storage layer.
    • ID Extraction: Automatically parses the UUID of the newly created database from the CLI output.
    • Configuration Patching: Uses sed to inject the real database_id into the wrangler.jsonc configuration file.
    • Schema Application: Executes the schema.sql file against the D1 instance to create the 9 required tables.
    • Deployment: Runs wrangler deploy to push the worker.js logic to the Cloudflare Edge.

Configuration & Infrastructure

The deployment is governed by wrangler.jsonc, which defines the environment bindings and the entry point for the MCP server.

Component Identifier Description
Worker Name claude-sleuth-db The name of the service in the Cloudflare dashboard.
Main Entry worker.js The JavaScript file containing the MCP tool logic and D1 interactions.
D1 Binding DB The variable name used within the code to access the database.
Transport MCP over HTTP Uses POST /mcp as the primary endpoint for tool calls.

Deployment Data Flow

The following diagram illustrates how the CLI setup bridges the local configuration to the Cloudflare Cloud environment.

CSDb Provisioning Flow

graph TD
    subgraph "Local Environment"
        A["setup.sh"] --> B["wrangler d1 create"]
        B --> C["wrangler.jsonc (Template)"]
        C -- "sed injection" --> D["wrangler.jsonc (Configured)"]
        D --> E["wrangler d1 execute --file=schema.sql"]
    end

    subgraph "Cloudflare Edge Space"
        E --> F[("D1: sleuth-db")]
        D --> G["wrangler deploy"]
        G --> H["Worker: worker.js"]
        H -- "Binding: DB" --> F
    end

    subgraph "Claude AI Space"
        I["Claude Desktop/Web"] -- "POST /mcp" --> H
    end
Loading

Connecting to Claude

Once deployed, the Worker provides a URL (typically https://claude-sleuth-db.<subdomain>.workers.dev/mcp). This URL must be configured as an MCP connector to allow Claude to access the 26 persistence tools.

MCP Configuration (mcp.json)

The server is designed to be added to the mcpServers configuration block.

{
  "mcpServers": {
    "claude-sleuth-db": {
      "url": "https://claude-sleuth-db.<YOUR_SUBDOMAIN>.workers.dev/mcp"
    }
  }
}

MCP Tool Domains

The CSDb exposes 26 tools categorized by their functional domain within the investigation lifecycle. These tools allow the model to interact with the D1 database via the worker.js logic.

Mapping Tool Domains to D1 Persistence

graph LR
    subgraph "Natural Language Space (Claude)"
        N1["'Add this person to the case'"]
        N2["'What happened on June 12th?'"]
        N3["'Note this in the notebook'"]
    end

    subgraph "Code Entity Space (MCP Server)"
        T1["add_entity"]
        T2["add_timeline_event"]
        T3["save_notebook"]
        
        N1 --> T1
        N2 --> T2
        N3 --> T3
    end

    subgraph "Data Persistence (D1)"
        D1[("Table: entities")]
        D2[("Table: timeline_events")]
        D3[("Table: notebook")]

        T1 --> D1
        T2 --> D2
        T3 --> D3
    end
Loading
Domain Key Tools Purpose
Investigation create_investigation, load_investigation Manages top-level case metadata and session context.
Entities add_entity, search_entities Stores POLE (Person, Object, Location, Event) data.
Relationships add_relationship, get_neighbors Persists links between entities for graph analysis.
Timeline add_timeline_event, get_timeline Normalizes chronological data for matrix construction.
Evidence register_evidence Tracks file hashes and source URLs for chain of custody.

Clone this wiki locally