Getting Started

Deploy MCP servers


Build and deploy Model Context Protocol (MCP) servers on Supabase using Edge Functions.

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 mcp

Create a deno.json file in supabase/functions/mcp/ 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
"hono": "npm:hono@^4.9.2",
6
"zod": "npm:zod@^4.1.13"
7
}
8
}

Replace the contents of supabase/functions/mcp/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
// Create Hono app
10
const app = new Hono()
11
12
// Create your MCP server
13
const server = new McpServer({
14
name: 'mcp',
15
version: '0.1.0',
16
})
17
18
// Register a simple addition tool
19
server.registerTool(
20
'add',
21
{
22
title: 'Addition Tool',
23
description: 'Add two numbers together',
24
inputSchema: { a: z.number(), b: z.number() },
25
},
26
({ a, b }) => ({
27
content: [{ type: 'text', text: String(a + b) }],
28
})
29
)
30
31
// Handle MCP requests at the root path
32
app.all('/', async (c) => {
33
const transport = new StreamableHTTPTransport()
34
await server.connect(transport)
35
return transport.handleRequest(c)
36
})
37
38
Deno.serve(app.fetch)

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 mcp

Your MCP server is now running at:

1
http://localhost:54321/functions/v1/mcp

Test your MCP server

Test your server with the official MCP Inspector:

1
npx -y @modelcontextprotocol/inspector

Use the local endpoint http://localhost:54321/functions/v1/mcp 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 mcp

Your MCP server will be available at:

1
https://<your-project-ref>.supabase.co/functions/v1/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
)

Examples

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

Resources