All connectors

Prisma Postgres

Databases

Prisma Postgres

Connect agents to a Prisma Postgres database so they can answer questions from your application's data.

Explore your data

  • Find the tables behind your Prisma models, with their columns, keys and relations.
  • Look up records, join tables, and summarize results.
  • Read JSON columns as structured data.

Make changes when you allow it

Prisma Postgres credentials always have full access to the database, so Houston adds the safety. With Read access, every statement runs in a read-only transaction and data and schema cannot change. With Write access, agents can also insert, update and delete rows.

Schema changes are best made through Prisma Migrate in your project, so your schema.prisma stays in step with the database.

Setup instructions

You need a Prisma Postgres database in the Prisma Console. No developer app is required.

  1. In the Prisma Console, open your project and select the database.
  2. Select Connect to your database, then Generate new connection string. Generate a new one for Houston rather than reusing your application's, so you can revoke it on its own later.
  3. Copy the direct connection string. It looks like postgres://USERNAME:[email protected]:5432/postgres?sslmode=require.
  4. In Houston, choose the access level. Read is recommended: every Prisma Postgres credential can change data, so Houston's Read level is what keeps agents from doing so.
  5. Leave Connection on Direct (recommended).
  6. Paste the Username (between postgres:// and the first :) and the Password (between that : and @db.prisma.io).
  7. Select Add connector.

Your password stays on the Houston server. Houston always connects with TLS and checks Prisma's certificate.

See Prisma's guide to direct connections for more about connection strings.

Advanced

Direct or pooled connection

Both use the same username and password. Houston opens a short connection for each statement, so the direct connection works well. Choose Pooled only if your plan's direct connection limit is reached; pooled statements stop after 10 minutes.

Revoking access

Generating a connection string doesn't revoke older ones. The Console names them all console-connection-string; tell yours apart by the last four characters of the password. Delete it in the Console when you remove this connector.

Troubleshooting

  • "Password authentication failed". Copy the username and password again from a freshly generated connection string. If the password contains % sequences, it was URL-encoded: enter the decoded characters.
  • "Could not connect". Check that the database still exists in the Prisma Console, and that Connection is set to one of Prisma's hosts.

Files

  • connector.luau
    -- Prisma Postgres over Houston's verified-TLS connection to db.prisma.io. Credentials stay on Houston.
    type Params = {string | number | boolean}
    type Result = {columns: {string}, rows: {{[string]: any}}, truncated: boolean, affectedRows: number?}
    type Table = {schema: string, name: string, type: string}
    type Column = {
    	name: string,
    	type: string,
    	nullable: boolean,
    	default: string?,
    	primaryKey: boolean,
    	references: {schema: string, table: string, column: string}?,
    }
    
    local MAX_ROWS = 10000
    local MAX_TABLES = 1000
    
    local function requireText(value: any, name: string): string
    	if type(value) ~= "string" or value == "" then
    		error(name .. " must be a nonempty string", 2)
    	end
    	return value
    end
    
    local function checkParams(params: any): Params?
    	if params == nil then
    		return nil
    	end
    	if type(params) ~= "table" then
    		error("params must be an array of strings, numbers or booleans", 2)
    	end
    	local count = 0
    	for key, value in params do
    		count += 1
    		local kind = type(value)
    		if type(key) ~= "number" or (kind ~= "string" and kind ~= "number" and kind ~= "boolean") then
    			error("params must be an array of strings, numbers or booleans", 2)
    		end
    	end
    	if count ~= #params then
    		error("params must be an array without gaps", 2)
    	end
    	return params
    end
    
    local function run(sql: string, params: Params?, readOnly: boolean, maxRows: number): Result
    	return await(db.query({sql = sql, params = params, maxRows = maxRows, readOnly = readOnly}))
    end
    
    local function query(sql: string, params: Params?): Result
    	return run(requireText(sql, "sql"), checkParams(params), true, MAX_ROWS)
    end
    
    local function execute(sql: string, params: Params?): Result
    	return run(requireText(sql, "sql"), checkParams(params), false, MAX_ROWS)
    end
    
    local TABLES_SQL = [[SELECT table_schema, table_name, table_type
    FROM information_schema.tables
    WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
      AND table_schema NOT LIKE 'pg\_%'
      AND ($1::text IS NULL OR table_schema = $1::text)
    ORDER BY table_schema, table_name]]
    
    local function listTables(schema: string?): {tables: {Table}, truncated: boolean}
    	if schema ~= nil then
    		requireText(schema, "schema")
    	end
    	local filter: any = if schema then schema else json.decode("null")
    	local result = run(TABLES_SQL, {filter}, true, MAX_TABLES)
    	local tables: {Table} = json.decode("[]")
    	for _, row in result.rows do
    		table.insert(tables, {
    			schema = row.table_schema,
    			name = row.table_name,
    			type = if row.table_type == "VIEW" then "view" else "table",
    		})
    	end
    	return {tables = tables, truncated = result.truncated}
    end
    
    local COLUMNS_SQL = [[SELECT column_name, data_type, udt_name, is_nullable, column_default
    FROM information_schema.columns
    WHERE table_schema = $1 AND table_name = $2
    ORDER BY ordinal_position]]
    
    local KEYS_SQL = [[SELECT a.attname AS column_name, con.contype::text AS kind,
      fn.nspname AS ref_schema, fc.relname AS ref_table, fa.attname AS ref_column
    FROM pg_constraint con
    JOIN pg_class c ON c.oid = con.conrelid
    JOIN pg_namespace n ON n.oid = c.relnamespace
    CROSS JOIN LATERAL unnest(con.conkey) WITH ORDINALITY AS k(attnum, ord)
    JOIN pg_attribute a ON a.attrelid = c.oid AND a.attnum = k.attnum
    LEFT JOIN pg_class fc ON fc.oid = con.confrelid
    LEFT JOIN pg_namespace fn ON fn.oid = fc.relnamespace
    LEFT JOIN pg_attribute fa ON fa.attrelid = con.confrelid AND fa.attnum = con.confkey[k.ord]
    WHERE n.nspname = $1 AND c.relname = $2 AND con.contype IN ('p', 'f')
    ORDER BY con.contype, con.conname, k.ord]]
    
    local function describeTable(name: string, schema: string?): {schema: string, table: string, columns: {Column}}
    	requireText(name, "name")
    	local schemaName = if schema == nil then "public" else requireText(schema, "schema")
    	local columnRows = run(COLUMNS_SQL, {schemaName, name}, true, MAX_ROWS).rows
    	if #columnRows == 0 then
    		error(`Table {schemaName}.{name} was not found; names are case-sensitive, so check listTables()`, 2)
    	end
    	local primary: {[string]: boolean} = {}
    	local references: {[string]: {schema: string, table: string, column: string}} = {}
    	for _, row in run(KEYS_SQL, {schemaName, name}, true, MAX_ROWS).rows do
    		if row.kind == "p" then
    			primary[row.column_name] = true
    		elseif row.kind == "f" and references[row.column_name] == nil then
    			references[row.column_name] = {schema = row.ref_schema, table = row.ref_table, column = row.ref_column}
    		end
    	end
    	local columns: {Column} = json.decode("[]")
    	for _, row in columnRows do
    		table.insert(columns, {
    			name = row.column_name,
    			type = if row.data_type == "USER-DEFINED" or row.data_type == "ARRAY" then row.udt_name else row.data_type,
    			nullable = row.is_nullable == "YES",
    			default = row.column_default,
    			primaryKey = primary[row.column_name] == true,
    			references = references[row.column_name],
    		})
    	end
    	return {schema = schemaName, table = name, columns = columns}
    end
    
    local exports: {[string]: any} = {query = query, listTables = listTables, describeTable = describeTable}
    if houston.allows("data:write") then
    	exports.execute = execute
    end
    
    local HELP: {[string]: string} = {
    	listTables = [[listTables(schema?) -> {tables = {{schema, name, type}}, truncated}
      Lists tables and views (type "table" or "view"), sorted by schema and name,
      optionally in one schema. System schemas are left out. At most 1,000 entries.
      Example: prisma.listTables("public")]],
    	describeTable = [[describeTable(name, schema?) -> {schema, table, columns}
      Describes one table or view; schema defaults to "public". Each column is
      {name, type, nullable, default?, primaryKey, references?}, in table order;
      references is {schema, table, column} for a foreign key. Enum and array
      columns report their PostgreSQL type name, such as "Role" or "_text".
      Names are case-sensitive: Prisma models usually map to quoted names like "User".
      Raises an error when the table does not exist.
      Example: prisma.describeTable("User")]],
    	query = [[query(sql, params?) -> {columns, rows, truncated}
      Runs one statement in a read-only transaction. Bind values with $1, $2, ...
      in sql and pass them in order as params (strings, numbers, booleans).
      Parameters take their type from context; cast where needed, as in $1::jsonb.
      Prisma creates case-sensitive names, so double-quote them: SELECT "id",
      "createdAt" FROM "User". Prisma enums are PostgreSQL enum types; compare
      them as text or cast, as in "role" = $1::"Role". The _prisma_migrations
      table records applied migrations.
      rows are objects keyed by column name, in columns order; NULL columns are
      absent. Booleans, integers, floats and json/jsonb columns become Lua values;
      integers beyond 2^53 and every other type keep PostgreSQL's text form, such as
      '2026-01-31 09:30:00+00' for timestamptz or '\x0102' for bytea.
      At most 10,000 rows or 4 MiB are returned; truncated tells when more exist,
      so add LIMIT, filters or aggregation. Give duplicate column names an alias.
      Example: prisma.query('SELECT "id", "email" FROM "User" WHERE "role" = $1::"Role" LIMIT 50', {"ADMIN"})]],
    	execute = [[execute(sql, params?) -> {affectedRows, columns, rows, truncated}
      Runs one statement that may change data, outside any transaction, with the
      same parameters as query. affectedRows counts the inserted, updated or deleted
      rows; rows hold any RETURNING values. A failed or interrupted call may already
      have applied its change, so check before running it again. Schema changes made
      here bypass Prisma Migrate and will drift from the project's schema.prisma.
      Example: prisma.execute('UPDATE "Task" SET "done" = true WHERE "id" = $1 RETURNING "id"', {42})]],
    }
    
    function exports.help(): string
    	local sections = {
    		"prisma-postgres: SQL on one Prisma Postgres database. Each call is one statement on its own connection. "
    			.. "Connector calls return values directly; do not await them. "
    			.. "Start with listTables() and describeTable(name) to find the right quoted names.",
    	}
    	for _, name in {"listTables", "describeTable", "query", "execute"} do
    		if exports[name] then
    			table.insert(sections, HELP[name])
    		end
    	end
    	return table.concat(sections, "\n\n")
    end
    
    return exports
    
  • houston.json
    {
      "schema_version": 2,
      "name": "Prisma Postgres",
      "files": [
        "connector.luau"
      ],
      "icon": "icon.svg",
      "access": [
        {
          "name": "data",
          "label": "Access",
          "description": "Prisma Postgres credentials always have full access to the database. Read runs every statement in a read-only transaction, so agents cannot change data or schema. Write also lets them insert, update and delete rows.",
          "levels": [
            {
              "value": "read",
              "label": "Read"
            },
            {
              "value": "write",
              "label": "Write"
            }
          ],
          "default": "read"
        }
      ],
      "config": {
        "host": {
          "default": "db.prisma.io",
          "description": "Use the direct connection unless your plan's direct connection limit is reached.",
          "label": "Connection",
          "options": [
            {
              "label": "Direct (recommended)",
              "value": "db.prisma.io"
            },
            {
              "label": "Pooled",
              "value": "pooled.db.prisma.io"
            }
          ],
          "order": 1,
          "required": true,
          "type": "string"
        },
        "username": {
          "description": "The part of your connection string between postgres:// and the first colon.",
          "label": "Username",
          "max_length": 256,
          "order": 2,
          "required": true,
          "type": "string"
        },
        "password": {
          "description": "The part of your connection string between the colon after the username and @db.prisma.io.",
          "label": "Password",
          "order": 3,
          "required": true,
          "type": "secret"
        }
      },
      "proxy": [
        {
          "match": {
            "protocol": "postgres"
          },
          "action": {
            "connection": {
              "host": "{{config.host}}",
              "port": 5432,
              "database": "postgres",
              "user": "{{config.username}}",
              "password": "{{config.password}}",
              "tls": {
                "mode": "verify-full"
              }
            }
          }
        }
      ]
    }
    
  • icon.svgicon.svg
  • README.md
    ---
    description: Give agents SQL access to a Prisma Postgres database, read-only unless you allow changes.
    ---
    # Prisma Postgres
    
    Connect agents to a Prisma Postgres database so they can answer questions from
    your application's data.
    
    ## Explore your data
    
    - Find the tables behind your Prisma models, with their columns, keys and
      relations.
    - Look up records, join tables, and summarize results.
    - Read JSON columns as structured data.
    
    ## Make changes when you allow it
    
    Prisma Postgres credentials always have full access to the database, so Houston
    adds the safety. With **Read** access, every statement runs in a read-only
    transaction and data and schema cannot change. With **Write** access, agents
    can also insert, update and delete rows.
    
    Schema changes are best made through Prisma Migrate in your project, so your
    `schema.prisma` stays in step with the database.
    
  • SETUP.md
    You need a Prisma Postgres database in the
    [Prisma Console](https://console.prisma.io). No developer app is required.
    
    1. In the Prisma Console, open your project and select the database.
    2. Select **Connect to your database**, then **Generate new connection string**.
       Generate a new one for Houston rather than reusing your application's, so you
       can revoke it on its own later.
    3. Copy the **direct** connection string. It looks like
       `postgres://USERNAME:[email protected]:5432/postgres?sslmode=require`.
    4. In Houston, choose the access level. **Read** is recommended: every Prisma
       Postgres credential can change data, so Houston's Read level is what keeps
       agents from doing so.
    5. Leave **Connection** on **Direct (recommended)**.
    6. Paste the **Username** (between `postgres://` and the first `:`) and the
       **Password** (between that `:` and `@db.prisma.io`).
    7. Select **Add connector**.
    
    Your password stays on the Houston server. Houston always connects with TLS and
    checks Prisma's certificate.
    
    See Prisma's guide to
    [direct connections](https://www.prisma.io/docs/postgres/database/direct-connections)
    for more about connection strings.
    
    ## Advanced
    
    ### Direct or pooled connection
    
    Both use the same username and password. Houston opens a short connection for
    each statement, so the direct connection works well. Choose **Pooled** only if
    your plan's direct connection limit is reached; pooled statements stop after 10
    minutes.
    
    ### Revoking access
    
    Generating a connection string doesn't revoke older ones. The Console names them
    all `console-connection-string`; tell yours apart by the last four characters of
    the password. Delete it in the Console when you remove this connector.
    
    ### Troubleshooting
    
    - **"Password authentication failed".** Copy the username and password again
      from a freshly generated connection string. If the password contains `%`
      sequences, it was URL-encoded: enter the decoded characters.
    - **"Could not connect".** Check that the database still exists in the Prisma
      Console, and that **Connection** is set to one of Prisma's hosts.
    
  • tests
    • describe_table.luau
      -- describeTable merges columns with primary and foreign keys, defaults to public, and reports a missing table.
      return {
      	scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "db.prisma.io", username = "fixture-user", password = "fixture-password"}},
      	access = {data = "read"},
      	configure = function()
      		requests = {}
      		db = {query = function(request)
      			table.insert(requests, request)
      			local isKeys = string.find(request.sql, "pg_constraint", 1, true) ~= nil
      			if request.params[2] == "Missing" then
      				return fixture.operation({columns = {}, rows = {}, truncated = false})
      			end
      			if isKeys then
      				return fixture.operation({columns = {"column_name", "kind", "ref_schema", "ref_table", "ref_column"}, rows = {
      					{column_name = "authorId", kind = "f", ref_schema = "public", ref_table = "User", ref_column = "id"},
      					{column_name = "id", kind = "p"},
      				}, truncated = false})
      			end
      			return fixture.operation({columns = {"column_name", "data_type", "udt_name", "is_nullable", "column_default"}, rows = {
      				{column_name = "id", data_type = "integer", udt_name = "int4", is_nullable = "NO", column_default = "nextval('\"Post_id_seq\"'::regclass)"},
      				{column_name = "title", data_type = "text", udt_name = "text", is_nullable = "NO"},
      				{column_name = "status", data_type = "USER-DEFINED", udt_name = "Status", is_nullable = "YES"},
      				{column_name = "tags", data_type = "ARRAY", udt_name = "_text", is_nullable = "NO"},
      				{column_name = "authorId", data_type = "integer", udt_name = "int4", is_nullable = "NO"},
      			}, truncated = false})
      		end}
      	end,
      	run = function(exports)
      		local result = exports.describeTable("Post")
      		assert(result.schema == "public" and result.table == "Post" and #result.columns == 5)
      		local id, title, status, tags, author = table.unpack(result.columns)
      		assert(id.name == "id" and id.type == "integer" and id.primaryKey == true and id.nullable == false)
      		assert(id.default == "nextval('\"Post_id_seq\"'::regclass)" and id.references == nil)
      		assert(title.primaryKey == false and title.default == nil)
      		assert(status.type == "Status" and status.nullable == true)
      		assert(tags.type == "_text")
      		assert(author.references.schema == "public" and author.references.table == "User" and author.references.column == "id")
      
      		assert(#requests == 2)
      		for _, request in requests do
      			assert(request.readOnly == true)
      			assert(request.params[1] == "public" and request.params[2] == "Post")
      		end
      		assert(string.find(requests[1].sql, "information_schema.columns", 1, true))
      
      		exports.describeTable("Report", "analytics")
      		assert(requests[3].params[1] == "analytics" and requests[3].params[2] == "Report")
      
      		local ok, err = pcall(exports.describeTable, "Missing")
      		assert(not ok and string.find(tostring(err), "public.Missing was not found", 1, true))
      		assert(#requests == 5, "a missing table stops before the key query")
      		ok, err = pcall(exports.describeTable, "")
      		assert(not ok and string.find(tostring(err), "name must be a nonempty string", 1, true))
      		assert(#requests == 5)
      	end,
      }
      
    • list_tables.luau
      -- listTables reads information_schema read-only, filters by schema when asked, and keeps an empty result an array.
      return {
      	scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "db.prisma.io", username = "fixture-user", password = "fixture-password"}},
      	access = {data = "read"},
      	configure = function()
      		requests = {}
      		db = {query = function(request)
      			table.insert(requests, request)
      			if #requests == 1 then
      				return fixture.operation({columns = {"table_schema", "table_name", "table_type"}, rows = {
      					{table_schema = "public", table_name = "User", table_type = "BASE TABLE"},
      					{table_schema = "public", table_name = "_prisma_migrations", table_type = "BASE TABLE"},
      					{table_schema = "reporting", table_name = "ActiveUsers", table_type = "VIEW"},
      				}, truncated = false})
      			end
      			return fixture.operation({columns = {"table_schema", "table_name", "table_type"}, rows = {}, truncated = false})
      		end}
      	end,
      	run = function(exports)
      		local all = exports.listTables()
      		assert(#all.tables == 3 and all.truncated == false)
      		assert(all.tables[1].schema == "public" and all.tables[1].name == "User" and all.tables[1].type == "table")
      		assert(all.tables[3].name == "ActiveUsers" and all.tables[3].type == "view")
      		local first = requests[1]
      		assert(first.readOnly == true and first.maxRows == 1000)
      		assert(string.find(first.sql, "information_schema.tables", 1, true))
      		assert(json.encode(first.params) == "[null]", "no schema filter sends a JSON null parameter")
      
      		local empty = exports.listTables("archive")
      		assert(#empty.tables == 0 and json.encode(empty.tables) == "[]", "empty results stay JSON arrays")
      		assert(requests[2].params[1] == "archive" and requests[2].readOnly == true)
      
      		local ok, err = pcall(exports.listTables, "")
      		assert(not ok and string.find(tostring(err), "schema must be a nonempty string", 1, true))
      		assert(#requests == 2)
      	end,
      }
      
    • pooled.luau
      -- The pooled host is an accepted Connection choice and serves the same operations.
      return {
      	scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "pooled.db.prisma.io", username = "fixture-user", password = "fixture-password"}},
      	configure = function()
      		requests = {}
      		db = {query = function(request)
      			table.insert(requests, request)
      			return fixture.operation({columns = {"ok"}, rows = {{ok = 1}}, truncated = false})
      		end}
      	end,
      	run = function(exports)
      		assert(exports.execute == nil, "access defaults to Read")
      		assert(exports.query("SELECT 1 AS ok").rows[1].ok == 1 and #requests == 1)
      		assert(requests[1].readOnly == true)
      	end,
      }
      
    • read_only.luau
      -- Read connections expose the read operations alone, and query always asks for a read-only statement.
      return {
      	scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "db.prisma.io", username = "fixture-user", password = "fixture-password"}},
      	access = {data = "read"},
      	configure = function()
      		requests = {}
      		db = {query = function(request)
      			table.insert(requests, request)
      			return fixture.operation({columns = {"id", "email"}, rows = {{id = 7, email = "[email protected]"}}, truncated = false})
      		end}
      	end,
      	run = function(exports)
      		assert(exports.execute == nil, "Read access must not expose execute")
      		assert(exports.query and exports.listTables and exports.describeTable, "read operations must be exported")
      		local result = exports.query('SELECT "id", "email" FROM "User" WHERE "role" = $1::"Role"', {"ADMIN"})
      		assert(result.rows[1].id == 7 and result.rows[1].email == "[email protected]" and result.truncated == false)
      		local request = requests[1]
      		assert(request.sql == 'SELECT "id", "email" FROM "User" WHERE "role" = $1::"Role"')
      		assert(#request.params == 1 and request.params[1] == "ADMIN")
      		assert(request.readOnly == true and request.maxRows == 10000)
      
      		exports.query("SELECT 1")
      		assert(#requests == 2 and requests[2].params == nil and requests[2].readOnly == true)
      
      		local ok, err = pcall(exports.query, "")
      		assert(not ok and string.find(tostring(err), "sql must be a nonempty string", 1, true))
      		ok, err = pcall(exports.query, "SELECT $1", {{nested = true}})
      		assert(not ok and string.find(tostring(err), "params must be an array", 1, true))
      		ok, err = pcall(exports.query, "SELECT $1", {name = "x"})
      		assert(not ok and string.find(tostring(err), "params must be an array", 1, true))
      		assert(#requests == 2, "invalid arguments must not reach the database")
      	end,
      }
      
    • read_write.luau
      -- Write connections add execute, which sends a statement allowed to write.
      return {
      	scenario = {publisher = {}, auth_method = "", auth_config = {}, config = {host = "db.prisma.io", username = "fixture-user", password = "fixture-password"}},
      	access = {data = "write"},
      	configure = function()
      		requests = {}
      		db = {query = function(request)
      			table.insert(requests, request)
      			return fixture.operation({columns = {"id"}, rows = {{id = 42}}, truncated = false, affectedRows = 1})
      		end}
      	end,
      	run = function(exports)
      		assert(exports.query and exports.listTables and exports.describeTable, "read operations stay exported")
      		local result = exports.execute('UPDATE "Task" SET "done" = true WHERE "id" = $1 RETURNING "id"', {42})
      		assert(result.affectedRows == 1 and result.rows[1].id == 42)
      		local request = requests[1]
      		assert(request.sql == 'UPDATE "Task" SET "done" = true WHERE "id" = $1 RETURNING "id"')
      		assert(request.readOnly == false and request.maxRows == 10000)
      		assert(#request.params == 1 and request.params[1] == 42)
      
      		exports.query('SELECT count(*) AS n FROM "Task"')
      		assert(requests[2].readOnly == true, "query stays read-only on Write connections")
      
      		local ok = pcall(exports.execute, "")
      		assert(not ok and #requests == 2)
      	end,
      }