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.
Install and start
Section titled “Install and start”-
Install TernoDBI
Terminal window pip install terno-dbi -
Start the server
Terminal window ternodbi startIt runs on
http://127.0.0.1:8376by default. Add a port number to use another one, for exampleternodbi start 9000. On first start it creates anadminuser with the passwordadminand adefaultorganisation. -
Add your database
Open the admin panel at
http://127.0.0.1:8376/adminand add a datasource. Connection details are encrypted at rest. -
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 adminternodbi manage issue_token --name "System Admin" --type admin --org default --user adminAdd
--expires 30for a token that expires after 30 days, or--datasource 1to limit a token to one datasource.
Connect an MCP client
Section titled “Connect an MCP client”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.
Host it for a team
Section titled “Host it for a team”To serve MCP over HTTP with OAuth sign-in instead of tokens, install the HTTP extra and run the ASGI app:
pip install 'terno-dbi[http]'uvicorn terno_dbi.server.asgi:application --port 8376Users then add your server’s /mcp URL to their client, the same way they would add https://mcp.terno.ai/mcp.
Learn more
Section titled “Learn more”- TernoDBI on GitHub: full setup, configuration and API reference.
- TernoDBI overview: what the data layer does and why.