opencode-supabase 0.2.2 → 0.2.3-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,9 +26,32 @@ Connect your account and ask your agent about Supabase capabilities.
26
26
 
27
27
  - `supabase`
28
28
  - `supabase-postgres-best-practices`
29
+ - `opencode-supabase-guide`
29
30
 
30
31
  No separate `skills` CLI setup is required. Installing the plugin makes these skills available to OpenCode through the plugin server config hook.
31
32
 
33
+ ## Supabase MCP Onboarding
34
+
35
+ Ask your agent:
36
+
37
+ ```text
38
+ Set up Supabase MCP for my project
39
+ ```
40
+
41
+ The agent can explain Supabase MCP, help you choose the target project, and open the Supabase Studio Connect Sheet with the MCP tab and OpenCode client selected.
42
+
43
+ Studio remains the source of truth for MCP feature groups, permissions, generated OpenCode config, and auth steps. If you want help applying the Studio output to this repository, paste the Studio prompt or OpenCode config snippet back into OpenCode.
44
+
45
+ You can skip any Studio instruction to install Supabase Agent Skills separately. This plugin already bundles Supabase skills.
46
+
47
+ After changing OpenCode MCP config, restart OpenCode. If OAuth is not prompted automatically, run:
48
+
49
+ ```bash
50
+ opencode mcp auth supabase
51
+ ```
52
+
53
+ This plugin opens the MCP setup page and guides the workflow. It does not automatically edit MCP config or choose read-only/feature-group settings for you.
54
+
32
55
  ### Disable Bundled Skills
33
56
 
34
57
  If you want Supabase tools without bundled skills, disable them in plugin options:
@@ -65,7 +88,7 @@ Bundled skills are vendored as real files under `skills/` from `supabase/agent-s
65
88
  bun run skills:sync
66
89
  # or: bun run skills:sync <commit-sha-or-ref>
67
90
  bun run typecheck
68
- bun test
91
+ bun run test
69
92
  bun run verify:pack
70
93
  ```
71
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-supabase",
3
- "version": "0.2.2",
3
+ "version": "0.2.3-alpha.0",
4
4
  "type": "module",
5
5
  "description": "OpenCode plugin for Supabase integration with server and TUI components",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,52 @@
1
+ ---
2
+ name: opencode-supabase-guide
3
+ description: Use when users ask to set up Supabase MCP in OpenCode, paste Supabase Studio MCP config, or need MCP tools connected.
4
+ ---
5
+
6
+ # OpenCode Supabase Guide
7
+
8
+ ## Question Tool Rule
9
+
10
+ Every interactive choice MUST use `question` tool. Never assume, never auto-pick. This includes:
11
+
12
+ - Selecting a project when multiple exist — list options with name + ref in the question.
13
+ - Confirming before opening browser — include project name + ref in the question.
14
+ - Choosing whether to apply Studio config to the repo.
15
+ - Any yes/no or selection prompt.
16
+
17
+ No prose "ask" — always `question` tool invocation.
18
+
19
+ ## Overview
20
+
21
+ Supabase MCP adds project-scoped Supabase tools to OpenCode. Before MCP setup, tell user to run `/supabase` to connect their account — plugin tools (list projects, create project) need OAuth. MCP config comes from Studio prompt, not rebuilt from code.
22
+
23
+ ## MCP Setup Flow
24
+
25
+ 1. Resolve project with `supabase_list_projects`. If auth fails, tell user: "Run `/supabase` to connect your Supabase account." If multiple projects, use `question` tool listing name + ref for each.
26
+ 2. Use `question` tool to confirm: "Open Supabase MCP Connect for `<name>` (`<ref>`)?"
27
+ 3. Call `supabase_open_mcp_setup`. Always print returned URL in output.
28
+ 4. Tell user to paste Studio prompt/config back for wiring into `opencode.json`.
29
+
30
+ ## Studio Prompt Handling
31
+
32
+ Extract MCP JSON from Studio prompt. Strip line numbers (`1{`). Preserve URLs exactly — never rebuild from `project_ref`. MCP server key usually `supabase`; auth: `opencode mcp auth supabase`. Skip `npx skills add supabase/agent-skills` — already bundled.
33
+
34
+ ## Config Rules
35
+
36
+ Prefer repo-root `opencode.json` (or `.jsonc`). Global (`~/.config/opencode/opencode.json`) only on explicit request. Use `question` tool before editing. Remind to restart OpenCode.
37
+
38
+ ## Common Mistakes
39
+
40
+ | Mistake | Fix |
41
+ | --------------------------------------- | ---------------------------------------- |
42
+ | Rebuilding/normalizing Studio URLs | Preserve pasted URLs exactly |
43
+ | Omitting setup URL from output | Always print exact returned URL |
44
+ | Installing separate Agent Skills | Already bundled in this plugin |
45
+ | Writing global config by default | Prefer repo-root `opencode.json` |
46
+ | Choosing MCP features for user | Studio decides read-only, feature groups |
47
+ | Calling MCP setup while unauthenticated | Tell user to run `/supabase` first |
48
+ | Asking user without `question` tool | Always use `question` tool for confirmations, project selection, any interactive choice |
49
+
50
+ ## Troubleshooting
51
+
52
+ MCP tools missing after config? Restart OpenCode, run `opencode mcp auth supabase`.
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
5
5
  export const BUNDLED_SUPABASE_SKILLS = [
6
6
  "supabase",
7
7
  "supabase-postgres-best-practices",
8
+ "opencode-supabase-guide",
8
9
  ] as const;
