HTTP OAuth Auth0 MCP server

Provides secure OAuth 2.0 authentication for MCP implementations with flexible token storage and horizontal scalability through Auth0 integration.
Back to servers
Setup instructions
Provider
Naptha AI
Release date
May 03, 2025
Stats
73 stars

This article explains how to set up and use an MCP server that supports HTTP and SSE transports with OAuth authorization. The implementation follows the Model Context Protocol specification.

Introduction

This MCP server implementation supports Streamable HTTP & SSE Transports with OAuth authorization. It provides a reference implementation that you can customize with your own functionality and OAuth credentials to create a working MCP server that adheres to the latest specifications.

Installation Requirements

Dependencies

The server requires Bun, a fast all-in-one JavaScript runtime, as the recommended runtime and package manager. Limited compatibility testing has been done with npm and tsc.

Setting Up OAuth

The server requires an OAuth authorization server that supports dynamic client registration (RFC7591). Auth0 is recommended for this purpose.

To set up with Auth0:

  1. Create an Auth0 account at Auth0.com
  2. Create at least one connection to an identity provider (Google, GitHub, etc.)
  3. Promote the connection to a domain-level connection
  4. Enable Dynamic Client Registration (also called "Dynamic Application Registration")

You'll need the following information to configure your server:

  • Auth0 client ID
  • Auth0 client secret
  • Auth0 tenant domain

Configuration

  1. Copy the .env.template file to create a new .env file
  2. Update the .env file with your Auth0 credentials and configuration:
# Add your Auth0 credentials and other configuration here
AUTH0_CLIENT_ID=your_client_id
AUTH0_CLIENT_SECRET=your_client_secret
AUTH0_DOMAIN=your_domain.auth0.com

Running the Server

The repository includes two server implementations:

Stateless Implementation

Supports only the streamable HTTP transport and is suitable for serverless deployment:

bun run src/app.stateless.ts

Stateful Implementation

Supports both SSE and streamable HTTP transports, but requires in-memory state:

bun run src/app.stateful.ts

Usage

Integrating with MCP Hosts

To connect your server to MCP hosts like Cursor or Claude Desktop, use the mcp-remote npm package:

bunx mcp-remote --transport http-first https://your-domain.com/mcp

Or with npm:

npx mcp-remote --transport http-first https://your-domain.com/mcp

Transport options:

  • http-first: Tries HTTP transport first, falls back to SSE
  • sse-first: Tries SSE transport first, falls back to HTTP
  • http-only: Only uses HTTP transport
  • sse-only: Only uses SSE transport

Connecting to JavaScript/TypeScript Agents

For direct integration with JS/TS applications, you'll need to use authorization headers:

import { openai } from '@ai-sdk/openai';
import { experimental_createMCPClient as createMcpClient, generateText } from 'ai';
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

const mcpClient = await createMcpClient({
  transport: new StreamableHTTPClientTransport(
    new URL("http://localhost:5050/mcp"), {
      requestInit: {
        headers: {
          Authorization: "Bearer YOUR_TOKEN_HERE",
        }, 
      },
      authProvider: undefined,
    }
  ),
});

const tools = await mcpClient.tools();
await generateText({
  model: openai("gpt-4o"),
  prompt: "Hello, world!",
  tools: {
    ...(await mcpClient.tools())
  }
});

Server Architecture

The repository provides:

  1. An MCP server (which you can replace with your own)
  2. An Express.js application that manages both SSE and Streamable HTTP transports and OAuth authorization

The Express application implements the required OAuth endpoints including /authorize and the Authorization Server Metadata endpoint, but proxies the actual authorization to your upstream OAuth server.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "http-oauth-auth0" '{"command":"npx","args":["mcp-remote","--transport","http-first","https://your-server-url.com/mcp"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "http-oauth-auth0": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "--transport",
                "http-first",
                "https://your-server-url.com/mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "http-oauth-auth0": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "--transport",
                "http-first",
                "https://your-server-url.com/mcp"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later