Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

feat(db): add mcp_client_grants for approved Claude clients

spacesdrive1e4ff1feca85
diff --git a/supabase/migrations/20261104212724_create_mcp_client_grants.sql b/supabase/migrations/20261104212724_create_mcp_client_grants.sql
new file mode 100644
index 0000000..94db671
--- /dev/null
+++ b/supabase/migrations/20261104212724_create_mcp_client_grants.sql
@@ -0,0 +1,15 @@
+-- creates mcp_client_grants, which records what each Claude client a person approved may do for them
+create table public.mcp_client_grants (
+ id text primary key,
+ user_id uuid not null references auth.users (id) on delete cascade,
+ -- the OAuth client id Supabase Auth issued to the Claude client
+ client_id text not null,
+ client_name text not null,
+ permission text not null,
+ last_used_at timestamptz,
+ created_at timestamptz not null default now(),
+ updated_at timestamptz not null default now(),
+ constraint mcp_client_grants_user_client_key unique (user_id, client_id),
+ constraint mcp_client_grants_permission_check check (permission in ('read', 'write')),
+ constraint mcp_client_grants_client_name_check check (char_length(client_name) between 1 and 200)
+);
diff --git a/supabase/migrations/20261104212733_revoke_browser_access_mcp_client_grants.sql b/supabase/migrations/20261104212733_revoke_browser_access_mcp_client_grants.sql
new file mode 100644
index 0000000..ef10e51
--- /dev/null
+++ b/supabase/migrations/20261104212733_revoke_browser_access_mcp_client_grants.sql
@@ -0,0 +1,3 @@
+-- turns on row level security and removes browser access to mcp_client_grants
+alter table public.mcp_client_grants enable row level security;
+revoke all on table public.mcp_client_grants from anon, authenticated;
diff --git a/supabase/migrations/20261104212741_add_mcp_client_grants_updated_at_trigger.sql b/supabase/migrations/20261104212741_add_mcp_client_grants_updated_at_trigger.sql
new file mode 100644
index 0000000..e0ae2d7
--- /dev/null
+++ b/supabase/migrations/20261104212741_add_mcp_client_grants_updated_at_trigger.sql
@@ -0,0 +1,3 @@
+-- adds the trigger that keeps updated_at current on mcp_client_grants
+create trigger mcp_client_grants_set_updated_at before update on public.mcp_client_grants
+ for each row execute function public.set_updated_at();
diff --git a/supabase/migrations/20261104212750_index_mcp_client_grants_user_created.sql b/supabase/migrations/20261104212750_index_mcp_client_grants_user_created.sql
new file mode 100644
index 0000000..a46c884
--- /dev/null
+++ b/supabase/migrations/20261104212750_index_mcp_client_grants_user_created.sql
@@ -0,0 +1,2 @@
+-- adds an index that lists the Claude clients a person approved, newest first
+create index mcp_client_grants_user_created_idx on public.mcp_client_grants (user_id, created_at desc);
diff --git a/supabase/rollbacks/20261104212724_create_mcp_client_grants.sql b/supabase/rollbacks/20261104212724_create_mcp_client_grants.sql
new file mode 100644
index 0000000..1fe7bd5
--- /dev/null
+++ b/supabase/rollbacks/20261104212724_create_mcp_client_grants.sql
@@ -0,0 +1,2 @@
+-- removes mcp_client_grants, which stops every Claude client signed in with OAuth until it is approved again
+drop table if exists public.mcp_client_grants;
diff --git a/supabase/rollbacks/20261104212733_revoke_browser_access_mcp_client_grants.sql b/supabase/rollbacks/20261104212733_revoke_browser_access_mcp_client_grants.sql
new file mode 100644
index 0000000..a514c1f
--- /dev/null
+++ b/supabase/rollbacks/20261104212733_revoke_browser_access_mcp_client_grants.sql
@@ -0,0 +1,2 @@
+-- turns row level security off on mcp_client_grants; it had no browser grants to give back
+alter table public.mcp_client_grants disable row level security;
diff --git a/supabase/rollbacks/20261104212741_add_mcp_client_grants_updated_at_trigger.sql b/supabase/rollbacks/20261104212741_add_mcp_client_grants_updated_at_trigger.sql
new file mode 100644
index 0000000..e2a0c7e
--- /dev/null
+++ b/supabase/rollbacks/20261104212741_add_mcp_client_grants_updated_at_trigger.sql
@@ -0,0 +1,2 @@
+-- removes the trigger that keeps updated_at current on mcp_client_grants
+drop trigger if exists mcp_client_grants_set_updated_at on public.mcp_client_grants;
diff --git a/supabase/rollbacks/20261104212750_index_mcp_client_grants_user_created.sql b/supabase/rollbacks/20261104212750_index_mcp_client_grants_user_created.sql
new file mode 100644
index 0000000..511fea1
--- /dev/null
+++ b/supabase/rollbacks/20261104212750_index_mcp_client_grants_user_created.sql
@@ -0,0 +1,2 @@
+-- removes the index that lists the Claude clients a person approved
+drop index if exists public.mcp_client_grants_user_created_idx;
diff --git a/supabase/schemas/public/tables/mcp_client_grants.sql b/supabase/schemas/public/tables/mcp_client_grants.sql
new file mode 100644
index 0000000..5baf89d
--- /dev/null
+++ b/supabase/schemas/public/tables/mcp_client_grants.sql
@@ -0,0 +1,33 @@
+CREATE TABLE "public"."mcp_client_grants" (
+ "id" text NOT NULL,
+ "user_id" uuid NOT NULL,
+ "client_id" text NOT NULL,
+ "client_name" text NOT NULL,
+ "permission" text NOT NULL,
+ "last_used_at" timestamp with time zone,
+ "created_at" timestamp with time zone NOT NULL DEFAULT now(),
+ "updated_at" timestamp with time zone NOT NULL DEFAULT now(),
+ CONSTRAINT "mcp_client_grants_client_name_check" CHECK (((char_length(client_name) >= 1) AND (char_length(client_name) <= 200))),
+ CONSTRAINT "mcp_client_grants_permission_check" CHECK ((permission = ANY (ARRAY['read'::text, 'write'::text]))),
+ CONSTRAINT "mcp_client_grants_pkey" PRIMARY KEY (id),
+ CONSTRAINT "mcp_client_grants_user_client_key" UNIQUE (user_id, client_id),
+ CONSTRAINT "mcp_client_grants_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE
+);
+
+ALTER TABLE "public"."mcp_client_grants"
+ ENABLE ROW LEVEL SECURITY;
+
+CREATE INDEX mcp_client_grants_user_created_idx ON public.mcp_client_grants USING btree (user_id, created_at DESC);
+
+CREATE TRIGGER mcp_client_grants_set_updated_at
+ BEFORE UPDATE ON public.mcp_client_grants
+ FOR EACH ROW
+ EXECUTE FUNCTION public.set_updated_at();
+
+GRANT DELETE, INSERT, MAINTAIN, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON TABLE "public"."mcp_client_grants" TO "service_role";
+
+REVOKE ALL ON TABLE "public"."mcp_client_grants" FROM "postgres";
+
+GRANT DELETE, INSERT, MAINTAIN, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON TABLE "public"."mcp_client_grants" TO "postgres";
+
+REVOKE ALL ON TABLE "public"."mcp_client_grants" FROM "anon", "authenticated";