9
10
 
10
11
  export type BundledSupabaseSkill = (typeof BUNDLED_SUPABASE_SKILLS)[number];
@@ -1,6 +1,7 @@
1
1
  import type { PluginOptions } from "@opencode-ai/plugin";
2
2
  import { tool } from "@opencode-ai/plugin";
3
3
  import type { ToolContext } from "@opencode-ai/plugin/tool";
4
+ import open from "open";
4
5
 
5
6
  import { supabaseManagementApiFetch } from "../shared/api.ts";
6
7
  import {
@@ -23,6 +24,7 @@ type ToolDeps = {
23
24
  fetch?: FetchLike;
24
25
  logger?: SupabaseLogger;
25
26
  now?: () => Date;
27
+ open?: (target: string) => Promise<unknown>;
26
28
  };
27
29
 
28
30
  type InFlightRefresh = {
@@ -421,6 +423,28 @@ export async function ensureSupabaseToolAuth(
421
423
  return refreshEntry.promise;
422
424
  }
423
425
 
426
+ function createMcpSetupUrl(projectRef: string) {
427
+ const url = new URL(`https://supabase.com/dashboard/project/${encodeURIComponent(projectRef)}`);
428
+ url.searchParams.set("showConnect", "true");
429
+ url.searchParams.set("connectTab", "mcp");
430
+ url.searchParams.set("mcpClient", "opencode");
431
+ return url.toString();
432
+ }
433
+
434
+ function formatMcpSetupResult(projectRef: string, url: string) {
435
+ return `Opened Supabase MCP setup for project ${projectRef} in Studio.
436
+
437
+ URL: ${url}
438
+
439
+ On the Connect page:
440
+ 1. Confirm MCP tab and OpenCode client are selected.
441
+ 2. Choose the feature groups and permissions you want in Studio.
442
+ 3. Follow the OpenCode config and auth steps shown by Studio.
443
+ 4. If you want me to wire this into the current repo, paste the Studio prompt or OpenCode config snippet back here.
444
+ 5. You can skip any "install Supabase Agent Skills" step because this plugin already bundles them.
445
+ 6. Restart OpenCode after changing config; run \`opencode mcp auth supabase\` if OAuth is not prompted automatically.`;
446
+ }
447
+
424
448
  export function createSupabaseTools(
425
449
  input: SupabaseToolInput,
426
450
  options?: PluginOptions,
@@ -525,6 +549,26 @@ export function createSupabaseTools(
525
549
  );
526
550
  },
527
551
  }),
552
+ supabase_open_mcp_setup: tool({
553
+ description:
554
+ "Open Supabase Studio MCP Connect page for a project after the user confirms the project. Use when the user asks to set up, connect, configure, or use Supabase MCP in OpenCode. Before calling, explain MCP briefly and ask: Open Supabase MCP Connect page for <project name> (<project-ref>)?",
555
+ args: {
556
+ project_ref: tool.schema.string().describe("Supabase project reference ID"),
557
+ },
558
+ async execute(args, _context: SupabaseToolContext) {
559
+ await ensureSupabaseToolAuth(input, options, deps);
560
+ const url = createMcpSetupUrl(args.project_ref);
561
+ const openBrowser = deps.open ?? open;
562
+ await openBrowser(url);
563
+ await deps.logger?.info("supabase mcp setup opened", {
564
+ tool: "supabase_open_mcp_setup",
565
+ sessionID: _context.sessionID,
566
+ messageID: _context.messageID,
567
+ agent: _context.agent,
568
+ });
569
+ return formatMcpSetupResult(args.project_ref, url);
570
+ },
571
+ }),
528
572
  supabase_login: tool({
529
573
  description: "Explain how to connect Supabase in the TUI.",
530
574
  args: {},
@@ -22,14 +22,16 @@ type SupabaseDialogProps = {
22
22
 
23
23
  const ONBOARDING_MESSAGE = `Supabase is connected.
24
24
 
25
- You can ask me about:
25
+ Now unlock project-scoped tools with Supabase MCP — ask me to set it up to get database inspection, docs, advisors, and more for your project in OpenCode.
26
+
27
+ You can also ask about:
26
28
  - your organizations and projects
27
29
  - API keys for a project
28
30
  - available database regions
29
31
  - creating a new project
30
32
 
31
33
  Try this:
32
- list my Supabase projects`;
34
+ Set up Supabase MCP for my project`;
33
35
 
34
36
  const onboardedSessionIDsByApi = new WeakMap<TuiPluginApi, Set<string>>();
35
37