Build an app backend with Supabase and Lares
Supabase provides a PostgreSQL database, user authentication, and APIs for applications on your Olares device. With Lares connected through the Supabase Model Context Protocol (MCP) server, you can create tables and access policies through conversation.
In this tutorial, you will build and run a command-line notes application, using row-level security (RLS) to keep each user's notes private. You will also use Metabase to query sample project costs stored in a separate database table.
Learning objectives
In this guide, you will learn how to:
- Connect Lares to the Supabase MCP server.
- Create a database table to store users’ notes and configure per-user access with RLS.
- Use Lares to generate a notes application, then run it in Code Server and sign in with a user account created in Supabase.
- Verify that each user can access only their own notes.
- Connect Metabase to Supabase and query sample project costs.
Prerequisites
- Lares configured with a model that supports tool calls. Follow Get started with Lares to complete the setup.
- Code Server installed from Market. You will use its editor and terminal to create and run the notes application.
- Metabase installed from Market for reporting.
Install Supabase
- Open Market and search for "Supabase".
- Click Get, then Install, and wait for installation to complete.
Connect Lares to the Supabase MCP server
Connect Lares to Supabase so you can use database tools in a conversation.
Connection authentication
Lares connects through Olares authentication on the same instance, so you do not need to provide an additional access token or API key. Keep the Supabase Studio entrance set to Internal in Olares Settings.
Open Olares Settings, and go to Applications > Supabase > Supabase Studio.
Copy the Endpoint address, and append
/api/mcpto the end. For example:texthttps://<studio-host>/api/mcpOpen Lares, go to Settings > MCP, and click Add server.
Specify the following settings:
Setting Value Server name supabase_officialTransport Streamable HTTPMCP URL The copied endpoint address ending in /api/mcpClick Save. Lares connects and loads the server's tools.
Start a new conversation in Lares to check the MCP connection with the following prompt:
textUse supabase_official to list the tables in the public schema and return this Supabase installation's API URL. Use the MCP tools directly and do not modify data.Lares should return the Supabase API URL and a list of tables in the
publicschema. If you have not created any tables yet, the list will be empty.
Build and run a notes application with Supabase
Use Lares to prepare a Supabase database table, configure access policies, and generate a notes application. Then run the application in Code Server and check that each user can access only their own notes.
Create the notes table and access policy with Lares
With the MCP connection ready, use Lares to create a database table for the notes application and an access policy so each user can access only their own notes.
Each note stores its owner's user ID in owner_id. The policy compares this value with the signed-in user's ID to control access.
Database administration access
The MCP server can change database tables and access policies. Review the proposed SQL and approve only the intended changes.
In the Lares conversation, describe the required table and policy:
textUse supabase_official to prepare a private notes table for my app. Inspect the public schema first. Create public.user_notes with: - id: UUID primary key, default gen_random_uuid() - owner_id: UUID, required - note: text, required Enable RLS and grant SELECT, INSERT, UPDATE, DELETE to authenticated. Create an own_notes policy FOR ALL TO authenticated with both USING and WITH CHECK set to auth.uid() = owner_id. Use apply_migration for the schema changes. Show the planned SQL before applying it. Only change this table, and do not drop existing data or grant anonymous access. If the table already exists, explain any differences before proposing a migration.Review the proposed SQL. When Lares asks for approval, approve only the intended changes and wait for it to finish.
Open Supabase Studio, and go to Table Editor. Find
user_notesand check theid,owner_id, andnotecolumns and the RLS policy indicator showing one policy.Ask Lares to inspect
user_notesand summarize its RLS policy:textUse supabase_official to inspect public.user_notes. Confirm that RLS is enabled and summarize the policy's name, the role it applies to, and both the USING read condition and the WITH CHECK write check.The summary should show RLS enabled and one
own_notespolicy for theauthenticatedrole, with both conditions comparingauth.uid()withowner_id.
Alternative: create the notes table in SQL Editor
If you have not created user_notes with Lares, open Supabase Studio's SQL Editor, paste the following query, and click Run. Then check the table and policy as described above.
create table public.user_notes (
id uuid default gen_random_uuid() primary key,
owner_id uuid not null,
note text not null
);
alter table public.user_notes enable row level security;
grant select, insert, update, delete on public.user_notes to authenticated;
create policy own_notes on public.user_notes
for all to authenticated
using (auth.uid() = owner_id)
with check (auth.uid() = owner_id);Create the notes application with Lares
The command-line application signs users in, adds notes, and lists their notes from Supabase's user_notes table.
Ask Lares to generate the program and its configuration files:
textHelp me connect a private notes app to Supabase. Use supabase_official to inspect user_notes and its RLS policy, and get the API URL and anon key. Create notes.mjs using @supabase/supabase-js v2 and Node.js 22. Read SUPABASE_URL, SUPABASE_ANON_KEY, NOTES_EMAIL, and NOTES_PASSWORD from process.env. I will load .env with node --env-file=.env. Sign in with signInWithPassword and support these commands: - whoami: show the signed-in user's email and ID, never session tokens - add "text": insert into user_notes with owner_id set to that user's ID, then show the saved note and its ID - list: select id and note from user_notes, relying on RLS for isolation Report SDK errors and exit after each command. Save notes.mjs, .env, .env.example, and .gitignore directly in your workspace root, not in a subfolder. Fill .env with the API URL and anon key. Leave NOTES_EMAIL and NOTES_PASSWORD empty, and ignore .env and node_modules/ in Git. Use placeholders in .env.example. Keep passwords out of the conversation and source code. Tell me the exact file location. Do not create Auth users, change the schema or policies, or run the app. Stop after preparing the files.Lares prepares four files for the same application:
File Purpose notes.mjsThe program you run. It signs in to Supabase, adds notes, and lists the signed-in user's notes. .envThe configuration used when running the program. Lares fills in the API URL and anonkey. You will add your Supabase Auth user's email and password..env.exampleA configuration template with placeholders, for reference or setting up another copy of the application. .gitignoreTells Git to exclude .envand thenode_modulesdependency folder from version control.Open Olares Files, go to Data > lares > data > workspace, and copy
notes.mjs,.env,.env.example, and.gitignore.In Olares Files, go to Home > Code, create a folder named
notes-app, and paste all four files into it. Code Server can access this folder.
Create a user account for the notes application
Create a user account in Supabase to sign in to the notes application. This account is separate from your Olares account.
- Open Supabase Studio and go to Authentication > Users > Add user > Create new user.
- Enter an email such as
demo@example.comand a password of your own. Keep Auto confirm user? enabled, then click Create user. Auto confirmation lets you sign in for this example without receiving a confirmation email.
Run the notes application in Code Server
Open Code Server from the Launchpad.
Use File > Open Folder to open
/home/coder/notes-app, which corresponds to Home > Code > notes-app in Olares Files.If prompted, confirm that you trust the folder. Check that
notes.mjsand.envappear in the Explorer.Open Terminal > New Terminal.
Run
node -vto check the installed Node.js version. This example uses Node.js 22.If Node.js is missing or older than version 22, run the following four commands in order to install it with nvm:
bashtouch "$HOME/.bashrc" curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash . "$HOME/.nvm/nvm.sh" nvm install 22Run
npm -vto confirm that npm displays a version number. If you installed Node.js in the previous step, also runnode -vagain and check that it showsv22.x.x.In the Code Server terminal, switch to the project folder and install the Supabase JavaScript SDK:
bashcd /home/coder/notes-app npm install @supabase/supabase-js@2.118.0Open
.envin Code Server. LeaveSUPABASE_URLandSUPABASE_ANON_KEYunchanged. SetNOTES_EMAILandNOTES_PASSWORDto the email and password of the notes application account you created, then save the file:dotenvNOTES_EMAIL="your-email@example.com" NOTES_PASSWORD="your-password"Keep your password private
Store the password in
.env. Do not paste it into the Lares conversation or include it innotes.mjs.Alternative: copy the connection details from Supabase Studio and Olares Settings
Open Olares Settings, and go to Applications > Supabase > Supabase API. Copy its Endpoint into
SUPABASE_URLin.env, without/rest/v1or/api/mcp.In Supabase Studio, open Project Settings > API Keys > Legacy anon, service_role API keys, and copy the
anonkey intoSUPABASE_ANON_KEY. Do not useservice_role: it bypasses RLS and allows access to other users’ notes.In the same terminal, run the following commands to sign in, add a note, and read it back. The
--env-file=.envoption loads the connection settings and user credentials from.env:bashnode --env-file=.env notes.mjs whoami node --env-file=.env notes.mjs add "Ask the Lakeview contractor to confirm the delivery window." node --env-file=.env notes.mjs listThe terminal shows the signed-in user, the new note's ID, and the saved note. Each
addcommand creates a new row.
Check that users can only access their own notes
In Supabase Studio, repeat Create a user account for the notes application with a different email, such as
demo2@example.com, and a separate password.In Code Server, open
.envand updateNOTES_EMAILandNOTES_PASSWORDwith the second user's email and password. LeaveSUPABASE_URLandSUPABASE_ANON_KEYunchanged, then save the file.Run the following commands:
bashnode --env-file=.env notes.mjs whoami node --env-file=.env notes.mjs listThe signed-in user should now be the second user. This new user's list should be empty, even though the first user's note is still in the database.
Add a note for the second user, then list their notes:
bashnode --env-file=.env notes.mjs add "Compare the Riverside flooring quotes." node --env-file=.env notes.mjs listThe list should contain the Riverside note and exclude the first user's Lakeview note.
Restore the first user's email and password in
.env, save the file, and runnode --env-file=.env notes.mjs listagain. You should see their Lakeview note without the Riverside note.
Query Supabase data with Metabase
Metabase connects directly to PostgreSQL to query project costs. Lares creates the sample data through Supabase MCP, and you configure the database connection and run the report queries in Metabase.
Complete the initial Metabase setup
If this is your first time opening Metabase, complete its setup wizard before adding the Supabase connection:
- Open Metabase and click Let's get started.
- Enter your name, email, team name, and a password for your Metabase administrator account. Click Next and answer the usage question.
- At Add your data, click Continue with sample data to continue setup without connecting Supabase yet. You will add the Supabase connection in Connect Metabase to Supabase.
- Choose your usage data preference, click Finish, then click Take me to Metabase.
Collect the database connection details
For Metabase, collect the Supabase database host, exported session port, and database password. This connection uses the database username postgres.supabase.
Get the database host and port
Open Olares Settings, and go to Applications > Supabase > Permissions > Exported ports >
postgres-session. Note down the Exported port.On your computer, install Olares CLI and log in to your Olares instance if you have not already done so. In your computer's terminal, run:
basholares-cli settings apps get supabaseNote down the top-level URL from the command output as the database host, without
https://or a path.In the Ports list, check that the EXPOSE value for
postgres-sessionmatches the exported port you noted down in step 1. Use this port in Metabase.
Get the database password
In Control Hub, go to Browse > supabase-{user-name} > Deployments > db, open its pod, and then open the db container's terminal.
Run the following commands to display the database password:
sh. /runtime/keys.env printf '%s\n' "$POSTGRES_PASSWORD"Keep this terminal available. You will copy the password into Metabase when adding the connection. Do not paste it into the Lares conversation.
Create the project costs table with Lares
In Lares, send the following prompt to create
project_costswith three fictional renovation costs. Theamountvalues in this example are in US dollars.textUse supabase_official to inspect the public schema and prepare a table. project_costs: id integer primary key, project text not null, amount integer not null. Enable RLS on the table. Do not add anonymous access policies. Insert these fictional rows: 1, Lakeview, 100 2, Riverside, 200 3, Maple, 300 Use a migration for the schema and execute_sql for the sample rows. Show the proposed changes first. Preserve existing data and avoid duplicate rows.Review the proposed changes and confirm them in Lares.
When a tool call shows Waiting for approval, inspect its SQL and click Allow once for the intended operation. Repeat as needed for the migration, sample inserts, and verification queries.
Wait for Lares to finish, then open Table Editor in Supabase Studio and select
project_costs. Check that it contains the three rows from the prompt.
Alternative: prepare the table in SQL Editor
If you have not created project_costs with Lares, run the following query in Supabase Studio's SQL Editor.
create table public.project_costs (
id integer primary key,
project text not null,
amount integer not null
);
alter table public.project_costs enable row level security;
insert into public.project_costs values
(1, 'Lakeview', 100),
(2, 'Riverside', 200),
(3, 'Maple', 300);Connect Metabase to Supabase
In Metabase, open the Settings menu in the top-right corner and select Admin. Go to Databases > Add database.
Choose PostgreSQL, and enter:
Field Value Display name Home project costsHost The top-level URL collected in step 3 of Get the database host and port, without https://Port The Exported port collected in step 1 of Get the database host and port Database name postgresUsername postgres.supabasePassword The POSTGRES_PASSWORDfrom Get the database passwordUse a secure connection (SSL) Off for this package's LAN connection Database administrator access
This connection gives Metabase administrator-level access to Supabase, including access to
project_costswithout an RLS read policy. Only use these credentials in a Metabase instance you control.Click Save.
On the Home project costs database page, check that Connection and sync shows Connected.
Query project costs in Metabase
Open the Settings menu in the top-right corner and select Main app.
In the top right, click New > SQL query. Check the database selector above the SQL editor and select
Home project costsif it is not already selected.Paste the following query into the SQL editor, then click the run button to list the sample project costs:
sqlselect project, amount from public.project_costs order by id;The query returns a table with the
projectandamountcolumns and three rows:Lakeview100,Riverside200, andMaple300.Replace the SQL in the editor with the following query, then click the run button again to calculate the total:
sqlselect count(*) as records, sum(amount) as total_usd from public.project_costs;The query returns one row showing 3 records and a total of 600.
Troubleshooting
| Symptom | What to check |
|---|---|
| Lares cannot connect to MCP | Use the Supabase Studio HTTPS URL ending in /api/mcp with Streamable HTTP transport. Keep the Supabase Studio entrance set to Internal. |
Code Server cannot find notes.mjs or .env | Check that both files are in Home > Code > notes-app in Olares Files, then run the commands from /home/coder/notes-app in Code Server |
The terminal reports node: command not found | Run . "$HOME/.nvm/nvm.sh", then nvm use 22 in the same terminal. Check node -v before running the application again. If nvm or Node.js 22 is not installed, follow the installation steps in Run the notes application in Code Server. |
node -v reports a missing libatomic.so.1 | In the Code Server terminal, run sudo apt-get install -y libatomic1, then check node -v again |
| The notes application returns an empty list | An empty list is expected if the signed-in user has not added any notes. If notes are missing, run node --env-file=.env notes.mjs whoami to check the user, then check that the notes' owner_id matches that user's ID and that the RLS policy matches Create the notes table and access policy with Lares. |
| Metabase cannot connect | Check the database host and the exported postgres-session port from Get the database host and port. Confirm that Metabase can reach that host and port. Use postgres.supabase as the username and the password from Get the database password. |
Learn more
- Manage Olares with Lares: Select a model and start a conversation.
- Enable the self-hosted Supabase MCP server: Understand the upstream server's network access requirements.