How to Connect Your AI Coding Assistant to Your Database Schema with MCP Server
Your AI assistant can write code but has no idea what your database looks like. MCP Server changes that β learn how to connect Cursor, Windsurf, or any AI IDE to your database schema for context-aware development.
If you use Cursor, Windsurf, or another AI-powered IDE, you've probably noticed something: your AI assistant can write application code, suggest API endpoints, and refactor functions β but it has no idea what your database looks like. It generates queries against tables that don't exist, suggests column names that don't match your schema, and creates migrations that conflict with your current structure.
The problem isn't the AI. It's that the AI doesn't have access to your database schema. MCP Server changes that.
What is MCP (Model Context Protocol)?
MCP is an open protocol that lets AI assistants connect to external tools and data sources. Think of it as a standard way for AI models to "see" and "interact with" things outside their default context. Instead of copying and pasting your schema into a prompt, MCP gives the AI direct, structured access to your data model.
When an AI assistant connects to an MCP server, it gains access to a set of tools β functions it can call to read data, create things, or modify structures. The AI decides when and how to use these tools based on your natural language instructions.
How ER Flow's MCP Server Works
ER Flow provides an MCP Server with 25+ tools that give your AI assistant full read and write access to your database schema. Here's what that means in practice.
When you connect Cursor or Windsurf to ER Flow's MCP Server, your AI assistant can read your entire schema (tables, columns, relationships, indexes), create new tables and add columns, establish foreign key relationships, modify existing structures, generate SQL migrations for your changes, and understand the context of your entire data model before suggesting code.
The key insight is that changes made by the AI appear on your ER Flow canvas in real-time. You're not working blind β you can see exactly what the AI is doing to your schema as it does it.
Setting Up the Connection
Step 1: Get your MCP Server URL
In your ER Flow workspace, navigate to the MCP Server settings. You'll find a connection URL that looks something like https://mcp.erflow.io/workspace/[your-workspace-id]. Copy this URL.
Step 2: Configure your AI IDE
For Cursor: Open your Cursor settings, navigate to the MCP section, and add a new MCP server connection. Paste your ER Flow MCP URL and save. Cursor will automatically discover the available tools.
For Windsurf: The process is similar β open Windsurf's MCP configuration, add ER Flow as a new server, and paste the connection URL.
Step 3: Start designing with AI
Once connected, your AI assistant can access your schema in any conversation. Try prompts like:
- "Look at my current database schema and suggest improvements"
- "Add a comments system with threading support to my blog schema"
- "Create a many-to-many relationship between users and roles with a permissions system"
- "I need to add soft deletes to all my tables β update the schema"
- "Generate the PostgreSQL migrations for the changes we just made"
Real-World Workflow Example
Let's walk through a realistic scenario. You're building a SaaS project management app, and you already have basic tables for Users, Projects, and Tasks in ER Flow.
You open Cursor and type: "I need to add a time tracking feature. Users should be able to log time entries against tasks, with support for billable vs non-billable hours, and I need to generate reports by project and by user."
Because Cursor is connected to your ER Flow MCP Server, it can see your existing tables and their relationships. It understands that Tasks belong to Projects, and Projects belong to Users. With that context, it creates a time_entries table with the right foreign keys pointing to your existing tasks and users tables, adds columns for hours, billable (boolean), description, date, and timestamps, creates the appropriate indexes for reporting queries, and generates the migration files.
All of this appears on your ER Flow canvas as it happens. You can see the new table, its relationships drawn to your existing tables, and verify that everything looks correct before committing the migration.
Why This Matters
Context eliminates hallucinations
The number one problem with AI-generated database code is that the AI doesn't know your current schema. It guesses table names, invents columns, and creates migrations that break. MCP Server eliminates this by giving the AI real, structured access to your actual schema. No more guessing.
Design and code stay in sync
When your AI assistant creates tables through MCP, both your visual diagram and your migration files update simultaneously. There's no drift between your documentation and your implementation.
Speed without sacrificing quality
Describing a feature in natural language and having the AI create the schema, complete with proper relationships, indexes, and data types, is dramatically faster than designing it manually. But because everything appears on your visual canvas, you maintain full oversight. You're not blindly accepting AI-generated SQL β you're reviewing a visual representation of the changes.
It works with your existing workflow
MCP Server doesn't replace your workflow β it enhances it. You can mix manual design (dragging and dropping tables on the canvas) with AI-assisted design (natural language prompts) in the same session. Use AI for the initial structure, then fine-tune visually. Or design manually and ask the AI to review your schema and suggest improvements.
Advanced Usage
Once you're comfortable with the basics, try these advanced patterns.
Schema review: Ask your AI assistant to analyze your entire schema and suggest normalization improvements, missing indexes, or potential performance issues. Because it can see all your tables and relationships, it can identify patterns you might miss.
Cross-cutting changes: Need to add audit columns (created_by, updated_by, deleted_at) to every table? One prompt handles it across your entire schema.
Migration planning: Ask the AI to generate a migration plan that accounts for data preservation. "I need to split the addresses table into billing_addresses and shipping_addresses β generate the migration with data migration steps."
Documentation generation: "Generate a markdown document describing my entire database schema, including all relationships and the purpose of each table."
Getting Started
If you're already using ER Flow, the MCP Server is available in your workspace settings. If you're new to ER Flow, you can create a free account at erflow.io, set up your first diagram, and connect your AI IDE in under 10 minutes.
The gap between your AI assistant and your database is now closed. Your schema is no longer invisible to the tools that help you write code.