OAuth 2.1 MCP Server is an MCP server and Next.js starter template that implements OAuth 2.1 authentication to secure Model Context Protocol endpoints. It connects AI clients to authenticated application resources using Drizzle ORM on PostgreSQL for session and token persistence, alongside Redis for Server-Sent Events coordination. Software developers building multi-user agent integrations use this template to issue access tokens, manage dynamic client registrations, and verify authorization scopes before exposing MCP tools. It enables host applications to support both Streamable HTTP and SSE transports via the Vercel MCP adapter, allowing client-facing platforms like Claude Desktop, Cursor, and VS Code to interact safely with user-specific APIs. With built-in authentication support using Better Auth alongside external providers like Google, developers can guard resources without breaking standard MCP communication patterns.
Category: AI & LLM Tooling
Tags: authentication, nextjs, oauth, postgresql, redis
pnpm install. 2. Configure your .env file with DATABASE_URL, REDIS_URL, BETTER_AUTH_SECRET, and your OAuth credentials (such as GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET). 3. Generate and push database schemas using pnpm run db:generate and pnpm run db:push. 4. Start the local server with pnpm run dev or deploy the app to Vercel. 5. To connect Claude Desktop, add an integration using your hosted URL ending in /mcp/sse. 6. For Cursor, add the following to mcp.json: json { "mcpServers": { "MyServer": { "name": "MCP OAuth Demo", "url": "https://example.com/mcp/mcp", "transport": "http-stream" } } }Part of MCP Servers
Clone the repository from GitHub and install packages using pnpm install. Define the required environment variables in your env file, including DATABASE_URL and BETTER_AUTH_SECRET. Generate and push database tables with pnpm run db:generate and pnpm run db:push, then launch the development server using pnpm run dev.
It works with Claude Desktop and Claude Web using the SSE transport path. It also supports Cursor, Visual Studio Code, and the official MCP Inspector using the Streamable HTTP transport endpoint.
Redis is required when serving traffic via the Server-Sent Events transport. This enables real-time message broadcasting and compatibility with MCP clients like Claude Desktop that rely on SSE rather than standard streamable HTTP.
Yes, OAuth 2.1 MCP Server is an open source template hosted on GitHub. It was forked from run-llama/mcp-nextjs and updated to use Drizzle ORM and Better Auth for persistence and authentication.
The server currently requires deployment to Vercel due to its dependency on the @vercel/mcp-adapter package, which handles protocol routing for both SSE and Streamable HTTP transports.