Database Intelligence Layer

Created By
terno-ai2 months ago
TernoDBI is a database intelligence layer designed for Security and Accuracy, bridging the gap between AI Agents and Enterprise Data. It acts as a powerful standalone Model Context Protocol (MCP) server, or it can be directly embedded into your existing Django projects. Either way, it provides a unified, secure API for interacting with warehouse-scale databases while enforcing strict access controls and optimizing the database schema context for LLMs.
Overview
image

TernoDBI: Database Intelligence Layer

License Python Django

TernoDBI is a database intelligence layer designed for Security and Accuracy, bridging the gap between AI Agents and Enterprise Data. It acts as a powerful standalone Model Context Protocol (MCP) server, or it can be directly embedded into your existing Django projects. Either way, it provides a unified, secure API for interacting with warehouse-scale databases while enforcing strict access controls and optimizing the database schema context for LLMs.

Quick Start: Chat with your DB in 5 Minutes

The easiest way to get started is to run TernoDBI locally and connect your favorite AI agent.

  1. Install TernoDBI
    pip install terno-dbi
    
  2. Start the Server
    ternodbi start
    
    (This automatically runs migrations, creates a default admin/admin user, and starts the server securely on 127.0.0.1:8376)
  3. Configure your Database Open the admin panel at http://127.0.0.1:8376/admin and add your datasource connections.
  4. Generate an Access Token Generate a token from the Admin UI or via the CLI:
    ternodbi manage issue_token --name "My Agent" --type query
    
  5. Configure MCP (See MCP Integration below)
  6. Start chatting with your enterprise data!

Key Features

  • Multi-Database Support: Out-of-the-box unified connection handling for Postgres, MySQL, Snowflake, BigQuery, Databricks, Oracle, and SQLite.
  • Split MCP Architecture:
    • Query Server: Read-only operations (list tables, schema info, execute SELECT queries) highly optimized for AI agents.
    • Admin Server: Write/Management operations (rename tables, update metadata, manage descriptions) designed for human-in-the-loop workflows.
  • Enterprise-Grade Security:
    • Row-Level Security (RLS): Define strict SQL-based filters (e.g., department_id = 5) that are automatically injected into every executed query.
    • Privacy-by-Default: Hide sensitive tables or columns from the LLM's context window unless explicitly exposed to specific Roles.
    • SQLShield: Automatic AST-based SQL validation preventing prompt injection and destructive operations.
  • LLM-Ready Schema Enrichment:
    • Semantic Metadata: Decouple physical database names (e.g., t_users_v2_fnl) from clean, user-facing semantic names (Customers).
    • Statistical Profiling: Automatic cardinality and distribution statistics injection to help LLMs consistently generate correct SQL filters.
  • High-Performance Pagination:
    • Cursor-Based (HMAC): $O(1)$ performance. Benchmarks demonstrate a ~28x speedup over offset pagination.
    • Server-Side Streaming: Effortlessly export millions of rows via server-side cursors.

Usage & Core APIs

Running the API Server

ternodbi start

Management Commands (CLI)

Automate your credential and access management simply via the built-in CLI:

# General Query Token (For standard AI Assistants)
ternodbi manage issue_token --name "Claude Agent" --type query --expires 30

# Admin Token (Full System Access)
ternodbi manage issue_token --name "System Admin" --type admin

# Scoped Token (Restricted to a Specific Datasource)
ternodbi manage issue_token --name "Finance Data Only" --type query --datasource 1

Query API & Pagination

TernoDBI provides versatile REST endpoints.

Offset Mode (Default) - Best for standard UI implementations.

POST /api/query/datasources/1/query/
{
    "sql": "SELECT * FROM users",
    "pagination_mode": "offset",
    "page": 2,
    "per_page": 50
}

Cursor Mode (High Performance) - Best for headless Agents & large Data Exports.

POST /api/query/datasources/1/query/
{
    "sql": "SELECT * FROM users",
    "pagination_mode": "cursor",
    "per_page": 50,
    "cursor": "eyJ2IjoxLCJ2YWx..." 
}

TernoDBI as an MCP Server

