Universal Authentication for MCP Servers - The standard that everyone should follow.
A lightweight, modular authentication library that provides OAuth2 support for popular providers like Google, GitHub, Slack, and Microsoft.
npm install mcp-auth-core
import { MCPAuth, PROVIDERS } from 'mcp-auth-core';
// Create auth instance
const auth = new MCPAuth();
// Register a service with Google OAuth
auth.registerService('my-app', {
clientId: 'your-google-client-id',
clientSecret: 'your-google-client-secret',
redirectUri: 'http://localhost:3000/callback',
scopes: ['profile', 'email'],
provider: PROVIDERS.google
});
// Get authorization URL
const authUrl = auth.getAuthUrl('my-app');
console.log('Visit this URL to authorize:', authUrl);
// Handle callback (in your server)
const token = await auth.handleCallback('my-app', authorizationCode);
// Make authenticated requests
const response = await auth.makeRequest('my-app', userId, 'https://api.example.com/data');
- Google - Full OAuth2 support with user info
- GitHub - OAuth2 with user profile
- Slack - OAuth2 for Slack apps
- Microsoft - Azure AD OAuth2
🎯 MCP-Auth: The Universal Standard
✅ No more custom OAuth for each service
✅ Automatic token refresh
✅ Secure storage
✅ Easy service integration
✅ One API to rule them all
- 🔐 OAuth2 Support - Complete OAuth2 flow implementation
- 🔄 Token Refresh - Automatic token refresh when expired
- 💾 Flexible Storage - Customizable token storage
- 🏗️ Modular Design - Easy to extend with custom providers
- 📦 TypeScript - Full TypeScript support with types
- 🌐 Universal - Works in Node.js and browser environments
The main authentication class that handles OAuth flows.
new MCPAuth(storage?: AuthStorage)
registerService(serviceId: string, config: MCPAuthConfig)
- Register a service configurationgetAuthUrl(serviceId: string, state?: string)
- Get authorization URLhandleCallback(serviceId: string, code: string)
- Handle OAuth callbackgetToken(serviceId: string, userId: string)
- Get valid access tokenmakeRequest(serviceId: string, userId: string, url: string, options?)
- Make authenticated request
MCPAuthConfig
- Service configurationAuthToken
- Token informationAuthProvider
- OAuth provider configurationAuthStorage
- Storage interface for tokens
See the examples/
directory for complete usage examples.
MIT