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 relationsinstead of legacy helpers - Apply
configure(env)auto-wiring or explicitdbarguments consistently - Follow all d1-eloquent conventions (soft deletes, revision tracking, mass assignment, etc.)
Install the Skill
# Clone into your Claude Code skills directory
git clone https://github.com/Orphnet/d1-eloquent-skill.git ~/.claude/skills/d1-eloquent-skillThat'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
claude mcp add d1-eloquent -- npx @orphnet/d1-eloquent-mcpInstall in Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"d1-eloquent": {
"command": "npx",
"args": ["@orphnet/d1-eloquent-mcp"],
"env": {
"D1_BINDING": "DB",
"MODELS_PATH": "./src/models"
}
}
}
}Configuration
| Variable | Default | Description |
|---|---|---|
WRANGLER_CONFIG | ./wrangler.jsonc | Path to wrangler config |
D1_BINDING | DB | D1 binding name |
D1_LOCAL | true | Use local D1 (false for remote) |
MODELS_PATH | ./src/models | Where 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_LIMIT | 1000 | Maximum rows returned per query |
Available Tools
Schema & Inspection
d1_list_tables-- list all tables with column infod1_describe_table-- full schema, indexes, foreign keys, row countd1_migration_status-- applied vs pending migrations
Querying
d1_query-- read-only SQL with parameter bindingd1_find-- ORM-style filters (no SQL needed)d1_find_by_id-- find by primary keyd1_count-- count with optional filters
Mutations
d1_create-- insert with auto-UUID and timestamp generationd1_update-- update by primary key (dirty tracking)d1_delete-- delete or soft-deleted1_restore-- restore soft-deleted records
Revisions & Time-Travel
d1_revisions-- revision history for a recordd1_as_of-- reconstruct state at a past timestampd1_revert-- roll back to a specific revision
Utilities
d1_bulk_create-- insert up to 100 records at onced1_raw_query-- arbitrary SQL (writes require confirmation)
Safety
d1_queryonly allowsSELECT/WITH/EXPLAIN/PRAGMAd1_raw_queryrequires explicitconfirm_write: truefor 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
- d1-eloquent-skill on GitHub -- skill source and reference docs
- Claude Code documentation -- skills, MCP servers, and configuration