The first time I wired Claude Code into a database over MCP, it felt like cheating. I asked it to check a few tables, add a column, and pull a filtered slice of rows, and it handled the whole thing without me opening a SQL client.
That honeymoon lasted about a week. As soon as we tried using the same setup on a real project with other people and real business data, the usual raw-SQL MCP approach started falling apart:
- You either hand the agent a read-only replica (which kills schema prototyping, test seeding, and internal tool work) or you give it write access and hope it never misreads a prompt and runs a bad
ALTERor an unscopedDELETE. - Generic database connections almost always run under a service role or table owner. That quietly bypasses your application's row-level policies and pulls sensitive columns (
discount_size, margins, internal notes, PII) straight into the LLM context window. - Even when the agent does everything right and creates clean tables, you are left with a headless database. If a PM, ops teammate, or client wants to browse records, filter rows, or export to Excel, you still have to build an admin panel.
- And you still have to write the CRUD endpoints, validation, pagination, and auth middleware before any frontend or automation workflow can talk to those tables.
To be fair, raw SQL over MCP still makes sense in plenty of cases. If you are tuning query plans, running EXPLAIN ANALYZE, or investigating a legacy 300-table Postgres cluster, a tightly restricted read-only SQL role is hard to beat.
For building application tables, client portals, and internal tools, though, giving the agent raw SQL is the wrong abstraction. Instead of exposing execute_sql, we put MCP one layer up, in front of our platform's metadata and permission engine.
Raw SQL MCP vs. Entity MCP
We open-sourced our server (@yourappspace/mcp-server, MIT) for YourAppSpace Core around a small set of typed entity operations instead of raw SQL strings.
Here is how the two approaches compare in day-to-day use:
| Area | Raw SQL MCP | Entity MCP (dev-entity) |
|---|---|---|
| Schema changes | Arbitrary DDL (ALTER, DROP TABLE, TRUNCATE) |
Typed calls (create_table, add_field, delete_field), no DROP TABLE
|
| Auth & permissions | DB connection role (often over-privileged) | User-scoped API key enforcing server-side RLS and Field-Level Security |
| Sensitive columns | Often returned into LLM context unless stripped via custom views | Hidden/read-only columns blocked server-side by role and workflow state |
| Client guardrails | Hard to classify arbitrary SQL strings | Standard MCP tool annotations (readOnlyHint, destructiveHint, idempotentHint) |
| Human UI | None (DB client / CLI only) | Built-in Visual Data Model Designer and Data Grid UI with Excel/CSV export |
| App API | Manual controllers / middleware | Auto-generated REST endpoints for every table |
Keeping the tool surface small (9 tools)
One trap we wanted to avoid early on was wrapping every REST endpoint 1-to-1 and dumping 40+ tool schemas into the model's context window before the first prompt. We capped dev-entity at 9 tools and collapsed single-row and batch mutations into the same CRUD tools (item vs. items):
| Tool | What it does | readOnlyHint |
destructiveHint |
|---|---|---|---|
list_tables |
Lists accessible tables (supports offset / limit pagination) |
true |
false |
get_table |
Fetches table metadata, PK (<tableName>id), columns, and lookup targets |
true |
false |
create_table |
Creates a new custom table in the active workspace | false |
false |
add_field |
Adds a scalar column (INTEGER, DOUBLE, BOOLEAN, STRING, TEXT, DATE, DATETIME, TIME, BIGINT) or foreign-key lookup (lookupEntity) |
false |
false |
delete_field |
Deletes a non-key column (system and primary keys are protected) | false |
true |
read_rows |
Queries rows with parameterized whereQuery + params or JSON filters, sorting, pagination, and includeTotal
|
true |
false |
create_rows |
Inserts one record (item) or a batch (items) |
false |
false |
update_rows |
Partially updates one or more rows by primary key | false |
false |
delete_rows |
Deletes one or more rows by primary key | false |
true |
What is missing from that list is intentional: no execute_sql, no drop_table, and no DELETE or UPDATE driven by a WHERE clause.
Server-side RLS and column visibility
Prompt instructions like "never delete rows" or "don't read sensitive columns" are advice, not security boundaries. Every call from dev-entity sends a user-scoped API key (ip_api_key_...) in the X-Auth header, and the backend evaluates the exact same rules that govern the web UI and REST API.
On the row side, Access Maps control View, Create, Edit, and Delete per role or expression. If a user's Access Map filters rows with createdbyid=@currentUserId and has Delete unchecked, any delete_rows call made with that user's key fails with HTTP 403 regardless of what the prompt asked for.

