MCPServer exposes
the Web-standard fetch(Request) boundary needed by that runtime; an Edge
Function forwards requests to server.fetch and does not call listen().
This guide deploys the CLI build output at .mcp-use/build/index.js.
Prerequisites
- A TypeScript MCP server built with
mcp-use. - The Supabase CLI, authenticated with
supabase login. - A Supabase project reference.
- Node.js 22.22.2 or later to run the
mcp-usebuild. - Docker only when you choose local Supabase bundling or local function serving. Supabase can also bundle through its API.
Author the server
The public Edge Function URL contains the gateway prefix/functions/v1/mcp-server. Give the MCP server a matching full base path so
the request path seen by server.fetch and the client endpoint agree:
server.fetch later in this guide.
If your gateway or custom domain rewrites the function prefix before the
request reaches the Edge Function, change
basePath to the pathname the
handler actually receives and use that same pathname in the client URL.Build for the Edge Function
The build creates:widgets.
Set its public URL prefix while building so the generated View manifest points
at Storage:
supabase/functions/mcp-server/.mcp-use/build/index.js, not a dist
artifact.
Map npm imports in Deno
The built entry keeps its package imports external. Replacesupabase/functions/mcp-server/deno.json with:
mcp-use imports through
the npm:mcp-use@beta package entry point.
Pin the npm:mcp-use version to the same version used by the project when
reproducible builds are required.
Forward requests to server.fetch
Replace supabase/functions/mcp-server/index.ts:
server.fetch returns a Web Response, so no Node listener, adapter, or port
is involved.
Upload View and public assets
With the default MCP path above, Storage must preserve the URL hierarchy embedded bymcp-use build:
animal-card, upload its built files and the public assets:
- View bundles load from
<basePath>/_mcp-use/views/<name>/.... - Files from the project’s
public/directory load from<basePath>/_mcp-use/public/....
Build-time, runtime, and CSP values
The three concerns are distinct:
Set the runtime values:
CSP_URLS only when intentionally granting the same extra origins to all
four CSP categories. Prefer the tool’s view.csp or a category-specific
variable such as CSP_CONNECT_DOMAINS for narrower access.
Choose gateway authentication
Supabase gateway authentication and MCP authentication are separate layers. For a public demo, disable Supabase’s gateway JWT check explicitly:Test and deploy
Check the Deno entry before deployment:--use-docker to force local bundling, or --use-api to force
server-side bundling. Docker is not unconditionally required for deployment.
The hosted endpoint is:
client connect with -H "Authorization: Bearer TOKEN".
Troubleshooting
- Function 404: verify the project reference, function name, and that
basePathmatches the full request pathname received by the Edge Function. - MCP route 404: make sure the client includes the final
/mcp. - View asset 404: compare the Storage object hierarchy with
<basePath>/_mcp-use/views/and<basePath>/_mcp-use/public/. - View CSP violation: add only the missing external origin to
view.cspor the correspondingCSP_*runtime variable, then redeploy. - Bundle too large: inspect it with
deno infoand try local bundling withsupabase functions deploy mcp-server --use-docker.