Home/Tools/@tpmjs/tools-supabase

callRpc

@tpmjs/tools-supabase

Call a Supabase PostgreSQL function (RPC) with optional parameters.

Official
ops
v0.1.0
MIT

Interactive Playground

Test @tpmjs/tools-supabase (callRpc) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-supabase
pnpm add @tpmjs/tools-supabase
yarn add @tpmjs/tools-supabase
bun add @tpmjs/tools-supabase
deno add npm:@tpmjs/tools-supabase

2. Import the tool

import { callRpc } from '@tpmjs/tools-supabase';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { callRpc } from '@tpmjs/tools-supabase';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { callRpc },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Signature

(function_name: string, params?: Record<string, unknown>) => Promise<unknown>

Tags

ai
call
database
function
ops
optional
parameters
postgres
postgresql
rpc
supabase
tpmjs

Parameters

Available configuration options

Auto-extracted
function_name
Required
Type: string

The PostgreSQL function name to call.

params
Optional
Type: object

Object containing function parameters.

Schema extracted: 3/1/2026, 4:29:20 AM

README

@tpmjs/tools-supabase

Supabase REST API tools for AI agents. Query, insert, update, delete rows, call RPC functions, and more using the PostgREST API.

Installation

npm install @tpmjs/tools-supabase

Setup

Set these environment variables:

SUPABASE_URL="https://your-project.supabase.co"
SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"

The service role key bypasses Row Level Security (RLS) and grants full database access to AI agents.

Usage

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { queryRows, insertRows } from '@tpmjs/tools-supabase';

const result = await generateText({
  model: openai('gpt-4o'),
  prompt: 'Get the first 5 users from the database',
  tools: { queryRows, insertRows },
});

Query Rows

import { queryRows } from '@tpmjs/tools-supabase';

// Query with filtering and ordering
await queryRows.execute({
  table: 'users',
  select: 'id,name,email',
  filter: 'age=gte.18&status=eq.active',
  order: 'created_at.desc',
  limit: 10,
});

Insert Rows

import { insertRows } from '@tpmjs/tools-supabase';

// Insert a single row
await insertRows.execute({
  table: 'users',
  rows: [{ name: 'Alice', email: 'alice@example.com' }],
});

// Bulk insert
await insertRows.execute({
  table: 'users',
  rows: [
    { name: 'Bob', email: 'bob@example.com' },
    { name: 'Carol', email: 'carol@example.com' },
  ],
});

Available Tools

ToolDescription
queryRowsQuery rows from a table with filtering, ordering, and pagination
getRowByIdGet a single row by its primary key value
insertRowsInsert one or more rows into a table
updateRowsUpdate rows matching a filter condition
deleteRowsDelete rows matching a filter condition
upsertRowsInsert or update rows using merge-duplicates strategy
callRpcCall a PostgreSQL function (RPC) with parameters
countRowsCount rows in a table with optional filtering
listTablesList all available tables in the database
searchRowsSearch rows using case-insensitive pattern matching

PostgREST Filter Syntax

Supabase uses PostgREST filter syntax for queries:

  • Equality: status=eq.active
  • Greater than: age=gt.18
  • Greater than or equal: age=gte.18
  • Less than: price=lt.100
  • Pattern matching: name=like.*smith*
  • Case-insensitive: email=ilike.*@gmail.com
  • Multiple filters: age=gte.18&status=eq.active (AND)

See PostgREST documentation for more operators.

Safety Features

Important: The updateRows and deleteRows tools require a non-empty filter to prevent accidental full-table operations. This is a safety requirement to protect your data.

// ❌ This will throw an error
await deleteRows.execute({ table: 'users', filter: '' });

// ✅ This is safe
await deleteRows.execute({ table: 'users', filter: 'id=eq.123' });

License

MIT

Statistics

Downloads/month

46

GitHub Stars

15

Quality Score

85%

Bundle Size

NPM Keywords

tpmjs
ops
ai
supabase
database
postgres

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai
callRpc | TPMJS | TPMJS