Getting Started

Deploy MCP servers

Deploy custom MCP servers on Supabase Edge Functions


Deploy your Model Context Protocol (MCP) servers on Supabase take advantage of features like Edge Functions, OAuth, and scaling for AI applications.

  • Get started with deploying MCP servers on Supabase

Deploy your MCP server

Prerequisites

Before you begin, make sure you have:

  • Docker installed (required for local Supabase development)
  • Deno installed (Supabase Edge Functions runtime)
  • Supabase CLI installed

Create a new project

Start by creating a new Supabase project:

1
mkdir my-mcp-server
2
cd my-mcp-server
3
supabase init

Create the MCP server function

Create a new Edge Function for your MCP server:

1
supabase functions new simple-mcp-server

Create a deno.json file in supabase/functions/simple-mcp-server/ with the required dependencies:

1
{
2
"imports": {
3
"@hono/mcp": "npm:@hono/mcp@^0.1.1",
4
"@modelcontextprotocol/sdk": "npm:@modelcontextprotocol/sdk@^1.24.3",
5
"@modelcontextprotocol/sdk/": "npm:/@modelcontextprotocol/sdk@^1.24.3/",
6
"hono": "npm:hono@^4.9.2",
7
"zod": "npm:zod@^4.1.13"
8
}
9
}

Replace the contents of supabase/functions/simple-mcp-server/index.ts with:

1
// Setup type definitions for built-in Supabase Runtime APIs
2
import 'jsr:@supabase/functions-js/edge-runtime.d.ts'
3
4
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
5
import { StreamableHTTPTransport } from '@hono/mcp'
6
import { Hono } from 'hono'
7
import { z } from 'zod'
8
9
// Change this to your function name
10
const functionName = 'simple-mcp-server'
11
const app = new Hono().basePath(`/${functionName}`)
12
13
// Create your MCP server
14
const server = new McpServer({
15
name: 'simple-mcp-server',
16
version: '1.0.0',
17
})
18
19
// Register a simple addition tool
20
server.registerTool(
21
'add',
22
{
23
title: 'Addition Tool',
24
description: 'Add two numbers together',
25
inputSchema: { a: z.number(), b: z.number() },
26
},
27
({ a, b }) => ({
28
content: [{ type: 'text', text: String(a + b) }],
29
})
30
)
31
32
// Handle MCP requests
33
app.all('/mcp', async (c) => {
34
const transport = new StreamableHTTPTransport()
35
await server.connect(transport)
36
return transport.handleRequest(c)
37
})
38
39
Deno.serve(app.fetch)

Understanding the code

The MCP server implementation uses several key components:

Hono routing: Supabase Edge Functions route all requests to /<function-name>/*. The Hono app uses basePath to handle this:

1
const functionName = 'simple-mcp-server'
2
const app = new Hono().basePath(`/${functionName}`)

MCP server setup: The McpServer class from the official SDK handles the MCP protocol:

1
const server = new McpServer({
2
name: 'simple-mcp-server',
3
version: '1.0.0',
4
})

Tool registration: Tools are registered with a name, metadata, input schema (using Zod), and a handler function:

1
server.registerTool(
2
'add',
3
{
4
title: 'Addition Tool',
5
description: 'Add two numbers together',
6
inputSchema: { a: z.number(), b: z.number() },
7
},
8
({ a, b }) => ({
9
content: [{ type: 'text', text: String(a + b) }],
10
})
11
)

HTTP transport: The StreamableHTTPTransport from @hono/mcp connects your MCP server to HTTP requests:

1
app.all('/mcp', async (c) => {
2
const transport = new StreamableHTTPTransport()
3
await server.connect(transport)
4
return transport.handleRequest(c)
5
})

Local development

Start the Supabase local development stack:

1
supabase start

In a separate terminal, serve your function:

1
supabase functions serve --no-verify-jwt simple-mcp-server

Your MCP server is now running at:

1
http://localhost:54321/functions/v1/simple-mcp-server/mcp

Test your MCP server

Test your server with the official MCP Inspector:

1
npx -y @modelcontextprotocol/inspector

Enter your MCP endpoint URL in the inspector UI to explore available tools and test them interactively.

Deploy to production

When you're ready to deploy, link your project and deploy the function:

1
supabase link --project-ref <your-project-ref>
2
supabase functions deploy --no-verify-jwt simple-mcp-server

Your MCP server will be available at:

1
https://<your-project-ref>.supabase.co/functions/v1/simple-mcp-server/mcp

Update your MCP client configuration to use the production URL.

Adding more tools

Extend your MCP server by registering additional tools. Here's an example that queries your Supabase database:

1
import { createClient } from 'jsr:@supabase/supabase-js@2'
2
3
// Create Supabase client
4
const supabase = createClient(
5
Deno.env.get('SUPABASE_URL')!,
6
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
7
)
8
9
server.registerTool(
10
'list_users',
11
{
12
title: 'List Users',
13
description: 'Get a list of users from the database',
14
inputSchema: { limit: z.number().optional().default(10) },
15
},
16
async ({ limit }) => {
17
const { data, error } = await supabase
18
.from('users')
19
.select('id, email, created_at')
20
.limit(limit)
21
22
if (error) {
23
return {
24
content: [{ type: 'text', text: `Error: ${error.message}` }],
25
isError: true,
26
}
27
}
28
29
return {
30
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
31
}
32
}
33
)

Add authentication

Examples

You can find ready-to-use MCP server implementations here:

Resources