Access Map restricting row visibility to the creator and disabling deletes server-side.
Row-level security alone still leaves a common blind spot: if an agent is allowed to read an Order row, a normal query still pulls restricted columns straight into the chat context. With Field-Level Security, columns like discount_size can be marked hidden, read-only, or required by role and workflow stage. Hidden fields never leave the server.

Field-Level Security rules controlling discount_size across workflow stages.
Trying the full workflow (no sign-up needed)
If you want to see the split-screen flow before wiring anything locally, here is a short walkthrough:
To try it yourself locally, you just need Node.js >= 20.20 and npm >= 10.8.
1. Grab a sandbox API key
Open core.yourappspace.com and click Try now. It spins up an isolated demo workspace immediately without asking for an email. In the welcome message on the right, copy your ip_api_key_... value from YOUR API KEY FOR REST & MCP:

The instant demo workspace generates a ready-to-use API key in the welcome panel.
2. Wire up your MCP client with npx
You don't need to clone the repo. MCP_ENTITY_BASE_URL defaults to https://core.yourappspace.com, so you only need to set it when pointing at a self-hosted Docker instance (like http://localhost:8080).
For Claude Code (.mcp.json in your project root) or Cursor (.cursor/mcp.json):
{
"mcpServers": {
"dev-entity": {
"command": "npx",
"args": ["-y", "@yourappspace/mcp-server"],
"env": {
"MCP_ENTITY_API_KEY": "ip_api_key_your_key_here"
}
}
}
}
OpenAI Codex CLI (~/.codex/config.toml):
[mcp_servers.dev-entity]
command = "npx"
args = ["-y", "@yourappspace/mcp-server"]
[mcp_servers.dev-entity.env]
MCP_ENTITY_API_KEY = "ip_api_key_your_key_here"
JetBrains IntelliJ IDEA AI Assistant:
Open Settings -> Tools -> AI Assistant -> Model Context Protocol (MCP), click + Add -> STDIO, paste the same JSON block as Claude Code / Cursor above, and click Apply.
Heads-up when testing the connection: seeing all 9 tools show up in
/mcponly tells you the STDIO process booted. It does not validate your key. Run a quicklist_tablescall with{"offset": 0, "limit": 1}right after saving your config:
- HTTP
401: double-check theip_api_key_prefix (don't addBearerin front of it) and key expiration.- HTTP
403: auth worked, but the key's user lacks permission for that table or action.
If you want the agent to follow the platform's naming and field conventions out of the box, the repo also ships BASE_PROMPT.md (drop it in as CLAUDE.md or AGENTS.md) and a Cursor rule at rules/yourappspace-mcp.mdc.
3. Inspecting and evolving an existing table
A very typical day-two task is adding columns to a table that already exists. Say we ask the agent:
Inspect the
Ordertable schema, then adddelivery_address(STRING) andpriority(INTEGER). Verify both fields are registered afterward.
The agent calls list_tables, reads the existing structure with get_table, and sends two add_field calls:
{
"tableName": "order_1789030504",
"fieldName": "delivery_address",
"fieldType": "STRING",
"displayName": "Delivery Address"
}
{
"tableName": "order_1789030504",
"fieldName": "priority",
"fieldType": "INTEGER",
"displayName": "Priority"
}

The agent adds both columns and immediately re-checks table metadata with get_table.
When you open the Order entity in YourAppSpace, those columns are already registered across table metadata, forms, and workflow rules:

New fields appear immediately in the table configuration without a separate migration deploy.
And because the visual designer reads the same live metadata, relationships across tables stay visible instead of drifting out of sync with handwritten docs:

Visual Data Model Designer showing live tables and foreign-key links.
4. Creating a related table, seeding rows, and querying
Creating a new table with a foreign-key reference follows the same sequence. Ask the agent to create customer_feedback linked to interaction, seed 4 records, and summarize rows with rating >= 4.
First, create_table:
{
"tableName": "customer_feedback",
"displayName": "Customer Feedback"
}
Then add_field for each scalar column and for the lookup reference (notice that fieldType is omitted when setting lookupEntity):
{
"tableName": "customer_feedback",
"fieldName": "interaction",
"displayName": "Interaction",
"lookupEntity": "interaction"
}
Next, insert records in batch mode with create_rows (custom tables automatically include a primary key <tableName>id and require displayname):
{
"tableName": "customer_feedback",
"items": [
{
"displayname": "Feedback #1",
"interaction": 1,
"rating": 5,
"status": "Reviewed",
"comment": "Fast response and clear onboarding walkthrough"
},
{
"displayname": "Feedback #2",
"interaction": 2,
"rating": 4,
"status": "New",
"comment": "Helpful consultation, minor follow-up needed"
},
{
"displayname": "Feedback #3",
"interaction": 3,
"rating": 2,
"status": "New",
"comment": "Took too long to get an initial reply"
},
{
"displayname": "Feedback #4",
"interaction": 4,
"rating": 5,
"status": "Resolved",
"comment": "Issue resolved quickly on the first call"
}
]
}
For reading back filtered records, read_rows supports bound parameters (params), sorting, pagination, and includeTotal:
{
"tableName": "customer_feedback",
"whereQuery": "rating >= :minRating",
"params": {
"minRating": 4
},
"orderBy": "[{\"field\":\"rating\",\"direction\":\"desc\"}]",
"includeTotal": true,
"limit": 50
}
That same read_rows tool also works nicely for quick spot checks from the CLI or IDE, like pulling a single record by ID:

Inspecting a single Order record through read_rows without switching to a DB GUI.
Or pulling a filtered slice and formatting it straight into CSV:

Filtered read_rows query formatted into CSV right in the agent session.
5. What you get without writing UI or controllers
Once the agent finishes creating tables or inserting rows, teammates can immediately work with the data in the built-in Data Grid UI (columns, grouping, sorting, filters, inline editing, Excel export):

A record inserted by the MCP agent showing up immediately in the live Data Grid.
And every table exposes documented REST API endpoints governed by the exact same RLS and Field-Level Security rules:

Auto-generated REST API endpoints ready for frontends, scripts, or workflow tools.
Three small design decisions that mattered most
If you are building your own MCP server over a business backend, these three details saved us the most debugging time:
Non-atomic batch writes with per-row errors
When an agent inserts 20 rows via create_rows and row #14 has a bad foreign key or fails validation, returning a generic HTTP 500 almost always triggers a retry loop that duplicates rows #1 through #13. Instead, batch writes process rows independently and return a structured result:
{
"count": 1,
"items": [
{
"status": "ok",
"item": {
"customer_feedbackid": 101,
"displayname": "Feedback #1"
}
}
],
"errors": [
{
"status": "error",
"index": 1,
"message": "Referenced interaction id 999 does not exist"
}
]
}
That gives the model enough context to fix just the failing row instead of retrying the whole batch.
Mandatory primary keys on update_rows and delete_rows
Both tools require <tableName>id on every item in the payload. Refusing filter-based updates and deletes structurally rules out accidental mass updates or wipes.
Documenting the difference between "tools loaded" and "auth works"
Most MCP clients list tools right after the STDIO handshake without touching the upstream API. Explicitly telling users (and putting in CLAUDE.md / .mdc rules) to verify connectivity with list_tables({"offset": 0, "limit": 1}) avoids confusing silent auth errors later in a session.
What we're working on next
Right now @yourappspace/mcp-server runs as a local STDIO bridge via npx. That works well for local dev and for self-hosted / air-gapped Docker deployments (just set MCP_ENTITY_BASE_URL to your instance).
Next, we're adding a hosted Remote MCP endpoint (Streamable HTTP) straight onto YourAppSpace workspaces so you can connect an agent with a URL and token, without needing Node.js installed locally.
Links if you want to poke at it
- Instant sandbox (no sign-up): core.yourappspace.com
- Open-source MCP server (MIT): github.com/yourappspace/yourappspace-mcp
- npm package:
npx -y @yourappspace/mcp-server(npmjs.com/package/@yourappspace/mcp-server) - Full MCP docs: yourappspace.com/docs.html#454
- Feedback / issues: GitHub Discussions
If you are giving Claude Code or Cursor write access to a database in your own stack, what guardrails ended up sticking? I'm still weighing whether we should add an explicit dry-run / diff mode for schema mutations next.
Top comments (0)