跪拜 Guibai
← All articles
Database · Artificial Intelligence · AI Programming

KingbaseES Fences AI Queries with MCP Isolation and Row-Level Audit

By 这个DBA有点耶 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

AI agents that generate SQL against a production database invalidate the old trust model of human-written, static queries. This architecture shows where to insert isolation, per-row audit, and output filtering, and it's honest about three spots where the design still depends on human decisions.

Summary

KingbaseES's KES AI database wraps AI access in three layers: an MCP isolation layer, row-level semantic audit, and full-chain LLM output validation. The premise is that keeping data inside the database is necessary but not sufficient, because AI generates SQL dynamically, reads large contextual chunks, and can produce misleading conclusions even from compliant queries. The design moves permission checking forward: the AI client never holds credentials and only passes query intent to an MCP Server, which validates SQL type, runs risk grading, and forwards only compliant requests to KingbaseES. The database remains the final arbiter, but the first filter happens before the SQL arrives.

Row-level access control ties permissions to specific rows, and audit records semantic context: which business scenario, which agent, which sensitive data tags. That granularity catches query sequences that are individually compliant but together amount to bulk extraction. On the output side, a generate-validate-grade-output loop blocks or flags high-risk model conclusions before they reach users.

The breakdown also names three open questions: the MCP Server's own security, who defines the AI's business permissions with a default of blocking DDL and large DML, and audit log integrity against tampering. The conclusion is that security is a set of continuously running mechanisms, not a one-time switch.

Takeaways
— Data never leaves the database is necessary but not sufficient for AI database security.
— AI Agent SQL is dynamically generated, can read large context batches, and is hard to distinguish from malicious instructions at the SQL level.
— KingbaseES places an MCP Server between the AI client and the database; the AI client holds no credentials and only passes query intent.
— MCP Server runs SQL whitelist validation and risk grading before forwarding requests; KingbaseES remains the final permission arbiter.
— Traditional audit records account+SQL+time, but AI requires row-level access control and semantic context such as business scenario, originating agent, and sensitive data tags.
— Semantic audit analyzes query sequences, not just single statements, to catch bulk extraction from many compliant queries.
— Full-chain LLM output validation uses a generate-validate-grade-output loop to block or flag high-risk conclusions before user delivery.
— Three open questions: MCP Server security, who defines AI permission boundaries (default: block DDL and bulk DML), and audit log integrity/tamper resistance.
Conclusions

The design builds trust at the protocol layer by stripping the AI of direct database credentials, which is a cleaner pattern than trying to sanitize generated SQL after the fact.

Semantic audit that flags query sequences rather than individual statements treats an AI agent's access pattern as the attack surface, not a single misbehaving query.

The three open questions admit that no database-side mechanism settles who gets to decide what an AI may do; that remains a human policy decision, and a default of banning DDL and bulk DML is a pragmatic stand.

Concepts & terms
MCP (Model Context Protocol)
A protocol for connecting AI models to external tools and data. Here, KingbaseES uses an MCP Server as an isolation layer so the AI client never holds direct database credentials; it only passes query intent to the server, which validates and forwards requests.
Row-level access control
A security mechanism that restricts which rows a user or agent can access, not just which tables. It enables finer-grained permissions and more detailed audit trails.
Semantic audit
An audit mode that records the business context of each query (business scenario, initiating agent, sensitive data tags) in addition to the SQL, so sequences of queries can be analyzed for pattern-based abuse.
LLM output validation
A post-generation check on the model's response, grading it for risk and blocking or flagging high-risk content before it reaches the user, to prevent misleading or out-of-bounds conclusions derived from compliant data.
From the discussion
Featured comments
shushenghong

The layer of "who asked AI to query, and why" is equally missing from coding agents. Our team runs all AI tasks on a dedicated machine within the team, credentials are stored only on that machine, permissions are assigned per project, and every access can be traced back to which task was dispatched by whom, so at least it's auditable when something goes wrong. The issue of individual compliance but combined overreach is very real. I'd like to ask: when semantic audit identifies sequences of queries, does it aggregate by session, or by the task that the Agent undertook?

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