Skip to content

Claude Code Integration

d1-eloquent ships with first-class Claude Code support through two complementary tools: a skill that teaches Claude how to write correct d1-eloquent code, and an MCP server that gives Claude live access to your D1 database.

Skill

The d1-eloquent skill is a set of reference documents that Claude Code loads automatically when it detects you're working with d1-eloquent. It covers model definitions, migrations, query building, relationships, hooks, casting, seeders, factories, and every CLI command.

When the skill is active, Claude will:

  • Generate models with correct BaseModel<TAttrs> patterns, TEXT primary keys, and proper casts
  • Write migrations using the schema builder (not raw SQL)
  • Use declarative static relations instead of legacy helpers
  • Apply configure(env) auto-wiring or explicit db arguments consistently
  • Follow all d1-eloquent conventions (soft deletes, revision tracking, mass assignment, etc.)

Install the Skill

bash
# Clone into your Claude Code skills directory
git clone https://github.com/Orphnet/d1-eloquent-skill.git ~/.claude/skills/d1-eloquent-skill

That's it. Claude Code discovers skills from ~/.claude/skills/ automatically. The skill activates whenever you mention d1-eloquent, Cloudflare D1, or ask Claude to scaffold a Workers + D1 project.

No configuration needed

The skill has no dependencies or build step. It's a set of markdown reference files that Claude reads on demand.

MCP Server

The MCP server gives Claude (and any MCP-compatible client) live read/write access to your D1 database. Claude can query records, inspect schema, create and update data, browse revision history, and time-travel — all through natural language.

The server understands your d1-eloquent models: it respects soft deletes, writes audit revisions, applies the correct primary keys, and auto-generates UUIDs.

Install in Claude Code

bash
claude mcp add d1-eloquent -- npx @orphnet/d1-eloquent-mcp

Install in Claude Desktop

Add to your claude_desktop_config.json:

json
{
  "mcpServers": {
    "d1-eloquent": {
      "command": "npx",
      "args": ["@orphnet/d1-eloquent-mcp"],
      "env": {
        "D1_BINDING": "DB",
        "MODELS_PATH": "./src/models"
      }
    }
  }
}

Configuration

VariableDefaultDescription
WRANGLER_CONFIG./wrangler.jsoncPath to wrangler config
D1_BINDINGDBD1 binding name
D1_LOCALtrueUse local D1 (false for remote)
MODELS_PATH./src/modelsWhere model classes live
D1_REMOTE_ACCOUNT_ID--Cloudflare account ID (remote mode)
D1_REMOTE_DATABASE_ID--D1 database ID (remote mode)
CLOUDFLARE_API_TOKEN--API token (remote mode)
MAX_ROW_LIMIT1000Maximum rows returned per query

Available Tools

Schema & Inspection

  • d1_list_tables -- list all tables with column info
  • d1_describe_table -- full schema, indexes, foreign keys, row count
  • d1_migration_status -- applied vs pending migrations

Querying

  • d1_query -- read-only SQL with parameter binding
  • d1_find -- ORM-style filters (no SQL needed)
  • d1_find_by_id -- find by primary key
  • d1_count -- count with optional filters

Mutations

  • d1_create -- insert with auto-UUID and timestamp generation
  • d1_update -- update by primary key (dirty tracking)
  • d1_delete -- delete or soft-delete
  • d1_restore -- restore soft-deleted records

Revisions & Time-Travel

  • d1_revisions -- revision history for a record
  • d1_as_of -- reconstruct state at a past timestamp
  • d1_revert -- roll back to a specific revision

Utilities

  • d1_bulk_create -- insert up to 100 records at once
  • d1_raw_query -- arbitrary SQL (writes require confirmation)

Safety

  • d1_query only allows SELECT / WITH / EXPLAIN / PRAGMA
  • d1_raw_query requires explicit confirm_write: true for mutations
  • All queries enforce a configurable row limit (default 1000)
  • Table and column names are validated against injection patterns
  • All queries use parameterized binding

Resources

Released under the MIT License.