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:
1mkdir my-mcp-server2cd my-mcp-server3supabase initCreate the MCP server function
Create a new Edge Function for your MCP server:
1supabase functions new simple-mcp-serverCreate 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}This tutorial uses the official MCP TypeScript SDK, but you can use any MCP framework that's compatible with the Edge Runtime, such as mcp-lite, mcp-use, or mcp-handler.
Replace the contents of supabase/functions/simple-mcp-server/index.ts with:
1// Setup type definitions for built-in Supabase Runtime APIs2import 'jsr:@supabase/functions-js/edge-runtime.d.ts'34import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'5import { StreamableHTTPTransport } from '@hono/mcp'6import { Hono } from 'hono'7import { z } from 'zod'89// Change this to your function name10const functionName = 'simple-mcp-server'11const app = new Hono().basePath(`/${functionName}`)1213// Create your MCP server14const server = new McpServer({15 name: 'simple-mcp-server',16 version: '1.0.0',17})1819// Register a simple addition tool20server.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)3132// Handle MCP requests33app.all('/mcp', async (c) => {34 const transport = new StreamableHTTPTransport()35 await server.connect(transport)36 return transport.handleRequest(c)37})3839Deno.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:
1const functionName = 'simple-mcp-server'2const app = new Hono().basePath(`/${functionName}`)MCP server setup: The McpServer class from the official SDK handles the MCP protocol:
1const 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:
1server.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:
1app.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:
1supabase startIn a separate terminal, serve your function:
1supabase functions serve --no-verify-jwt simple-mcp-serverYour MCP server is now running at:
1http://localhost:54321/functions/v1/simple-mcp-server/mcpThe --no-verify-jwt flag disables JWT verification at the Edge Function layer. This is required because MCP authentication is handled by the MCP server itself, not by Supabase's standard JWT validation.
Test your MCP server
Test your server with the official MCP Inspector:
1npx -y @modelcontextprotocol/inspectorEnter 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:
1supabase link --project-ref <your-project-ref>2supabase functions deploy --no-verify-jwt simple-mcp-serverYour MCP server will be available at:
1https://<your-project-ref>.supabase.co/functions/v1/simple-mcp-server/mcpUpdate 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:
1import { createClient } from 'jsr:@supabase/supabase-js@2'23// Create Supabase client4const supabase = createClient(5 Deno.env.get('SUPABASE_URL')!,6 Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!7)89server.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 supabase18 .from('users')19 .select('id, email, created_at')20 .limit(limit)2122 if (error) {23 return {24 content: [{ type: 'text', text: `Error: ${error.message}` }],25 isError: true,26 }27 }2829 return {30 content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],31 }32 }33)Add authentication
MCP authentication is not yet supported on Edge Functions. For now, MCP servers deployed on Supabase Edge Functions are publicly accessible.
Examples
You can find ready-to-use MCP server implementations here: