MCP Express SDK
The MCP Express SDK is a TypeScript-based Express library that leverages Descope auth and user management capabilities to allow you to easily add Model Context Protocol (MCP) Specification compliant-Authorization to your MCP Server. It implements the provider side of the OAuth 2.1 protocol with PKCE support, Dynamic Client Registration, and Authorization Server Metadata.
Prerequisites
Before you begin, ensure you have:
Installation
Quick Start
-
Get your credentials from the Descope Console
-
Create a
.env
file in your project root:
Note
The SERVER_URL
is the URL of your MCP Server.
eg. http://localhost:3000
or https://mcp.example.com
- Ensure that the environment variables are loaded, for example by using
dotenv
:
- Then, you can use the SDK as follows:
The descopeMcpAuthRouter()
function adds the metadata and route handlers (eg. dynamic client registration) to the server while the descopeMcpBearerAuth()
function checks the request's headers for a Bearer token and, if found, attaches the Auth
object to the request object under the auth
key.
- TypeScript Support (Optional)
If you're using TypeScript, you can add a type declaration to get proper type checking for the auth
property that gets attached to the Express request object. Create a new file (e.g., types/globals.d.ts
) and add:
This type declaration will:
- Enable TypeScript autocompletion for the
auth
property on request objects - Provide type safety when accessing auth-related properties
- Help catch potential type-related errors during development
Example usage in your route handlers:
Advanced Usage
Dynamic Client Registration
You can configure dynamic client registration options when initializing the provider:
Token Verification
You can customize the token verification options by setting the verifyTokenOptions
object:
Features
The SDK implements the Model Context Protocol Auth Specification, providing:
- 🔐 Hosted Metadata
- 🔑 Authorize endpoint
- 🎫 Token endpoint
- 🔒 Token revocation endpoint
- 📝 Dynamic Client Registration
OAuth Implementation
This SDK implements OAuth 2.0/2.1 following these RFCs:
- RFC 8414: OAuth 2.0 Authorization Server Metadata
- RFC 7591: OAuth 2.0 Dynamic Client Registration
- RFC 7009: OAuth 2.0 Token Revocation
All OAuth schemas are implemented using Zod for runtime type validation.