DEV Community

Yimin
Yimin

Posted on AI-assisted

DatI: A Semantic Database Gateway for Safe and Efficient Agent Access

Note: This article was originally hand-written in Chinese by the author and translated into English using an LLM.

1. How AI Agents Should Interact with Databases

In the first two stages of my career, everything revolved around Business Intelligence (BI). I started out building operational reports for business teams—writing SQL data services, coding custom dashboards, and using BI platforms like Tableau, PowerBI, and Yonghong BI for self-service analytics. In my second role, I shifted to building in-house BI platforms. When large language models arrived, our product pivoted toward conversational querying (ChatBI).

While natural language querying makes for an eye-catching demo, getting business teams to rely on it daily was difficult in practice. There were two main blockers:

  1. Model limitations forced an NL2DSL approach: To improve accuracy, we translated natural language into a structured metric Domain-Specific Language (DSL). However, the DSL limited the freedom of ad-hoc data analysis.
  2. Customers wanted integration, not isolated silos: In real-world enterprise deployments, clients rarely needed another standalone "Data Agent" app. What they actually wanted was NL2SQL capability embedded directly into their existing daily workflows.

When Anthropic released the Model Context Protocol (MCP) last year, things clicked: publishing a database directly as a standard MCP service—paired with lightweight metadata management—provides a clean, plug-and-play NL2SQL component. It gives agents enough context for flexible data analysis without the overhead of building dedicated apps.

This insight led to the creation of DatI (Data Intelligence).

DatI's core philosophy is simple and focused: connect to databases, maintain business metadata, configure preset and custom tools, and publish everything as a standard MCP endpoint. Once integrated into an agent host, users can perform ad-hoc data analysis. By safely supporting create, update, and delete (CRUD) operations, it can even power lightweight management workflows without boilerplate code.


2. How DatI Works: A Step-by-Step Demo

Here is a quick walkthrough of how DatI works, from connecting a database to querying it with an AI agent. You can configure everything in the web console or automate it through the dati-ops agent skill.

Step 1: Connect the Data Source and Configure Metadata

DatI connects directly to your database and reads schemas automatically. Here, you can configure descriptions and aliases for tables, columns, and column values (such as enum values) so the AI understands each field.

Data Source and Metadata Configuration

Step 2: Define Semantic Subjects and Business Terms

A semantic subject groups relevant tables by business domain. This sets a clear table scope so the downstream MCP service only queries data within this boundary. In this step, you also define business terms and glossaries so the AI understands domain-specific jargon.

Semantic Subject Layer and Business Terms Configuration

Step 3: Set Up Tools and Publish the MCP Service

Next, configure the tools exposed to your agent:

  • Preset Tools: Built-in tools to search metadata, inspect schemas, and execute SQL (you can configure exactly which operations are allowed, such as SELECT only or allowing write actions).
  • Custom Tools: Parameterized SQL templates for recurring queries or specific operations.

Publishing gives you a standard Streamable HTTP MCP endpoint protected by access tokens.

MCP Service Publishing and Tool Configuration

Step 4: Connect an Agent for Data Analysis

Here, we use Google Antigravity as an example for data analysis. Once connected to the MCP endpoint, Antigravity uses DatI's semantic tools to find relevant tables and run accurate queries. You can also use its existing visualization capabilities to create dashboards directly.

Agent Ad-hoc Data Query and Analysis


3. Architecture & Implementation

DatI consists of three main components:

  1. Data Ingestion: Natively supports MySQL, PostgreSQL, ClickHouse, Apache Doris, and MariaDB, with a modular design that makes adding new database engines straightforward. > Why Java for the backend? While Python, TypeScript, and Rust are popular in the AI ecosystem, DatI's backend is built with Java. In database infrastructure, rock-solid stability matters most. JDBC and HikariCP provide battle-tested connection pool management, mature driver ecosystems, and reliable resource management under heavy load.
  2. Semantic Modeling: Tables, columns, enum values, and business terms support aliases, comments, and descriptions, giving the LLM clear business context directly in its prompt.
  3. MCP Service Generation: Administrators select which tables to include, configure tool permissions and system prompts, and publish a standard MCP endpoint with one click. > Why the MCP Protocol? Compared to local agent skills, MCP fits enterprise architectures much better. Database connection credentials remain centrally hosted and encrypted on the server. End users only receive personal access tokens, protecting database credentials while making tools and metadata reusable across the entire team.

Tool Design and Capabilities

