terrabase

terrabase

LLM-assisted, safety-gated Postgres migrations exposed as an MCP server, using a deterministic rule engine over Postgres's own parser AST for safety enforcement, with two-phase approval and append-only audit ledger.

Category
Visit Server

README

terrabase-v2

CI License: Apache 2.0 Node PRs Welcome

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
packages/core shared types, zod schemas, errors, config, DSN redaction
packages/pg-ast libpg_query (WASM) parse + traversal + typed node guards
packages/pg-safety the 30-rule deterministic safety analyzer (the heart)
packages/pg-introspect live schema → compact JSON model
packages/pg-advisor EXPLAIN (FORMAT JSON) parsing + HypoPG index advice
packages/pg-migrate append-only audit ledger + transactional, approval-gated apply
packages/llm Ollama structured output + retry-on-zod-error
apps/mcp-server the 5 MCP tools + two-phase orchestration

Full design: docs/specs/2026-07-07-terrabase-v2-design.md.

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 stdio

Register 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_migrationintent→LLM-drafted SQL or raw sql → analyze → returns a SafetyReport + proposalId (applies nothing)
  • apply_migrationproposalId + approvalToken → gated, transactional apply → ledger
  • explain_query — parsed plan tree + flagged problems
  • advise_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 dev

Contributing

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.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured