Clerk MCP server

Manage Clerk's authentication and user management organization management, session handling, and authorization features.
Back to servers
Provider
Clerk
Release date
Apr 12, 2025
Language
TypeScript
Package
Stats
34.9K downloads
1.4K stars

The Clerk Agent Toolkit MCP server enables AI agents to interact with Clerk's user management functionality through the Model Context Protocol. This allows AI models to access Clerk's API for managing users, organizations, and invitations through a standardized interface.

Installation

To run the Clerk MCP server locally, you'll need to have Node.js installed and a Clerk secret key. The server can be started using npx without installing any packages permanently.

Basic Setup

Run the server with your Clerk secret key:

# Using environment variable
CLERK_SECRET_KEY=sk_123 npx -y @clerk/agent-toolkit -p local-mcp

# Or passing the secret key as an argument
npx -y @clerk/agent-toolkit -p local-mcp --secret-key sk_123

Customizing Available Tools

By default, the MCP server provides access to all available Clerk tools. You can limit which tools are available using the --tools flag:

# Use all tools
npx -y @clerk/agent-toolkit -p local-mcp --tools="*"

# Use only user management tools
npx -y @clerk/agent-toolkit -p local-mcp --tools users

# Use all user management tools (alternative syntax)
npx -y @clerk/agent-toolkit -p local-mcp --tools "users.*"

# Use multiple tool categories
npx -y @clerk/agent-toolkit -p local-mcp --tools users organizations

# Use specific tools
npx -y @clerk/agent-toolkit -p local-mcp --tools users.getUserCount organizations.getOrganization

Usage

Integration with Claude Desktop

To use the Clerk MCP server with Claude Desktop, add the following configuration to your claude_desktop_config.json file:

{
  "mcpServers": {
    "clerk": {
      "command": "npx",
      "args": ["-y", "@clerk/agent-toolkit", "-p=local-mcp", "--tools=users", "--secret-key=sk_123"]
    }
  }
}

Replace sk_123 with your actual Clerk secret key.

Available Tools

The Clerk MCP server exposes the following tool categories:

  • Users: Tools for managing users, including creating, retrieving, updating, and deleting user accounts
  • Organizations: Tools for managing organizations, including creating, retrieving, updating, and deleting organizations
  • Invitations: Tools for managing invitations to organizations

Command-Line Options

For a complete list of server options, run:

npx -y @clerk/agent-toolkit -p local-mcp --help

Advanced Configuration

Using a Custom Clerk Client

For more advanced use cases where you need to use a custom Clerk client:

  1. Install the required dependencies:
npm install @clerk/agent-toolkit @clerk/backend
  1. Create a custom Clerk client in your code:
import { createClerkToolkit } from '@clerk/agent-toolkit/modelcontextprotocol';
import { createClerkClient } from '@clerk/backend';

// Create a new Clerk client
const clerkClient = createClerkClient({ secretKey: 'sk_your_key_here' });

// Instantiate a new Clerk toolkit with the custom client
const toolkit = await createClerkToolkit({ clerkClient });

// Use the toolkit as needed

Session Claims

When working with the MCP server, you can inject session claims (like userId, sessionId, orgId) into system prompts to make them accessible to the AI model. This is helpful when you want the AI to act on behalf of a specific user or within a specific organization context.

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