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.
README
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 |
|---|---|
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_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 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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。