Quick answer: A production AI agent backend architecture must combine four layers without relying on prompt instructions alone: PostgreSQL 18 + pgvector HNSW for structured & semantic state, Row-Level Security (RLS) for tenant isolation, a hardened MCP server (@aurabase/mcp-server: 86 tools, 82 with project key, 37 engine-enforced read-only tools, --destructive-policy), and AST-verified read-only NL2SQL + multi-provider AI Gateway (OpenAI, Anthropic, Gemini) hosted in the EU.
The Problem
Why prompt-only guardrails fail in production
Most tutorials wire an LLM straight to a database driver and add "Please never run DROP TABLE" to the system prompt. Prompt instructions are probabilistic — indirect prompt injection inside user-generated text or hallucinated schema edits will eventually bypass them.
A real AI agent backend moves every boundary out of the prompt and into the database and protocol engines: PostgreSQL transactions, RLS roles, AST validation, and fail-closed MCP servers.
4-Layer Blueprint
The four layers of a hardened AI agent backend
| Layer | Security & architectural responsibility | Aurabase native implementation |
|---|---|---|
| 1. Memory & State | Structured records + sub-10ms vector similarity + flexible docs | Dedicated PostgreSQL 18 + pgvector HNSW (and --engine mongodb projects for NoSQL) |
| 2. Agent Tooling (MCP) | Typed tool discovery, zero fabricated values, destructive gates | @aurabase/mcp-server: 86 tools across 13 domains (--read-only, --destructive-policy, --allowed-tools) |
| 3. Data Isolation & NL2SQL | Tenant isolation + zero SQL injection for end-user queries | PostgreSQL RLS (auth.uid()) + Rust sqlparser AST-validated read-only NL2SQL with mandatory LIMIT |
| 4. LLM Gateway & Audit | Multi-provider routing + full EU query/latency audit trail | Native AI Gateway (OpenAI, Anthropic, Gemini, SSE streaming) + EU ClickHouse observability |
MCP Hardening
Inside Aurabase's 86-tool MCP server (13 domains)
Unlike thin database wrappers that only expose one raw run_sql tool, @aurabase/mcp-server structures access into 13 typed domains with validated output schemas (82 tools with a project key; 4 reserved for management-plane credentials):
- Database (23) & RLS (6):
list_tables,describe_table,diff_schema,apply_migration,explain_query,get_security_advisors,create_rls_policy,toggle_rls - AI (5) & Observability (4):
index_document,rag_query,vector_search,create_vector_index,ai_completion,list_slow_queries,list_active_queries - Storage (9), Auth (7), Edge Functions (6), Backups (5), Notifications (10), Realtime (3), Project (4), API keys (3), Docs (1)
Passing --read-only removes every mutating tool from tools/list and instructs PostgreSQL to run every query inside a READ ONLY transaction — even a clever SQL payload cannot write or drop data.
# Local stdio for Cursor / Claude Code / VS Code (37 read-only tools)
npx -y -p @aurabase/mcp-server aurabase-mcp \
--url "https://<slug>.aurabase.cloud" \
--project-id "<project-uuid>" \
--service-role-key "aura_sk_..." \
--read-onlyEnd-User AI
AST-verified NL2SQL + pgvector RAG for end users
For customer-facing AI features (analytics copilots, semantic document search), Aurabase combines two complementary paths directly inside aura-ai:
- RAG with
pgvectorHNSW: embed and index tenant documents in the same PostgreSQL 18 database as your application data — no separate Pinecone/Qdrant cluster to synchronize or leak cross-tenant vectors. - AST-verified NL2SQL: natural-language questions compile into SQL parsed through Rust's
sqlparser, rejecting anything other than a bounded read-onlySELECTand honoring your existing RLS policies.
IDE Guides
Connect your AI coding agent in 60 seconds
Follow our step-by-step setup guides for Cursor, Claude Code, VS Code Copilot Agent, or read the full 86-tool MCP reference and Native AI overview.
Frequently Asked Questions