TernoDBI exposes Model Context Protocol (MCP) servers to effortlessly plug into MCP-compatible clients.

Provided MCP Tools:

  • Query Service: list_datasource, list_tables, list_table_columns, execute_query (restricted securely via SQLShield).
  • Admin Service: add_datasource, delete_datasource, validate_connection, sync_metadata, rename_table, rename_column, update_table_description, update_column_description, get_table_info.

Example: Connecting Claude Desktop

  1. Download and install Claude Desktop.
  2. Open Claude Desktop, navigate to Account → Settings → Developer.
  3. Click Edit Config to open your claude_desktop_config.json.
  4. Paste the following configuration:
{
  "mcpServers": {
    "ternodbi-query": {
      "command": "uvx",
      "args": [
        "--from",
        "terno-dbi",
        "dbi-mcp",
        "query"
      ],
      "env": {
        "TERNODBI_API_URL": "http://127.0.0.1:8376",
        "TERNODBI_API_KEY": "dbi_query_YOUR_TOKEN_HERE"
      }
    },
    "ternodbi-admin": {
      "command": "uvx",
      "args": [
        "--from",
        "terno-dbi",
        "dbi-mcp",
        "admin"
      ],
      "env": {
        "TERNODBI_API_URL": "http://127.0.0.1:8376",
        "TERNODBI_API_KEY": "dbi_admin_YOUR_TOKEN_HERE"
      }
    }
  }
}
  1. Restart Claude Desktop. You can now prompt Claude: "Show me the available datasources."

Advanced Integrations

Integrating TernoDBI inside a Custom Django Project

If you already have a mature Django infrastructure, TernoDBI can be integrated directly as a Django App.

Step-by-Step Integration:

  1. Install the package in your Django environment: pip install terno-dbi
  2. Add the core apps to your INSTALLED_APPS in settings.py:
    INSTALLED_APPS = [
        ...
        'terno_dbi.core',
        # Optional: include query or admin apps based on your needs
    ]
    
  3. Include TernoDBI's URL configurations in your root urls.py:
    path('api/terno/', include('terno_dbi.core.urls')), # Mounts the core API endpoints
    
  4. Run python manage.py migrate to apply the TernoDBI schema alongside your existing tables.
  5. You can now use TernoDBI's internal models, query optimizers, and services directly programmatically inside your Django views or Celery tasks!

(Refer to our comprehensive Django Integration Guide for advanced overriding and customization).

Integrating with Custom AI Agents (LangChain, LlamaIndex, Python)

TernoDBI's uniform REST API allows any custom agent architecture to ingest data securely without needing an MCP host.

Step-by-Step Integration:

  1. Provision a specific query token for your custom script using the CLI.
  2. In your Agent implementation, define a tool to call /api/query/datasources/ to discover connections.
  3. Your Agent flow should dictate:
    • Call /api/query/datasources/{id}/schema/ to fetch the context-optimized tables and columns.
    • Inject this highly structured schema context into your LLM prompt.
    • Send the LLM's generated sql string payload via POST to /api/query/datasources/{id}/query/.
    • Iterate based on the response structure or SQLShield validation errors gracefully.

(Refer to our Custom Agent SDK examples for reference implementations in Python and TypeScript).

Documentation

Detailed guides for setting up and mastering TernoDBI:

Contributing

We welcome contributions.

  1. Fork the repo.
  2. Create a feature branch: git checkout -b feat/your-feature
  3. Add tests & docs.
  4. Open a PR describing your change.

Please follow the repo's code style (Black/flake8) and include unit tests for security-critical logic.

Community & Support

If you need help, have a question, or want to discuss a new feature:

  • Open an Issue for bug reports and feature requests.
  • Start a Discussion for general questions or architectural feedback.

License

TernoDBI is proudly open-source and released under the Apache 2.0 License. See the LICENSE file for more details.

Built with precision for the next generation of Enterprise AI.

Server Config

