# Run, deploy, and verify

Treat local infrastructure, function serving, protocol tests, and application
outcomes as separate checks.

## Local loop

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

1. Start local Supabase:

   ```sh
   supabase start
   ```

2. Serve the function in another terminal:

   ```sh
   npx chumbo dev --function mcp
   ```

   For a generated static API-key server, keep `MCP_API_KEY` in the project's
   gitignored local environment file and pass it with `--env-file`. Hosted
   Edge Function secrets are configured separately.

3. Run the generated mode-specific contract test:

   ```sh
   deno task --config supabase/functions/mcp/deno.json test
   ```

   API-key mode discovers and invokes the generated starter. OAuth and bearer
   modes prove their unauthenticated rejection, while public mode proves the
   fetch handler boots. After replacing `whoami`, update `index_test.ts` for the
   new capability.

4. Probe the local MCP endpoint:

   ```sh
   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` is the
project's configured `[api].port`, or `54321` when absent. Use the actual
function name when it is not `mcp`. Add `--token` for bearer or API-key
discovery. Use a real user token when proving OAuth capabilities and RLS
locally. For public mode, first apply the generated rate-limit migration with
`supabase migration up --local`.

5. Invoke one explicitly safe application tool through the updated test or a
   configured MCP client. Check the application result, not just HTTP 200.

### Multi-persona testing, surface lockfiles, and `chumbo/testing`

- **In-process contract tests (`chumbo/testing`):** Use `createMcpTestClient(app)` with `createTestAuthHarness()`, `assertRlsIsolation(...)`, and `lintUnmountedToolReferences(...)` to verify multi-user RLS isolation and profile description hygiene without external network calls.
- **Local two-persona runner (`npx chumbo try`):** Run `npx chumbo try <tool> --as user-a,user-b` against local Supabase to compare side-by-side results, byte/token budgets, and RLS isolation (non-read tools fail closed without `--yes`).
- **Surface lockfiles (`npx chumbo surface`):** Lock the advertised tool catalog with `npx chumbo surface snapshot --yes` (`mcp-surface.lock.json`) and gate CI with `npx chumbo surface diff` to catch breaking schema changes, authority widening, or catalog token regressions.
- **Journey test scaffolding (`npx chumbo test scaffold`):** Generate a runnable Deno or Vitest contract test skeleton from a payload-free run friction receipt (`--from-run <file>`).
- **Local workbench & MCP App simulator:** Run `npx chumbo dev --workbench` (and `--app <name>` for `ui://` apps) to inspect cold-start token budgets, test personas, and simulate inline/fullscreen CSP-enforced MCP App hosts locally.

## Host-target loop

A `--target next` or `--target node` scaffold runs inside the application
instead of `chumbo dev`, and doctor is its executable contract:

```sh
# next: start the app's ordinary dev server, then
npx chumbo doctor --url http://localhost:3000/mcp --call-tool whoami

# node: run the generated server directly, then probe it
node --experimental-strip-types mcp/index.ts
npx chumbo doctor --url http://127.0.0.1:8080/mcp --call-tool whoami
```

Provide `SUPABASE_URL` and `SUPABASE_PUBLISHABLE_KEY` (plus `MCP_API_KEY`,
`SUPABASE_SECRET_KEY`, or `CHUMBO_STATE_HMAC_KEY` when the mode needs them)
in the server environment. Doctor probes any URL without a Supabase
directory, so the same command verifies the production deployment with
`MCP_PUBLIC_URL` set.

## Deploy

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

Host targets deploy through the application's own pipeline (Vercel, Cloud
Run, or any Node host) instead of `supabase functions deploy`; verify with
the same doctor probe against the public URL.

The endpoint is Streamable HTTP at the function URL. Do not append `/sse`.

## Connect a client

For Claude Code:

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

OAuth mode opens the application's sign-in and consent flow; public mode needs
no credential. For bearer and API-key modes:

```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
diagnostics. Hosted connector products may require OAuth and dynamic client
registration.

## Select verification by risk

| Condition                                            | Evidence to collect                                                               |
| ---------------------------------------------------- | --------------------------------------------------------------------------------- |
| Every change                                         | Type-check; generated test; `initialize`; `tools/list`; one relevant `tools/call` |
| Text, structured, hybrid, or Resource result changed | Assert the exact wire shape and empty/error branches that differ                  |
| Auth or RLS changed                                  | Reject invalid credentials and prove two-user isolation where ownership matters   |
| Scoped discovery changed                             | Compare identities and directly reject a hidden capability call                   |
| Multi-auth changed                                   | Prove token routing and failed prefixed-key non-fallback                          |
| Deployment changed                                   | Run `doctor` and a real hosted client smoke against the public URL                |
| Setup, templates, or package exports changed         | Test a clean generated or packed consumer from first install                      |

## Completion signal

The generated test passes; `doctor` reaches the intended endpoint; the real
capability appears for the intended identity; a safe call produces the
application outcome; and the relevant unauthorized or cross-user case fails.
Name anything not tested.
