Building an MCP server in an edge function that uses OAuth

I'm trying to connect an agent (Claude Desktop) to an application I built with Supabase. I've added a simple edge function to act as a MCP server for Claude. I've served it under https (via ngrok) and registered it in Claude as a custom connector.
Claude calls my MCP server and initializes it properly (using the tools/list, initialize, notifications/initialized methods).
Then, when I ask Claude to use my tool, Claude calls my MCP server with a tools/call method. This is fine.
The problem comes after: I want the tolls calling to be authenticated. So my mcp server returns a 401 reponse with a Www-Authenticate header pointing to a second Edge function dedicated to the OAuth workflow. This is exactly what the MCP spec explains for authenticated apps.
However Claude never calls this endpoint and considers that the tool call is failed.
What am I missing?
Was this page helpful?