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.
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.
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
.
The server requires an OAuth authorization server that supports dynamic client registration (RFC7591). Auth0 is recommended for this purpose.
To set up with Auth0:
You'll need the following information to configure your server:
.env.template
file to create a new .env
file.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
The repository includes two server implementations:
Supports only the streamable HTTP transport and is suitable for serverless deployment:
bun run src/app.stateless.ts
Supports both SSE and streamable HTTP transports, but requires in-memory state:
bun run src/app.stateful.ts
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 SSEsse-first
: Tries SSE transport first, falls back to HTTPhttp-only
: Only uses HTTP transportsse-only
: Only uses SSE transportFor 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())
}
});
The repository provides:
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.
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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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