terrabase
OfficialUses Ollama's structured output capabilities to draft SQL migrations, with fallback to raw SQL input if Ollama is unavailable.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@terrabasePropose a migration to add an email column to users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
terrabase-v2
LLM-assisted, safety-gated Postgres migrations, exposed as an MCP server.
A local LLM may draft migration SQL, but a deterministic rule engine over Postgres's own parser AST is the sole safety authority. Every write goes through a two-phase, approval-gated flow and lands in an append-only audit ledger.
The LLM proposes, the rules decide.
Layout (pnpm monorepo)
Package | Purpose |
| shared types, zod schemas, errors, config, DSN redaction |
|
|
| the 30-rule deterministic safety analyzer (the heart) |
| live schema → compact JSON model |
|
|
| append-only audit ledger + transactional, approval-gated apply |
| Ollama structured output + retry-on-zod-error |
| the 5 MCP tools + two-phase orchestration |
Full design: docs/specs/2026-07-07-terrabase-v2-design.md.
Related MCP server: pg-sentinel
Quick start
pnpm install
pnpm build # tsup builds every package
pnpm typecheck # tsc --noEmit, strict
pnpm test # vitest unit tests (run everywhere)Configure via env (see .env.example): TERRABASE_DATABASE_URL, OLLAMA_HOST,
OLLAMA_MODEL, TERRABASE_PG_VERSION.
Run the MCP server
pnpm mcp # speaks MCP over stdioRegister it with any MCP client (command: node apps/mcp-server/dist/index.js).
Graceful degradation
The parser + rule engine run with no external services. If Ollama is down, pass sql
directly to propose_migration. If there's no database, SQL is still parsed and analyzed
offline against TERRABASE_PG_VERSION. Docker-backed integration tests skip automatically when
Docker is unavailable.
MCP tools
inspect_schema— compact schema model (read-only)propose_migration—intent→LLM-drafted SQL or rawsql→ analyze → returns aSafetyReport+proposalId(applies nothing)apply_migration—proposalId+approvalToken→ gated, transactional apply → ledgerexplain_query— parsed plan tree + flagged problemsadvise_index— HypoPG-simulated index recommendations (Tier-1 catalog fallback)
Desktop app (Strata)
An Electron GUI over the same engine lives in apps/desktop. It runs the
parser + rule engine locally, auto-discovers project databases, and renders the
SafetyReport visually.
pnpm --filter @terrabase-v2/desktop devContributing
Contributions are welcome! Please read CONTRIBUTING.md for setup, the PR checklist, and the one non-negotiable rule (the LLM is advisory only). All participants are expected to follow our Code of Conduct.
Security
Found a vulnerability? Please report it privately — see SECURITY.md. Do not open a public issue for security reports.
License
Licensed under the Apache License 2.0. © 2026 Terrabase.in.
This server cannot be deployed
Maintenance
Related MCP Connectors
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Query your warehouse or a CSV with Claude/ChatGPT over MCP, governed by table-level ACL + audit.
Related MCP Servers
- AlicenseNot gradedqualityAmaintenanceA hardened, read-only Postgres MCP server that enables LLMs to safely query databases without write, DDL, shell, or credential exposure.MIT
- AlicenseNot gradedqualityBmaintenanceA PostgreSQL MCP server with three independent safety layers that allows LLMs to explore and query databases safely via read-only SELECT operations, with full audit logging and query plan intelligence.MIT
- FlicenseAqualityBmaintenanceAn MCP server that enables AI agents to securely interact with PostgreSQL databases with least-privilege scopes, PII masking, and human approval for writes.4-
- FlicenseAqualityBmaintenanceA security-hardened Postgres MCP server that enables LLM agents to run safe, read-only SQL queries with enforcement via SQL-AST inspection and read-only transactions.1-