Better Auth MCP server

Integrates with Better-Auth to simplify authentication processes.
Back to servers
Provider
Nahman Mate
Release date
Jan 28, 2025
Language
TypeScript
Stats
25 stars

Better Auth MCP Server provides enterprise-grade authentication management with secure credential handling, multi-protocol authentication support (OAuth2, SAML, LDAP), and real-time threat detection capabilities. This server helps you implement and manage advanced authentication flows in your applications.

Installation

Installing via Smithery

To install Better Auth MCP Server for Claude Desktop automatically:

npx -y @smithery/cli install @nahmanmate/better-auth-mcp-server --client claude

Manual Configuration

To use with Claude Desktop, add the server configuration to your Claude config file:

On MacOS:

~/Library/Application Support/Claude/claude_desktop_config.json

On Windows:

%APPDATA%/Claude/claude_desktop_config.json

Add the following configuration:

{
  "mcpServers": {
    "better-auth-mcp-server": {
      "command": "node",
      "args": ["/path/to/better-auth-mcp-server/build/index.js"],
      "disabled": false,
      "alwaysAllow": []
    }
  }
}

Configuration

Environment Variables

Configure the server with these environment variables:

# Required
BETTER_AUTH_PROJECT_ID=your-project-id
BETTER_AUTH_API_KEY=your-api-key

# Optional
BETTER_AUTH_ENV=development|staging|production
LOG_LEVEL=info|debug|error

Security Best Practices

For optimal security:

  • API Key Management

    • Store API keys in environment variables
    • Rotate keys regularly
    • Use different keys for each environment
  • Access Control

    • Implement rate limiting
    • Configure IP allowlists
    • Follow the principle of least privilege
  • Monitoring

    • Enable audit logging
    • Monitor authentication failures
    • Set up alerts for suspicious activity

Using the Server

Core Tools

The Better Auth MCP Server provides several tools for authentication management:

Project Setup

// Initialize Better-Auth in your project
await mcp.useTool('setup_better_auth', {
  projectPath: './my-next-app',
  config: {
    projectId: process.env.BETTER_AUTH_PROJECT_ID,
    apiKey: process.env.BETTER_AUTH_API_KEY
  }
});

Testing Authentication Flows

// Test core authentication flows
await mcp.useTool('test_auth_flows', {
  flows: ['login', 'register', '2fa']
});

Migrating from Auth.js/NextAuth

If you're migrating from an existing authentication solution:

// Analyze current auth implementation
await mcp.useTool('analyze_current_auth', {
  projectPath: './my-next-app'
});

// Generate migration steps
await mcp.useTool('generate_migration_plan', {
  projectPath: './my-next-app',
  currentAuthType: 'next-auth'
});

Available Tools

  • Project Analysis

    • analyze_project - Get auth setup recommendations based on your project structure
    • analyze_current_auth - Detect existing auth implementations
    • generate_migration_plan - Create step-by-step migration paths
  • Security & Testing

    • test_auth_flows - Validate login, register, password reset, and 2FA flows
    • test_security - Run OWASP-aligned security checks
    • analyze_logs - Review authentication system logs for issues
    • monitor_auth_flows - Real-time authentication monitoring

Available Resources

Access these resources for monitoring and configuration:

  • better-auth://config - Current Better-Auth configuration settings
  • better-auth://logs - Authentication system logs

Debugging

Since MCP servers communicate over stdio, debugging can be challenging. The MCP Inspector tool provides visibility into the communication:

npm run inspector

This command will provide a URL to access debugging tools in your browser.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later