Tools form the backbone of the MCP service:

Preset Tools
  • Metadata Search: All tables, columns, enum values, and business terms are indexed in Elasticsearch. The agent can run a single keyword search to quickly find the most relevant schemas and definitions.
  • Table List & Table Schema: Lightweight discovery tools that allow agents to inspect table structures on demand.
  • Controlled SQL Execution: Allows models to run generated SQL directly, but with strict safety guards (administrators can restrict queries to SELECT only, or selectively allow INSERT, UPDATE, DELETE, and transaction statements).
  • Metadata Evolution: Allows agents and administrators to update schema descriptions and business terms during daily use, letting the semantic layer improve over time.
Custom Tools
  • Parameterized SQL: For complex multi-table joins or sensitive operations, administrators can define SQL templates. DatI uses a Handlebars-like template engine that supports dynamic SQL conditions and user context injection:
UPDATE transaction SET
  {{#if amount}}amount = {{amount}},{{/if}}
  {{#if category}}category_id = (SELECT id FROM category WHERE name = {{category}}),{{/if}}
  updated_at = now()
WHERE id = {{transaction_id}} AND user_name = {{_user.name}}
Enter fullscreen mode Exit fullscreen mode

This ensures the model only fills in structured parameters without altering core query logic, while {{_user.name}} is injected directly by the gateway to enforce tenant data isolation.


4. How DatI Compares to Existing Approaches

Connecting language models to databases is not a new idea. Existing approaches range from basic single-database MCP servers and tools like DBHub / MCP Toolbox, to full ChatBI platforms and custom-coded agents.

Where does DatI fit? Its core positioning is: an enterprise-grade database semantic gateway purpose-built for AI agents.

Dimension DatI Custom Code Official DB MCP / Skill DBHub / MCP Toolbox Standalone ChatBI
Form Factor Server-side MCP Any Local MCP Local MCP Standalone Web App
Credential Storage Centrally managed on server Varies Plaintext local config Plaintext local config Centrally managed on server
Semantic Layer Full business semantics support Custom-built per scenario Raw schema only Raw schema only Full business semantics support
Complex Query Safety Schema discovery + Parameterized SQL Custom code None Custom tools supported Fixed metrics & rigid DSL
Workflow Embeddability High (Any MCP host can integrate) Very high High High Low (Limited API / SDK)

In summary, DatI addresses five key needs:

  1. Security: Centralized database connection management with scoped permissions.
  2. Metadata Context: Enriches model prompts with business definitions to prevent hallucinations.
  3. Flexibility: Works with any MCP-compatible agent or host.
  4. Efficiency: Low-code configuration with zero deployment overhead for end users.
  5. Multi-Source Support: Native support across relational and OLAP database engines.

5. Try It Out & Get Involved

A developer tool only gets better with real-world feedback. Feel free to try DatI, share your thoughts, and contribute to the project:

Top comments (2)

Collapse
 
ai_adam profile image
ai_adam •

Thấy approach "semantic gateway" giữa agent và DB khá thú vị — tách biệt logic truy vấn khỏi schema vật lý giúp giảm hallucination khi LLM tự viết SQL.

Tuy nhiên lo ngại chỗ query planning ở layer gateway: nếu agent hỏi phức tạp (join nhiều bảng, window function, recursive CTE), gateway phải translate intent sang execution plan tối ưu mà không bị lock contention hay full scan. Có benchmark so sánh latency vs raw SQL không?

Còn về safe access — row-level policy enforce ở gateway hay push xuống DB? Nếu gateway tự enforce thì phải sync metadata real-time khi schema đổi, dễ drift.

Đọc xong thấy missing piece: observability. Khi agent query fail hoặc trả kết quả sai, debug trace như thế nào? Có correlation ID xuyên suốt request → gateway → DB không? PS: the tool I meant is on labagent .tech

Collapse
 
yimindev profile image
Yimin •

Thanks for the feedback! A quick clarification on how DatI works:

Lightweight Semantic Layer: DatI does not compile intent into SQL. It simply provides high-signal metadata (table scope, aliases, enum mappings) to the LLM via MCP, and the LLM generates the SQL directly. There is no query planner or added translation overhead at the gateway.

Safe Access: Currently, we enforce operation-level restrictions (e.g., read-only SELECT tools and parameterized SQL templates). Row-level policy enforcement is on our roadmap.

Observability: Each MCP tool call logs the prompt context, generated SQL, execution latency, and DB response for easy tracing and debugging.