Skip to main content
This guide demonstrates how to deploy an MCP server on Supabase Edge Functions, which runs on Deno and provides a serverless environment for your MCP applications.

Prerequisites

  1. Supabase CLI: Install from Supabase CLI Installation Guide
  2. Supabase Account
  3. Docker Required to solve bug https://github.com/orgs/supabase/discussions/32815
  4. Node.js/Bun: For building your MCP server

Quick Deployment

Deploy your MCP server to Supabase in one command using our automated deployment script:
# Download and run the deployment script
curl -fsSL https://raw.githubusercontent.com/mcp-use/mcp-use/main/examples/typescript/server/supabase/deploy.sh | bash -s -- YOUR_PROJECT_ID
Or download the script first to review it:
# Download the script
curl -fsSL https://raw.githubusercontent.com/mcp-use/mcp-use/main/examples/typescript/server/supabase/deploy.sh -o deploy.sh
chmod +x deploy.sh

# Run with your project ID
./deploy.sh YOUR_PROJECT_ID

# Optional: specify custom function name and bucket name
./deploy.sh YOUR_PROJECT_ID my-function-name my-bucket-name

What the script does

The deployment script automatically:
  1. ✅ Validates Supabase CLI installation and authentication
  2. ✅ Checks if the project is initialized and linked
  3. ✅ Patches config.toml with your project ID
  4. ✅ Builds your MCP application with the correct MCP_URL
  5. ✅ Copies build artifacts to the function directory
  6. ✅ Deploys the function to Supabase Edge Functions
  7. ✅ Uploads widgets to the storage bucket
Prerequisites for the script
  • Supabase CLI installed (npm install -g supabase)
  • Logged in to Supabase (supabase login)
  • Docker running (for deployment)
For manual deployment or to understand each step in detail, continue reading below.

Manual Deployment

Setting Up Your MCP Server for Supabase

1. Initialize a Supabase Project

If you don’t have a Supabase project yet:
supabase init

2. Create an Edge Function

supabase functions new mcp-server
This creates a new function at supabase/functions/mcp-server/.

3. Adapt your MCP Server to use Deno (required for Supabase Edge Functions)

Widgets in the resources folder are automatically registered. Additional widgets can be registered manually. (see UI Widgets)
Complete ExampleA full working example is available in the repository: Supabase Example
// supabase/functions/mcp-server/index.ts

import { createMCPServer } from "https://esm.sh/mcp-use@latest/server";

const PROJECT_REF = Deno.env.get("SUPABASE_PROJECT_REF") || "your-project-ref";
const BASE_URL = Deno.env.get("MCP_URL") || `https://${PROJECT_REF}.supabase.co/functions/v1/mcp-server`;

// Create the mcp-use MCP server instance
const server = createMCPServer("test-app", {
  version: "1.0.0",
  description: "MCP server with automatic UI widget registration deployed on Supabase",
  baseUrl: BASE_URL,
});

// Define your tools
server.tool({
  name: "get-my-city",
  description: "Get my city",
  cb: async () => {
    return { content: [{ type: "text", text: `My city is San Francisco` }] };
  },
});
await server.listen();

4. Widgets assets

Widget assets should be served from a CDN, for example Supabase Storage. Upload the content of the dist/resources/widgets folder to Supabase Storage and set the MCP_URL environment variable to the URL of the dist folder. E.g if you created a bucket called “widgets” in Supabase Storage:
# UPLOAD
supabase storage cp -r dist/resources/widgets ss://widgets/ --experimental
and then set the MCP_URL environment variable to the URL of the widgets bucket.
export MCP_URL="https://YOUR_PROJECT_REF.supabase.co/storage/v1/object/public/widgets" 

5. Build the mcp-use app

echo $MCP_URL
# should output: https://YOUR_PROJECT_REF.supabase.co/storage/v1/object/public/widgets
pnpm build

6. Copy the dist folder to the function directory

cp -r dist supabase/functions/mcp-server/

7. Configure the function in config.toml

[functions.mcp-server]
...
static_files = [ "./functions/mcp-server/dist/**/*.html", "./functions/mcp-server/dist/mcp-use.json" ]
...

8. Deploy the Function

supabase functions deploy mcp-server --use-docker

Using the MCP Server

You can connect to the MCP Server from any MCP client. Below are examples for browser and Node.js using the mcp-use library.

The MCP Server URL

// From your application
//const mcpUrl = `https://YOUR_PROJECT_ID.supabase.co/functions/v1/FUNCTION_NAME/mcp`;
// e.g. if your function name is "mcp-server" as above
const mcpUrl = `https://YOUR_PROJECT_ID.supabase.co/functions/v1/mcp-server/mcp`;

Browser/Client-Side Usage

import { BrowserMCPClient } from "mcp-use";

const client = new BrowserMCPClient({
  mcpServers: {
    supabase: {
      url: `https://YOUR_PROJECT_ID.supabase.co/functions/v1/mcp-server/mcp`,
      transport: "http",
      headers: {
        Authorization: `Bearer ${SUPABASE_ANON_KEY}`,
        "Content-Type": "application/json",
        Accept: "application/json, text/event-stream",
      },
    },
  },
});

// Create a session and initialize
const session = await client.createSession("supabase");
await session.initialize();

// Now use the session to call tools, access resources, etc.
const response = await session.connector.callTool("greet", { name: "World" });

Node.js Usage

import { MCPClient } from "mcp-use";

const client = new MCPClient({
  mcpServers: {
    supabase: {
      url: `https://YOUR_PROJECT_ID.supabase.co/functions/v1/mcp-server/mcp`,
      transport: "http",
      headers: {
        Authorization: `Bearer ${SUPABASE_ANON_KEY}`,
        "Content-Type": "application/json",
        Accept: "application/json, text/event-stream",
      },
    },
  },
});

// Create a session and initialize
const session = await client.createSession("supabase");
await session.initialize();

// Now use the session to call tools, access resources, etc.
const response = await session.connector.callTool("greet", { name: "World" });
Important: Docker Required for Static FilesStatic files configured in static_files are only bundled when Docker is running during deployment. This applies to both local development and production deployment.When deploying with supabase functions deploy, use the —use-docker flag.
docker info  # Verify Docker is running
supabase functions deploy mcp-server --use-docker
See the Supabase static files documentation for more details.

CORS Issues

  • Ensure your CORS headers are correctly configured
  • Check that the Accept header is included in requests
  • Verify your Authorization header has the correct token

Learn More