Skip to content

Introduction

pgvis turns any PostgreSQL or SQLite database into a fully-featured API — a PostgREST-compatible REST endpoint, Model Context Protocol (MCP) tools for AI agents, and an OpenAPI 3.0 document — from a single Rust engine with zero glue code.

Building database APIs is repetitive. Building typed MCP tools for AI agents is new and manual. Keeping REST endpoints, API documentation, and agent tooling consistent is painful. And when you want to support more than one database, maintaining two query builders doubles the work.

Point pgvis at a database. It introspects the schema once at startup and then serves that schema three ways from one pipeline — one query parser, one planner, one SQL builder:

SurfaceWhat it does
RESTA PostgREST-compatible HTTP API: the same query DSL, Prefer semantics, and PGRST* error codes. Existing PostgREST clients work unchanged.
MCPEvery table and function becomes a typed Model Context Protocol tool an LLM agent can discover and call — no hand-written schemas.
OpenAPIAn OpenAPI 3.0 document generated from the same introspected schema, always in sync with routes.
  • 30+ filter operators — equality, comparison, pattern matching, full-text search, array/JSONB containment, range operators, IS DISTINCT FROM
  • Logic filters — combine conditions with and=/or= using nested boolean expressions
  • Resource embedding — traverse foreign-key relationships with select=orders(items(*)) for nested JSON
  • Cursor pagination — keyset-based forward pagination via cursor_column/cursor_value with X-Next-Cursor header
  • Offset/limit pagination — classic pagination with Content-Range headers and exact/planned/estimated counts
  • Mutations — INSERT, UPDATE, DELETE with upsert (Prefer: resolution=merge-duplicates), bulk operations, and returning representations
  • RPC — call database functions with typed arguments, volatility-aware HTTP method routing
  • JWT authentication — HS256/HS384/HS512/RS256/EdDSA with role switching and Row-Level Security
  • Two backends — PostgreSQL and SQLite from the same engine, auto-detected from DSN
  • Embeddable — use pgvis-lib as a Rust library in your own axum app
PropertyDetails
One engine, three surfacesREST, OpenAPI, and MCP share the planner and SQL builder — they stay consistent by construction
Backend-agnosticAn I/O-free core works with any database implementing the Backend trait. A Dialect capability system gates features per backend
PostgREST-compatibleSame query DSL, same Prefer header semantics, same PGRST* error codes — drop-in replacement
Safe by constructionParameterized SQL (never string interpolation), JWT auth, role switching, RLS, statement timeouts
A library, not just a serverEmbed pgvis in any Rust application via pgvis-lib::Builder
HTTP Request / MCP Tool Call
Parse → ApiRequest (query DSL, filters, cursor, preferences)
Plan → ActionPlan (validate against schema cache, resolve joins)
Render → Parameterized SQL (dialect-aware, CTE-wrapped)
Execute → Backend::execute (Postgres pool / SQLite connection)
Format → JSON response + headers (Content-Range, X-Next-Cursor)

Seven crates, all dependencies pointing inward to the I/O-free core:

CrateRole
pgvis-coreParser, planner, SQL builder, schema cache types
pgvis-postgresPostgres backend (pool, introspection, execution)
pgvis-sqliteSQLite backend (introspection, execution)
pgvis-routeraxum REST router + OpenAPI generator
pgvis-mcpMCP tool generation, execution, stdio + HTTP transport
pgvis-libBuilder facade — the single way to assemble the stack
pgvis-serverThe pgvis CLI binary