AI & ToolsJun 3, 20268 min read

How to Use Claude as Your Database Architect with MCP Server

The Model Context Protocol lets Claude read your live schema, create tables, define relationships, and generate migrations β€” all from a natural language conversation. Here's how to set it up and get the most out of it.

Database design has always required a rare combination of skills: understanding the business domain, knowing relational theory, and hands-on experience with the quirks of different database engines. For most teams, this expertise lives in one or two people. What if you could give every developer on your team access to that level of knowledge, on demand, through a conversation?

That is the promise of connecting Claude to ER Flow via the Model Context Protocol. Claude becomes your database architect β€” one that never sleeps, remembers every design pattern, and can apply changes to your live schema in seconds.

What is the Model Context Protocol?

The Model Context Protocol (MCP) is an open standard introduced by Anthropic that defines how AI models communicate with external tools and data sources. Think of it as a USB standard for AI: instead of each tool having its own proprietary integration, any MCP-compatible tool can connect to any MCP-compatible AI client.

MCP Servers expose a set of "tools" β€” functions that the AI can call. When you ask Claude "add an audit log to the orders table," Claude does not just generate SQL text. It calls an actual tool that modifies your ER Flow schema. The change appears on your visual canvas immediately, with full undo support.

How ER Flow's MCP Server Works

ER Flow exposes a purpose-built MCP Server with tools that map directly to database design operations. The key tools include get-data-model-dbml (read the current schema as DBML), create-table (create a new table with columns, indexes, and foreign keys), update-table (modify an existing table), delete-table, create-column, update-column, delete-column, create-index, and batch-operations (apply multiple changes atomically in a single request).

Before making any change, Claude calls get-data-model-dbml to read your current schema. This is critical β€” it means Claude always works from an accurate picture of your existing tables and relationships, not from a hallucinated version. It sees your actual column names, types, constraints, and foreign keys. This context-awareness is what separates MCP-powered design from naive prompt-to-SQL generation.

Setting Up Claude Code with ER Flow

The setup takes under five minutes. Open your ER Flow project and navigate to Settings β†’ MCP Server. You will see your project's unique MCP Server URL and an API key. Copy both. If you are using Claude Code (the official Anthropic CLI), add the server to your project's .claude/mcp.json file with the type: "sse" transport, the project URL, and an Authorization: Bearer header containing your API key. Restart Claude Code and you will see the ER Flow tools listed in the available tools panel.

Cursor and Windsurf Setup

If you use Cursor, add the same configuration to .cursor/mcp.json in your project root. Windsurf reads from .windsurf/mcp.json. The structure is identical β€” only the file path changes. All three clients support the SSE transport that ER Flow uses, so the experience is consistent regardless of which AI editor you prefer.

Example: "Create a Notifications System"

Here is what a real conversation looks like. You type: *"Add a notifications system. Users should be able to receive notifications when someone comments on their post or follows them. Store whether each notification has been read."*

Claude calls get-data-model-dbml first, reads your existing users, posts, and comments tables, then calls batch-operations with a single request that creates the notifications table. The new table includes columns for id, user_id, type (a varchar constrained to values like comment and follow), actor_id (the user who triggered the notification), notifiable_type and notifiable_id (a polymorphic reference), read_at, and timestamps. Claude also creates a composite index on (user_id, read_at) for efficient unread-notification queries. All of this appears on your ER Flow canvas in one operation.

Example: "Add Audit Logging"

Audit logging is a pattern Claude applies fluently. Prompt: *"Add audit logging to the orders and products tables. I need to know who changed what and when."* Claude reads the schema, then creates an audit_logs table with id, user_id, auditable_type, auditable_id, event (created, updated, deleted), old_values (JSON), new_values (JSON), ip_address, and created_at. It adds a polymorphic index on (auditable_type, auditable_id) for fast lookups per record. If your project uses Laravel, it also notes the relevant package that provides an Auditable trait β€” because Claude understands the full stack, not just the schema.

Batch Operations for Speed

The batch-operations tool is especially powerful when making interconnected changes. Rather than creating a table, then adding foreign keys, then creating indexes as separate round-trips, Claude bundles everything into one atomic operation. This means your schema is never in an intermediate state where foreign keys reference tables that do not exist yet. For complex features that touch many tables, a single Claude response can apply dozens of changes without any intermediate errors.

Best Practices for AI-Assisted Schema Design

Always review before migrating. Claude is excellent at applying patterns, but it does not know your application's query patterns, expected data volumes, or performance requirements. After Claude makes changes, review the ER Flow canvas before generating migrations. Look for missing indexes on columns you will filter or join on heavily. Check that foreign key cascade rules match your deletion semantics.

Be specific about constraints. Vague prompts produce vague schemas. Instead of "add a price field," say "add a price column in integer cents, not null, unsigned, with a default of 0." The more precise your requirements, the more accurate the result. Use `get-data-model-dbml` explicitly. If you have made manual changes in ER Flow and want Claude to be aware of them, explicitly tell it to read the current schema first. This ensures Claude always works from the latest state rather than a stale picture of what the schema looked like earlier in the conversation.

The combination of Claude's pattern knowledge and ER Flow's visual feedback loop creates a database design workflow that is simultaneously faster and more accurate than either approach alone. Your AI handles the boilerplate; you focus on the design decisions that actually require business judgment.