{
  "mcpServers": {
    "ternodbi-query": {
      "command": "uvx",
      "args": [
        "--from",
        "terno-dbi",
        "dbi-mcp",
        "query"
      ],
      "env": {
        "TERNODBI_API_URL": "http://127.0.0.1:8376",
        "TERNODBI_API_KEY": "dbi_query_YOUR_TOKEN_HERE"
      }
    },
    "ternodbi-admin": {
      "command": "uvx",
      "args": [
        "--from",
        "terno-dbi",
        "dbi-mcp",
        "admin"
      ],
      "env": {
        "TERNODBI_API_URL": "http://127.0.0.1:8376",
        "TERNODBI_API_KEY": "dbi_admin_YOUR_TOKEN_HERE"
      }
    }
  }
}
Project Info
Created At
2 months ago
Updated At
2 months ago
Author Name
terno-ai
Star
-
Language
-
License
-
Category

Recommend Servers

View All
Tavily Mcp
@tavily-ai

JavaScript
a year ago
Bring your real authenticated browser session to AI coding agents. Local-first MCP server + Chrome MV3 extension. No cloud. No telemetry.
@Cubenest

peek records the user's actual logged-in browser (DOM via rrweb, console events, network metadata, optional response bodies via opt-in Deep capture) through a Chrome MV3 extension. The extension ships events through a native-messaging stdio bridge to a local MCP server (peek-mcp), which persists them to a SQLite database at ~/.peek/sessions.db. AI coding agents (Claude Code, Cursor, Cline, Windsurf) read sessions from the database via 10 MCP tools: Tool What it does list_recent_sessions List recently recorded sessions (id, origin, ts, event count). get_session_summary LLM-readable narrative summary of a session. get_session_console_errors Console errors recorded in a session. get_session_network_errors Failed/notable network requests in a session. get_user_action_before_error Last N user actions before a console error. generate_playwright_repro Generate a runnable Playwright test from a session. get_dom_snapshot Reconstruct the DOM at a given timestamp. query_dom_history Timeline of attribute/text changes for a selector. request_authorization Side-panel consent for write actions (Level 3). execute_action Dispatch a UI action (gated by permission level + destructive blocklist). Why local-first matters Every other "browser session for AI" tool ships to a vendor cloud. peek's SQLite + extension live on the user's machine — no remote endpoints, no telemetry. The privacy policy (docs/peek/PRIVACY_POLICY.md) is the source of truth. Install # 1. Add the MCP server to Claude Code claude mcp add peek -- npx -y @peekdev/mcp # 2. Install the Chrome extension from the Chrome Web Store # (link added once the CWS listing is approved)

a day ago
AI Work Market — USDC settlement rails for AI labor on Base Mainnet)
@Dario (DME)

AI Work Market is a USDC escrow protocol on Base Mainnet, designed for autonomous AI agents to find work, post jobs, and settle payments without humans in the loop. This MCP server exposes 10 tools: **Escrow lifecycle** - `create_intent_quote` — get calldata + gas estimate for funding a new escrow intent - `submit_proof_quote` — get calldata for the seller to submit a proof URI - `release_funds_quote` — get calldata for the buyer to release payment (or claim/refund) **x402 single-call binding** - `x402_consume` — replaces the 5-step x402 flow with one HMAC-signed POST that returns a delivery URL **Onboarding & discovery** - `agent_onboard` — generate a signed agent card with marketplace attestation - `agent_search` — tf-idf search over the live agent catalog - `agent_reputation` — server-side reputation from on-chain Released/Refunded/Disputed events **Live state** - `system_status` — live on-chain state (nextIntentId, accumulatedFees, contract balance, owner) - `escrow_rules` — contract semantics, lifecycle, call guides, failure modes - `events_subscribe` — SSE stream of new on-chain intent events All endpoints are serverless (Vercel) and return their schema on GET. No browser, no wallet UI required for an agent to integrate. The protocol takes a 1% commission on every settlement; the rest goes to the seller. The full AgentCard is at `/.well-known/agent-card.json` (A2A-compatible). The OpenAPI 3.0.3 spec is at `/.well-known/openapi.json` with `components.securitySchemes` (none, hmacX402). `robots.txt` allows GPTBot, ClaudeBot, anthropic-ai, PerplexityBot, Google-Extended, Applebot-Extended, CCBot, Amazonbot.

8 hours ago