Installation
Features
- OAuth 2.0 with Dynamic Client Registration (DCR)
- Enterprise SSO (SAML, OIDC)
- Magic link authentication
- JWT token verification
- Access to WorkOS SDK
- Organization management
- User management API
- Directory sync (SCIM)
Setup
1. Configure WorkOS
Get API Keys
- Sign up for WorkOS
- Go to Dashboard
- Navigate to API Keys
- Copy:
- API Key (
sk_...) - Client ID (
client_...)
- API Key (
Create AuthKit Environment
- In WorkOS Dashboard, go to AuthKit
- Create a new environment or use existing
- Note your AuthKit Domain (e.g.,
authkit-staging-abc123.workos.com)
Configure Redirect URIs
- In AuthKit settings, add redirect URI:
- Development:
http://127.0.0.1:3001/callback - Production:
https://your-domain.com/callback
- Development:
2. Environment Variables
Create a.env file:
3. Create Middleware
Createsrc/middleware.ts:
4. Configure xmcp
Inxmcp.config.ts, enable HTTP transport:
Configuration
Required Options
| Option | Type | Description |
|---|---|---|
apiKey | string | WorkOS API Key (sk_...) |
clientId | string | WorkOS Client ID (client_...) |
baseURL | string | Base URL of your MCP server |
authkitDomain | string | WorkOS AuthKit domain |
Optional Options
| Option | Type | Description |
|---|---|---|
docsURL | string | URL to your API documentation |
Usage in Tools
Access Session
Get authenticated user’s session:src/tools/whoami.ts
Get User Profile
Fetch full user details from WorkOS:Use in Tool Logic
src/tools/greet.ts
Access WorkOS Client
Use the WorkOS SDK for advanced operations:src/tools/get-my-memberships.ts
Organization Access Control
Check user’s organization membership:Role-Based Access
Permission-Based Access
Session Type
ThegetSession() function returns:
JWT Claims
WorkOS SDK
The plugin provides access to the full WorkOS SDK:User Management
Organizations
Directory Sync
OAuth Metadata Endpoints
The plugin automatically exposes:Resource Metadata
Authorization Server Metadata
Example Project
Complete example atexamples/workos-http:
src/middleware.ts
src/tools/get-my-memberships.ts
Enterprise SSO
Configure SSO Connection
- Go to WorkOS Dashboard → SSO
- Add a new connection (SAML or OIDC)
- Configure your IdP (Okta, Azure AD, etc.)
- Test the connection
SSO in Your App
WorkOS AuthKit handles SSO automatically. Users are redirected to their organization’s IdP during login.Troubleshooting
”Missing or invalid bearer token”
The MCP client isn’t sending an access token:- Verify AuthKit is configured correctly
- Check redirect URIs match exactly
- Ensure the client completed the OAuth flow
”Token has expired”
Access tokens are short-lived. The client should automatically refresh:- Disconnect and reconnect in the MCP client
- Check system clock is accurate
- Verify refresh token flow is working
”Token verification failed”
- Verify
WORKOS_API_KEYis correct - Check
WORKOS_AUTHKIT_DOMAINmatches your AuthKit environment - Ensure you’re using the correct environment (staging vs production)
- Verify JWKS endpoint is accessible
”Client not initialized”
WorkOS client isn’t configured:- Ensure
workosProvider()is insrc/middleware.ts - Check all environment variables are set
- Verify API key format is correct (
sk_...)