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.
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.
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
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
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.
The Clerk MCP server exposes the following tool categories:
For a complete list of server options, run:
npx -y @clerk/agent-toolkit -p local-mcp --help
For more advanced use cases where you need to use a custom Clerk client:
npm install @clerk/agent-toolkit @clerk/backend
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
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.
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.
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"
]
}
}
}
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.
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.