Skip to content

Repository files navigation

Datapad

Terminal-based database client for Oracle and PostgreSQL with SSH jump server support.

Demo

Features

  • Multi-Database Support - Connect to Oracle (service name/SID) or PostgreSQL
  • SSH Jump Server - Tunnel connections through SSH jump servers with key-based or password authentication
  • Interactive SQL Prompt - Full-featured terminal prompt with history and auto-completion
  • Table Formatting - Results displayed as formatted tables in the terminal
  • Saved Connections - SQLite database to save and load connection profiles
  • Meta Commands - .tables, .describe, .connect, .save, .load, etc.
  • MCP Server - Expose database tools to LLMs via Model Context Protocol (tdb-mcp)
  • MCP Query Control - Configure which tools and query modes the LLM can use via ~/.terminal_db/mcp.toml

Requirements

  • Python 3.10+
  • Oracle Instant Client (for oracledb thick mode, optional)

Installation

cd terminal-db-client
pip install -e .

Usage

tdb

Commands

Meta Commands (start with .)

Command Description
.connect Connect to a database (interactive prompt)
.connect <name> Connect using a saved connection
.disconnect Disconnect from database
.tables List all tables in current schema
.describe <table> Show table structure
.save <name> Save current connection
.load <name> Load a saved connection
.list List all saved connections
.delete <name> Delete a saved connection
.clear Clear screen
.exit / .quit Exit the application
.help Show help

SQL Execution

Just type any SQL query and press Enter:

SELECT * FROM user_tables;

Keyboard Shortcuts

Shortcut Action
Ctrl+R Search command history
Tab Auto-completion
Ctrl+C Cancel current input
Ctrl+D Exit

Saved Connections

Connections are saved in ~/.terminal_db/connections.db (SQLite). Query history is saved in ~/.terminal_db/query_history.txt.

Connection Fields

Database Connection

Field Description Example
Database Type oracle or postgres oracle
Host Database server hostname db.example.com
Port Database port 1521 (Oracle) / 5432 (PostgreSQL)
Service Name Oracle service name or PostgreSQL database name ORCLPDB1 / mydb
SID Oracle SID (alternative to service name) ORCL
Username Database username system
Password Database password ••••••

SSH Jump Server (optional)

Field Description Example
SSH Host Jump server hostname jump.example.com
SSH Port SSH port (default: 22) 22
SSH Username SSH username admin
SSH Key Path Path to SSH private key ~/.ssh/id_rsa
SSH Password SSH password (if no key) ••••••

Architecture

src/terminal_db/
├── main.py                    # CLI entry point
├── config.py                  # Pydantic models for connection config
├── db_connection.py           # Base ABC + OracleConnection + factory
├── db_connection_postgres.py  # PostgreSQL connection
├── ssh_tunnel.py              # SSH tunnel manager with paramiko
├── query_executor.py          # SQL query executor (Oracle & PostgreSQL)
├── connection_store.py        # SQLite connection storage
└── mcp/                       # MCP server for LLM integration
    ├── server.py              #   tools: connect, list_tables, describe_table, execute_query
    └── mcp_config.py          #   config loader (mcp.toml + CLI flags)

MCP Server (AI Integration)

DataPad provides an MCP server so LLMs (Claude, Copilot, etc.) can query your databases directly.

tdb-mcp

Configure in your MCP client (e.g., Claude Desktop):

{
  "mcpServers": {
    "datapad": {
      "command": "tdb-mcp"
    }
  }
}

Available tools:

  • list_connections — List saved connections
  • connect(connection_name) — Connect using a saved profile
  • list_tables — List tables in current schema
  • describe_table(table_name) — Show column structure
  • execute_query(query) — Run SQL queries (subject to query mode)

Save a connection first via tdb, then the MCP server uses the same ~/.terminal_db/connections.db.

MCP Configuration

Control what the LLM can do by editing ~/.terminal_db/mcp.toml:

[tools]
allowed = ["list_tables", "describe_table", "execute_query", "connect", "list_connections"]

[query]
mode = "read-only"  # "read-only" | "write"
max_rows = 200

Query Modes

Mode Allowed
read-only SELECT only
write Any query (INSERT, UPDATE, DELETE, DDL)

CLI Flags (override toml)

tdb-mcp --allow-write        # enable write mode for this session
tdb-mcp --max-rows 500       # override max rows
tdb-mcp --tools list_tables,describe_table  # restrict available tools

License

MIT

About

Your pocket Datapad for querying databases from the terminal

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages