Skip to content

Self-host TernoDBI

Run TernoDBI, the open-source data layer behind Terno's MCP server, on your own infrastructure.

TernoDBI is the open-source layer that powers Terno’s MCP server. Run it yourself if you want your AI agents to query your databases without going through Terno’s hosted service. It is licensed under Apache 2.0 and needs Python 3.10 or later.

It works with PostgreSQL, MySQL, Snowflake, BigQuery, Databricks, Oracle and SQLite, and applies the same safety checks as Terno: only SELECT queries reach your database, row-level filters are added to every query, and tables or columns you mark private stay hidden from the AI.

  1. Install TernoDBI

    Terminal window
    pip install terno-dbi
  2. Start the server

    Terminal window
    ternodbi start

    It runs on http://127.0.0.1:8376 by default. Add a port number to use another one, for example ternodbi start 9000. On first start it creates an admin user with the password admin and a default organisation.

  3. Add your database

    Open the admin panel at http://127.0.0.1:8376/admin and add a datasource. Connection details are encrypted at rest.

  4. Create access tokens

    A query token is read-only, for your AI agent. An admin token can also edit table descriptions, memory and the organisation prompt.

    Terminal window
    ternodbi manage issue_token --name "My Agent" --type query --org default --user admin
    ternodbi manage issue_token --name "System Admin" --type admin --org default --user admin

    Add --expires 30 for a token that expires after 30 days, or --datasource 1 to limit a token to one datasource.

TernoDBI runs as two local MCP servers: a read-only query server and an admin server, each with its own token. For Claude Desktop, open Settings → Developer → Edit Config and add:

{
"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"
}
}
}
}

Restart Claude Desktop and ask “Show me the available datasources.” Other MCP clients that run local servers take the same command, arguments and environment variables.

To serve MCP over HTTP with OAuth sign-in instead of tokens, install the HTTP extra and run the ASGI app:

Terminal window
pip install 'terno-dbi[http]'
uvicorn terno_dbi.server.asgi:application --port 8376

Users then add your server’s /mcp URL to their client, the same way they would add https://mcp.terno.ai/mcp.