Clerk MCP Template

A production-ready template for building Model Context Protocol (MCP) servers with Clerk authentication on Cloudflare Workers
  • typescript

2

GitHub Stars

typescript

Language

6 months ago

First Indexed

2 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "dyeoman2-clerk-mcp-template": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-remote",
        "https://your-mcp-server.your-subdomain.workers.dev/sse"
      ],
      "env": {
        "APP_URL": "https://your-app.com",
        "CLERK_SECRET_KEY": "sk_test_your_actual_clerk_secret_key",
        "CLERK_PUBLISHABLE_KEY": "pk_test_your_actual_clerk_publishable_key"
      }
    }
  }
}

You deploy a secure, Clerk-authenticated MCP (Model Context Protocol) server on Cloudflare Workers to expose your application’s data and actions as authenticated tools. This server handles OAuth flows, session state, and provides MCP tools that operate with the context of the authenticated Clerk user, enabling secure integrations with Claude AI or other MCP clients.

How to use

You connect an MCP client to your Clerk-authenticated MCP server to access your protected tools. The server manages the OAuth flow, ensures requests are authenticated, and exposes MCP tools that run in the context of the signed-in Clerk user. Use the Claude Desktop MCP configuration to register your server and enable tool access for your users.

How to install

Prerequisites include a modern Node.js runtime, a Clerk account with API keys, and a Cloudflare account with Workers enabled. You also need an existing application that uses Clerk for authentication.

Step-by-step install and setup you can follow locally:

# 1) Clone the template and install dependencies
git clone https://github.com/your-username/clerk-mcp-template.git my-mcp-server
cd my-mcp-server
npm install

# 2) Copy and customize environment variables
cp .dev.vars.example .dev.vars

Edit your environment variables to include Clerk keys and your app URL, which points to your Clerk-enabled application that will perform the MCP auth flow.

# .dev.vars
CLERK_SECRET_KEY=sk_test_your_actual_clerk_secret_key
CLERK_PUBLISHABLE_KEY=pk_test_your_actual_clerk_publishable_key
APP_URL=https://your-app.com

Create a KV namespace for OAuth session storage and bind it in your Cloudflare configuration.

wrangler kv:namespace create "OAUTH_KV"

Update the Cloudflare Worker configuration and the MCP server source to reflect your project name, version, and your own MCP tools.

To run locally during development, start the server and access it at the default development URL.

npm run dev

Example MCP server connection for Claude Desktop MCP configuration (local development): you will add this to Claude Desktop as a connected MCP server.

{
  "mcpServers": {
    "my-app": {
      "command": "npx",
      "args": [
        "@modelcontextprotocol/server-remote",
        "https://your-mcp-server.your-subdomain.workers.dev/sse"
      ]
    }
  }
}

Additional sections

Configuration and security are core to a reliable MCP server. The server uses OAuth 2.0 for authentication, HMAC signatures to protect state parameters, and automatic token refresh to keep sessions valid. Ensure you review and configure secure headers and proper CORS rules for your deployment.

Tools and endpoints are designed to run with authenticated context. You can replace example tools with your own implementations that call your application APIs, returning structured content suitable for MCP clients.

If you need debugging or troubleshooting, you can tail Cloudflare Worker logs, inspect MCP Inspector events, and verify your Clerk keys and JWT templates are correctly configured.

Notes

This guide uses a production-ready approach with Clerk authentication on Cloudflare Workers, Durable Objects for session state, and KV storage for transient OAuth data. It includes TypeScript typings, development tooling, and ready-to-use example MCP tools that you can customize.

Available tools

getUsers

Fetch all users from your application using the authenticated context and return a structured response suitable for MCP clients.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational