---
name: chumbo
description: Turn existing Supabase applications into end-user-facing Streamable HTTP MCP servers. Use for installing, configuring, developing, debugging, testing, deploying, or upgrading the chumbo package, including when a user asks generically to add MCP capabilities to a Supabase app, a Next.js application, or a Node service on Cloud Run or similar hosts. Covers tools, Resources, prompts, MCP Apps, authentication, RLS, host targets, and result design.
---

# Build MCP servers for Supabase apps

Chumbo is a TypeScript runtime and CLI that adds MCP to an existing Supabase
application. `npx chumbo setup` generates a Supabase Edge Function that handles
Streamable HTTP, authentication, and per-request context; `--target next`
generates the same MCP as a Next.js App Router route handler and
`--target node` as a standalone Node server, with the Supabase project
remaining the identity and data plane. The builder edits one file,
`capabilities.ts`, to expose application operations as ordinary MCP tools,
Resources, and prompts. Server metadata and request-aware instructions are
configured through `createSupabaseMcp` in the generated entrypoint when
needed.

```text
MCP client
  -> supabase/functions/mcp/index.ts          protocol, auth, server configuration
  -> supabase/functions/mcp/capabilities.ts   application operations
  -> existing APIs, Postgres, Storage, grants, and RLS
```

In OAuth and bearer modes, `ctx.supabase` is a fresh client carrying the
connected user's access token. Existing Postgres grants and RLS policies keep
the same authority they have in the rest of the application. No hosted Chumbo
service is required.

## Choose your course

| You need to                                                         | Read                                                               |
| ------------------------------------------------------------------- | ------------------------------------------------------------------ |
| Add MCP to a Supabase, Next.js, or Node repository, or resume setup | [Start or resume](references/start.md)                             |
| Design or revise a tool, Resource, or prompt                        | [Build capabilities](references/build-capabilities.md)             |
| Choose OAuth, bearer, API-key, or public access                     | [Access and RLS](references/access-and-rls.md)                     |
| Choose model-facing text, structured data, a hybrid, or a Resource  | [Design results](references/results.md)                            |
| Run locally, deploy, connect a client, or prove completion          | [Run, deploy, and verify](references/run-deploy-verify.md)         |
| Diagnose connection, auth, discovery, RLS, or version problems      | [Troubleshoot and upgrade](references/troubleshoot-and-upgrade.md) |

Read only the guide needed for the current course. Optional state, telemetry,
run correlation, MCP Apps, multi-auth, many-server composition, Cloud, and
Durable are collected under [advanced patterns](references/advanced-patterns.md).

## Ordinary path: one app, one Edge Function

### 1. Generate the server

From a repository containing `supabase/config.toml`:

```sh
npx chumbo setup
npx chumbo skill install
```

Setup previews its writes, asks who may connect, generates the function and
contract test, and reports the remaining steps. Installing the project-local
skill gives later agent sessions version-matched guidance. Setup is resumable
and does not overwrite builder-authored `capabilities.ts`.

### 2. Replace the starter with one real operation

The generated `whoami` tool is a diagnostic starter. Replace it with a
capability from the application rather than exposing database mechanics, then
update `index_test.ts` to discover and invoke the replacement. For example:

```ts
import {
  collectionInputSchema,
  collectionResult,
  type SupabaseMcpContext,
  type SupabaseMcpServer,
} from "chumbo";
import { z } from "zod";

export function registerCapabilities(
  server: SupabaseMcpServer,
  ctx: SupabaseMcpContext,
) {
  const taskSummary = z.object({
    id: z.string().uuid(),
    title: z.string(),
    status: z.string(),
  });
  server.registerTool(
    "list_tasks",
    {
      description:
        "Browse tasks visible to the connected user in stable ID order.",
      inputSchema: collectionInputSchema({ cursorSchema: z.string().uuid() }),
    },
    async ({ limit, cursor }) => {
      let query = ctx.supabase
        .from("tasks")
        .select("id, title, status")
        .order("id")
        .limit(limit + 1);
      if (cursor) query = query.gt("id", cursor);
      const { data, error } = await query;
      if (error) throw error;
      return collectionResult({
        items: data ?? [],
        limit,
        hasMore: false,
        itemSchema: taskSummary,
        project: ({ id, title, status }) => ({ id, title, status }),
        cursorFor: ({ id }) => id,
        tool: "list_tasks",
        arguments: cursor ? { cursor } : {},
        render: ({ items }) =>
          items.length
            ? items
                .map((task) => `- ${task.title} – ${task.status} (${task.id})`)
                .join("\n")
            : "No tasks are visible to the connected user.",
      });
    },
  );
}
```

The tool describes a user-visible operation. Identity comes from `ctx`; it is
not accepted as a tool argument. For collection/detail contracts, overflow recovery,
and consistency choices, read [Design results](references/results.md).

### 3. Run the local proof loop

Use separate terminals because the server command streams until stopped:

```sh
supabase start
npx chumbo dev --function mcp
deno task --config supabase/functions/mcp/deno.json test
npx chumbo doctor \
  --function mcp \
  --url http://127.0.0.1:API_PORT/functions/v1/mcp \
  --call-tool <SAFE_TOOL>
```

Use the exact Local MCP URL printed by `chumbo dev`; `API_PORT` follows the
project's configured Supabase API port. Supply `--token` when the selected
access mode requires one. Public mode requires the generated local rate-limit
migration first. Generated tests
prove the mode-specific scaffold contract: API-key mode invokes the starter,
OAuth and bearer modes prove their unauthenticated rejection, and public mode
proves the fetch handler boots. Separately discover and invoke one real
application capability with an appropriate identity.

### 4. Deploy and connect

```sh
supabase functions deploy mcp --no-verify-jwt
npx chumbo doctor \
  --function mcp \
  --url https://PROJECT_REF.supabase.co/functions/v1/mcp

claude mcp add --transport http my-app \
  https://PROJECT_REF.supabase.co/functions/v1/mcp
```

The command above fits OAuth or public mode. API-key and bearer clients must
send their credential:

```sh
claude mcp add --transport http my-app \
  https://PROJECT_REF.supabase.co/functions/v1/mcp \
  --header "Authorization: Bearer <credential>"
```

Keep live credentials out of committed project configuration, logs, and copied
diagnostic output.

The generated function disables the Supabase gateway JWT check because the
function owns the MCP authentication challenge. Protected modes still verify
every credential inside the runtime.

## Choose who connects

| Mode    | Use it when                                                            | Handler authority                                                   |
| ------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------- |
| OAuth   | End users connect their own accounts                                   | Supabase user token and existing RLS                                |
| Bearer  | An application-controlled client already holds a Supabase access token | Supabase user token and existing RLS                                |
| API key | A trusted machine or application-owned principal connects              | Verified subject and scopes; `ctx.supabase` uses the anonymous role |
| Public  | The capability is intentionally anonymous                              | Anonymous role plus the generated Postgres rate limiter             |

OAuth is the ordinary choice for a user-facing product. API key is the shortest
authenticated start for a prototype or trusted machine caller.

## Rules that matter on every path

- Keep application behavior in `capabilities.ts`; let the generated entrypoint
  own protocol and authentication plumbing.
- Model application operations, not tables. Reuse existing RPCs, APIs, grants,
  and RLS instead of creating a parallel backend.
- Derive caller identity and authority from the verified request context, not
  from model-supplied identity, role, or scope fields.
- Choose each result for its actual consumer. Do not mirror raw rows or
  duplicate large values into text and structured output by default.
- Preserve builder-authored files when resuming setup or upgrading.
- Treat compilation as the first check, not completion. Exercise the real MCP
  transport and the relevant positive and negative authority cases.

## Advanced usage

Ignore these paths unless the application has the corresponding need:

- composing onto an existing official `@supabase/server` MCP function with `chumbo/middleware` (`withChumbo`, `chumboMcpHandler`, `withMcpCors`, `withMcpTransportArmor`);
- multiple auth strategies, declarative capability profiles (`defineProfiles`, `withProfile`, `projectInputFields`, `scopedGuidance`), or canonical vocabulary resolution (`resolveCanonicalVocabulary`);
- credential- or session-partitioned coordination state (`ctx.state`, `ctx.sessionState`, `observeResource`/`requireObserved`, `mintPreview`/`consumePreview`, `registerUseWorkspace`);
- lifecycle events, self-hosted Insights (`chumbo/insights`), advertised-surface lockfiles (`chumbo surface snapshot|diff`), or application-run correlation (`ctx.run`, `withRunInput`);
- turnkey MCP Apps (`defineMcpApp`, `registerMcpApp`, `callAppTool`, `chumbo app add|build`, `chumbo dev --workbench --app`), project-branded CLIs (`chumbo cli init|render|try`), or end-user connection flows (`chumbo/connect`);
- clean public URLs, many MCPs from one function, Chumbo Cloud provisioning, or the separate Durable runtime.

Read [advanced patterns](references/advanced-patterns.md) to select one of these
compositions without adding its concepts to the ordinary starter.

## Use the project's actual version

The installed dependency, Deno import, and TypeScript types define what the
project can use. Deployed response headers describe what is live. When public
documentation is available through the docs MCP, inspect the returned
`packageVersion` before applying an API to an older project:

```text
https://dxrpeagddrpbezbkgvdv.supabase.co/functions/v1/docs-mcp
```

## Success

The generated test passes; `doctor` reaches the intended endpoint; one real
application capability appears in discovery; an explicitly safe call produces
the intended application outcome; and the relevant unauthorized or cross-user
case fails correctly. State anything not exercised.
