Files
supabase/apps/docs/content/guides/functions/examples/mcp-server-mcp-lite.mdx
Colum Ferry 95cf9a78a7 docs(cli): show config examples in TOML and JSONC (#53449)
## Problem

The CLI reads `supabase/config.jsonc` (and `config.json`) since v3.1.0,
but every docs page still shows `config.toml` only. There's also no page
explaining the formats, how to switch, the `$schema` / `#:schema`
declaration, or editor setup, and no reference pages for the new
`supabase config convert` and `supabase config validate` commands.

Linear: CLI-2871

## Solution

- **Dual-format examples from one source.** A new directive
(`features/directives/ConfigFormats.ts`) picks up any ```` ```toml ````
fence with `name=supabase/config.toml` and renders it as
`supabase/config.toml` / `supabase/config.jsonc` tabs. The JSONC is
generated at build time with `convertCliConfigTomlToJsonc` from
`@supabase/config`, the same converter `supabase config convert` uses,
so authors only write TOML and the JSONC matches what the CLI would
produce (comments included). Inside `<$CodeTabs>` the JSONC is added as
an extra tab.
- **The format choice sticks.** `ConfigCodeTabs` keeps the selected
format in `localStorage`, so choosing JSONC switches every config
example on the page and on later pages.
- **Config reference.** The `usage` examples on
`/guides/local-development/cli/config` use the same tabs (they were
highlighted as Python before), and the intro mentions `config.jsonc`.
The `remotes.<branch_name>` example now uses `[remotes.staging]`, since
`<branch_name>` isn't a valid TOML key.
- **New guide, "Config file formats"**
(`/guides/local-development/cli/config-formats`): which file wins,
minimum CLI version, `convert` and `validate`, schema declaration and
versioning, and editor setup (VS Code trusted domains, Even Better TOML,
Tombi, SchemaStore).
- **CLI reference.** Adds `supabase-config-convert` and
`supabase-config-validate` to the CLI reference nav.
`cli_v1_commands.yaml` is the generated v3.2.0 reference, identical to
the release bot's update in #53463, so the two PRs don't conflict.
- **Content.** About 60 existing config examples across the guides,
including the Branching configuration page, are tagged
`name=supabase/config.toml`. Branching reads `config.json` and
`config.jsonc` as well, and the Branching configuration page now says
so. Non-Supabase TOML (`pyproject.toml`, `bunfig.toml`) and the v2-era
`[inbucket]` before/after snippet stay TOML-only.
- **Format-neutral prose.** Sentences that described the config as
`config.toml` now say "your config file", naming `supabase/config.toml`
and `supabase/config.jsonc` once per page. TOML section syntax in prose
(`max_frequency` under `[auth.email]`) is written as key paths
(`auth.email.max_frequency`), which read the same in both formats.
Headings that named `config.toml` keep their old anchors. Sentences
about what `supabase init` creates still say `config.toml`.
- **Markdown export for agents.**
`internals/generate-guides-markdown.ts` runs the same transform, so the
`.md` pages served to AI agents include the JSONC example after each
TOML one.
- A test converts every tagged example under `content/`, so a broken
TOML example fails tests instead of the build.

New dependencies for `apps/docs`: `@supabase/config` (^1.8.0) and
`effect` (the same `effect` version Studio pins).

`config convert` and `config validate` ship in CLI v3.2.0, which is now
stable.

## Review instructions

1. Open `/docs/guides/local-development/seeding-your-database` on the
preview. Switch an example to `supabase/config.jsonc` and check the
other examples on the page switch too.
2. Open `/docs/guides/local-development/cli/config` and check the usage
examples open on JSONC.
3. Read `/docs/guides/local-development/cli/config-formats`.
4. Open `/docs/reference/cli/supabase-config-convert` and
`/docs/reference/cli/supabase-config-validate`.

## Self-review

Ran the `review-the-docs` local self-review (content, pipeline, and
component checks) over the 54 changed pages.

- No blockers. Fixed the nits it found: leftover TOML section syntax in
prose (diff engines, declarative schemas, Branching, the common settings
table on Local and hosted projects), a few long or ungrammatical
sentences, and the conversion follow-up steps on Config file formats,
now a list.
- Links, custom anchors, nav wiring, and frontmatter check out.
- The `.md` export on the preview shows each TOML example followed by
its JSONC version.
- `test-the-docs` deferred: the changed fences are config snippets, and
`ConfigFormats.test.ts` already converts every tagged example. No
procedural steps changed apart from the `config convert` and `config
validate` commands on the new page.

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-11-20 14:34:59 +00:00

301 lines
8.7 KiB
Plaintext

---
id: 'examples-mcp-server-mcp-lite'
title: 'Building an MCP Server with mcp-lite'
description: 'Build and deploy a Model Context Protocol (MCP) server on Supabase Edge Functions using mcp-lite.'
---
The [Model Context Protocol](https://modelcontextprotocol.io/introduction) (MCP) enables Large Language Models (LLMs) to interact with external tools and data sources. With `mcp-lite`, you can build lightweight MCP servers that run on Supabase Edge Functions, giving your AI assistants the ability to execute custom tools at the edge.
This guide shows you how to scaffold, develop, and deploy an MCP server using mcp-lite on Supabase Edge Functions.
## What is mcp-lite?
[mcp-lite](https://github.com/fiberplane/mcp-lite) is a lightweight, zero-dependency TypeScript framework for building MCP servers. It works everywhere the Fetch API is available, including Node, Bun, Cloudflare Workers, Deno, and Supabase Edge Functions.
## Why Supabase Edge Functions + mcp-lite?
This combination offers several advantages:
- **Fast cold starts**: Edge Functions boot in milliseconds, and warm isolates serve subsequent requests without restarting
- **Global distribution**: Deploy once and run everywhere
- **Direct database access**: Connect directly to your Supabase Postgres
- **Minimal footprint**: mcp-lite has zero runtime dependencies
- **Full type safety**: TypeScript support in Deno
- **Basic deployment**: One command to production
## Prerequisites
You need:
- [Docker](https://docs.docker.com/get-started/get-docker/) (to run Supabase locally)
- [Deno](https://deno.com/) (Supabase Edge Functions runtime)
- [Supabase CLI](/docs/guides/local-development/cli/getting-started)
## Create a new MCP server
Starting with `create-mcp-lite@0.3.0`, you can scaffold a complete MCP server that runs on Supabase Edge Functions:
```bash
npm create mcp-lite@latest
```
When prompted, select **Supabase Edge Functions (MCP server)** from the template options.
The template creates a focused structure for Edge Functions development:
```
my-mcp-server/
├── supabase/
│ ├── config.toml # Minimal Supabase config (Edge Functions only)
│ └── functions/
│ └── mcp-server/
│ ├── index.ts # MCP server implementation
│ └── deno.json # Deno imports and configuration
├── package.json
└── tsconfig.json
```
## Understanding the project structure
### Minimal config file [#minimal-configtoml]
The template includes a minimal `config.toml` that runs only Edge Functions - no database, storage, or Studio UI. This keeps your local setup lightweight:
```toml supabase/config.toml
# Minimal config for running only Edge Functions (no DB, storage, or studio)
project_id = "starter-mcp-supabase"
[api]
enabled = true
port = 54321
[edge_runtime]
enabled = true
policy = "per_worker"
deno_version = 2
```
You can always add more services as needed.
### Two Hono apps pattern
The template uses a specific pattern required by Supabase Edge Functions:
```ts
// Root handler - matches the function name
const app = new Hono()
// MCP protocol handler
const mcpApp = new Hono()
mcpApp.get('/', (c) => {
return c.json({
message: 'MCP Server on Supabase Edge Functions',
endpoints: {
mcp: '/mcp',
health: '/health',
},
})
})
mcpApp.all('/mcp', async (c) => {
const response = await httpHandler(c.req.raw)
return response
})
// Mount at /mcp-server (the function name)
app.route('/mcp-server', mcpApp)
```
This is required because Supabase routes all requests to `/<function-name>/*`. The outer `app` handles the function-level routing, while `mcpApp` handles your actual MCP endpoints.
### Deno import maps
The template uses Deno's import maps in `deno.json` to manage dependencies:
```json
{
"compilerOptions": {
"lib": ["deno.window", "deno.ns"],
"strict": true
},
"imports": {
"hono": "npm:hono@^4.6.14",
"mcp-lite": "npm:mcp-lite@0.8.2",
"zod": "npm:zod@^4.1.12"
}
}
```
This gives you npm package access while staying in the Deno ecosystem.
## Local development
### Start Supabase
Navigate to your project directory and start Supabase services:
```bash
supabase start
```
### Serve your function
In a separate terminal, serve your MCP function locally:
```bash
supabase functions serve --no-verify-jwt mcp-server
```
Or use the npm script (which runs the same command):
```bash
npm run dev
```
Your MCP server is available at:
```
http://localhost:54321/functions/v1/mcp-server/mcp
```
### Testing your server
Test the MCP server by adding it to your Claude Code, Claude Desktop, Cursor, or your preferred MCP client.
Using Claude Code:
```bash
claude mcp add my-mcp-server -t http http://localhost:54321/functions/v1/mcp-server/mcp
```
You can also test it using the MCP inspector:
```bash
npx @modelcontextprotocol/inspector
```
Then add the MCP endpoint URL in the inspector UI.
## How it works
The MCP server setup is straightforward:
```ts
import { McpServer, StreamableHttpTransport } from 'mcp-lite'
import { z } from 'zod'
// Create MCP server instance
const mcp = new McpServer({
name: 'starter-mcp-supabase-server',
version: '1.0.0',
schemaAdapter: (schema) => z.toJSONSchema(schema as z.ZodType),
})
// Define a tool
mcp.tool('sum', {
description: 'Adds two numbers together',
inputSchema: z.object({
a: z.number(),
b: z.number(),
}),
handler: (args: { a: number; b: number }) => ({
content: [{ type: 'text', text: String(args.a + args.b) }],
}),
})
// Bind to HTTP transport
const transport = new StreamableHttpTransport()
const httpHandler = transport.bind(mcp)
```
## Adding more tools
Extend your MCP server by adding tools directly to the `mcp` instance. Here's an example of adding a database search tool:
```ts
mcp.tool('searchDatabase', {
description: 'Search your Supabase database',
inputSchema: z.object({
table: z.string(),
query: z.string(),
}),
handler: async (args) => {
// Access Supabase client here
// const { data } = await supabase.from(args.table).select('*')
return {
content: [{ type: 'text', text: `Searching ${args.table}...` }],
}
},
})
```
You can add tools that:
- Query your Supabase database
- Access [Supabase Storage](/docs/guides/storage) for file operations
- Call external APIs
- Process data with custom logic
- Integrate with other Supabase features
## Deploy to production
When ready, deploy to Supabase's global edge network:
```bash
supabase functions deploy --no-verify-jwt mcp-server
```
Or use the npm script:
```bash
npm run deploy
```
Your MCP server will be live at:
```
https://your-project-ref.supabase.co/functions/v1/mcp-server/mcp
```
## Authentication considerations
<Admonition type="caution">
The template uses `--no-verify-jwt` for quick development. This means authentication is not enforced by Supabase's JWT layer, and anyone who finds the URL can call your tools.
For production, authenticate at the MCP server level following the [MCP Authorization specification](https://modelcontextprotocol.io/specification/draft/basic/authorization). On Supabase, `withOAuthProtectedResource` and `withSupabase` from `@supabase/server` do this with Supabase Auth as the OAuth 2.1 server, so each tool call runs as the signed-in user. They wrap any MCP library, including mcp-lite. See [Deploy MCP servers](/docs/guides/ai-tools/byo-mcp).
</Admonition>
### Security best practices
When deploying MCP servers:
- **Don't expose sensitive data**: Use the server in development environments with non-production data
- **Implement authentication**: Add proper authentication for production deployments
- **Validate inputs**: Always validate and sanitize tool inputs
- **Limit tool scope**: Only expose tools that are necessary for your use case
- **Monitor usage**: Track tool calls and monitor for unusual activity
For more security guidance, see the [MCP security guide](/docs/guides/getting-started/mcp#security-risks).
## What's next
With your MCP server running on Supabase Edge Functions, you can:
- Connect it to your [Supabase database](/docs/guides/database/overview) for data-driven tools
- Use [Supabase Auth](/docs/guides/auth) to secure your endpoints
- Access [Supabase Storage](/docs/guides/storage) for file operations
- Deploy to multiple regions automatically
- Scale to handle production traffic
- Integrate with AI assistants like Claude, Cursor, or custom MCP clients
## Resources
- [mcp-lite on GitHub](https://github.com/fiberplane/mcp-lite)
- [Model Context Protocol Spec](https://modelcontextprotocol.io/)
- [Supabase Edge Functions Docs](/docs/guides/functions)
- [Deno Runtime Documentation](https://deno.com/)
- [Fiberplane tutorial](https://blog.fiberplane.com/blog/mcp-lite-supabase-edge-functions/)