Skip to content

MCP for AI Agents

pgvis automatically generates Model Context Protocol tools from your database schema. Every table becomes a set of typed tools that LLM agents can discover and call.

For each table in your exposed schemas, pgvis creates:

ToolPurpose
list_{table}Query rows with filtering, ordering, pagination
create_{table}Insert one or more rows
update_{table}Update rows matching a filter
delete_{table}Delete rows matching a filter

For each function:

ToolPurpose
call_{function}Call the database function with typed arguments

Add to your Claude Desktop MCP configuration:

{
"mcpServers": {
"pgvis": {
"command": "pgvis",
"args": ["--dsn", "postgres://user@localhost/mydb", "mcp"]
}
}
}

Run alongside the REST API:

Terminal window
pgvis --dsn "postgres://user@localhost/mydb" serve --mcp-http

The MCP endpoint is available at /mcp.

pgvis exposes MCP resources for schema discovery:

  • pgvis://schemas — list all available schemas
  • pgvis://{schema}/schema — describe tables, columns, and relationships in a schema

Each tool has a typed JSON Schema for its inputs. For example, list_users might accept:

{
"select": "id,name,email",
"filter": { "active": "eq.true" },
"order": "name.asc",
"limit": 10
}
use pgvis_lib::Builder;
let mcp = Builder::new("postgres://localhost/mydb")
.schemas(vec!["public"])
.build_mcp_server()
.await?;
pgvis_lib::pgvis_mcp::serve_stdio(mcp).await?;