MCP OAuth Sample is an MCP server that provides a reference implementation of OAuth 2.1 authorization for Model Context Protocol clients. Built with Next.js 15, Prisma, and PostgreSQL, the project implements specification-compliant authentication and identity management for remote tool interactions. It connects to identity providers such as Google via NextAuth.js and persists token states, sessions, and client registrations directly inside a PostgreSQL database. Software engineers and AI platform developers use this implementation to establish secure authentication boundaries for AI workflows, preventing unauthorized access across distributed agent systems. The server enables full lifecycle token operations, including PKCE verification, automatic refresh token flows, and strict audience validation. It exposes standard discovery endpoints alongside both Server-Sent Events and HTTP streaming transports. In addition to core OAuth functionality, it incorporates dynamic client registration, real-time security monitoring, and an administrative analytics dashboard to track client tool usage and potential threat indicators across connected agent sessions.
Category: Databases & Data Stores
Tags: authentication, identity, nextjs, oauth, postgresql
pnpm install. 2. Configure your environment variables by running cp .env.example .env and setting your database and Google OAuth parameters. 3. Initialize the PostgreSQL schema by executing pnpm prisma generate followed by pnpm prisma db push. 4. Start the development server locally with pnpm dev. 5. Register the server in your MCP client configuration file. For Claude Desktop, add an SSE connection under mcpServers: json { "mcpServers": { "raxIT-oauth": { "url": "https://your-domain.com/mcp/sse", "transport": "sse" } } } For Cursor, configure the HTTP stream transport: json { "mcpServers": { "raxIT-oauth": { "url": "https://your-domain.com/mcp/mcp", "transport": "http-stream" } } }Part of MCP Servers
MCP OAuth Sample is an open-source reference server built with Next.js 15 that implements OAuth 2.1 authentication for the Model Context Protocol. It connects AI clients to protected tools and resources while integrating Google authentication through NextAuth.js, session management in PostgreSQL, and real-time security analytics.
The server works with any Model Context Protocol client supporting remote transports. It includes native configurations for Claude Desktop and Claude Web via Server-Sent Events at the /mcp/sse endpoint, as well as Cursor through HTTP streaming at the /mcp/mcp endpoint.
Clone the repository and install packages using pnpm install. Copy .env.example to .env to configure your database and authentication variables, then run pnpm prisma generate and pnpm prisma db push to initialize PostgreSQL. Start the local server with pnpm dev.
The server supports OAuth 2.1 specifications along with PKCE, refresh token rotation, RFC 8414 and RFC 9728 discovery endpoints, RFC 8707 resource parameters, RFC 7591 dynamic client registration, and strict token audience validation.
Yes, MCP OAuth Sample is open source software released under the Apache License 2.0. Developers can inspect, fork, modify, and host the code independently from its GitHub repository at raxITai/mcp-oauth-sample.