caelum0x e2b16cffd0 feat: Scribase plugin for Grok Build
MCP server (api.scribase.com) plus the scribase skills for creating a
project, adding auth/storage, writing a safe RLS policy, branch-per-PR
and the preview-branch-and-confirm workflow. Content ported as-is from
the live Scribase agents plugin (rithub.dev/scribase/scribase-agents),
packaged with a .grok-plugin/plugin.json manifest for Grok Build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 23:28:11 +03:00

3.2 KiB

name, description
name description
scribase-add-storage Add file storage to a Scribase project — create a bucket and write row-level-security policies for uploads, avatars, or any user-owned files, then upload and read them back with signed URLs. Use when the user asks to add file upload, storage, buckets, avatars, attachments, images, or object storage to a Scribase or Supabase-compatible app.

Scribase: file storage

Storage speaks the same /storage/v1 API as Supabase, so the app uses supabase.storage.* unchanged. Access is decided by row level security on storage.objects — a bucket with no policy is unreadable and unwritable by anon/authenticated, which is the safe default.

1. Create the bucket

MCP (fastest, from the chat session): call storage_buckets_create with name (required) and public: true only if the user actually wants files served by a public URL with no auth check — default to private. Optional file_size_limit (bytes) and allowed_mime_types (e.g. ["image/png", "image/*"]) cut down what a bad actor can upload. List what already exists with storage_buckets_list before creating a duplicate.

{ "name": "avatars", "public": false, "allowed_mime_types": ["image/*"], "file_size_limit": 5242880 }

Prefer this for a bucket the user wants right now, in a preview or on their own project. For anything shipping to production, do it as a migration instead (below) so the bucket and its policies are versioned and repeatable.

2. Policies: scope by the uploader's own folder

Convention: the first path segment is the owner's user id, so one policy covers every file under it.

-- 003_avatars.sql
insert into storage.buckets (id, name, public) values ('avatars', 'avatars', false)
  on conflict (id) do nothing;

create policy "avatars: owner reads" on storage.objects for select to authenticated
  using (bucket_id = 'avatars' and (storage.foldername(name))[1] = (select auth.uid())::text);
create policy "avatars: owner writes" on storage.objects for insert to authenticated
  with check (bucket_id = 'avatars' and (storage.foldername(name))[1] = (select auth.uid())::text);

Add for update/for delete the same way only if the user actually needs to replace or remove their own files; do not grant more than asked. Apply with migrate_run (see the general scribase skill) or scribase migrate --dir supabase/migrations --apply. See scribase-write-rls-policy for the policy-writing rules this storage policy also follows (one policy per command, index what a policy filters on, never using (true) on a private bucket).

3. Upload and read from the app

const { data: { user } } = await supabase.auth.getUser()
const path = `${user!.id}/avatar.png`
await supabase.storage.from('avatars').upload(path, file, { upsert: true, contentType: 'image/png' })

// Private bucket: a short-lived signed URL
const { data } = await supabase.storage.from('avatars').createSignedUrl(path, 60 * 60)

// Public bucket only (public: true at creation)
const { data: pub } = supabase.storage.from('avatars').getPublicUrl(path)

4. Report back

Say which bucket was created, whether it is public or private, exactly which policies exist and who they let read/write, and the upload path convention the app should follow ({user_id}/...).