MCPSERV.CLUB
dyeoman2

Clerk MCP Server

MCP Server

Secure, Clerk‑authenticated MCP tools on Cloudflare Workers

Stale(55)
2stars
0views
Updated 22 days ago

About

A ready‑to‑use template for building Model Context Protocol servers that integrate Clerk authentication and run on Cloudflare Workers. It handles OAuth flows, durable session state, KV storage, and offers TypeScript safety for SaaS, support, analytics, and automation use cases.

Capabilities

Resources
Access data sources
Tools
Execute functions
Prompts
Pre-built templates
Sampling
AI model interactions

Overview

The Clerk MCP Server Template is a turnkey solution for developers who want to expose secure, user‑authenticated Model Context Protocol (MCP) tools to Claude and other AI assistants. By leveraging Clerk’s OAuth 2.0 flow and Cloudflare Workers, the template removes the boilerplate typically required to tie an AI assistant to a web application that already relies on Clerk for identity. Once deployed, the server handles all aspects of authentication—from redirecting users to Clerk’s login page, exchanging authorization codes for access tokens, to maintaining per‑user MCP session state in Durable Objects. This means that every tool call sent by an AI assistant carries the correct, verified user context without exposing credentials or requiring the client to manage tokens.

The server’s architecture is intentionally lightweight yet robust. It runs as a Cloudflare Worker, giving developers instant global edge deployment and the ability to scale without provisioning servers. Persistent session data is stored in Durable Objects, ensuring that MCP sessions survive across multiple requests and remain isolated per user. Temporary OAuth state is kept in KV storage, providing a secure, tamper‑evident mechanism for tracking the OAuth flow. The template also includes HMAC‑signed state parameters and automatic token refresh logic, so developers can trust that the server will handle token expiration transparently.

Key features of this template include: Clerk authentication integration (complete OAuth 2.0 flow with state protection), TypeScript type safety throughout the codebase, ready‑to‑use example tools that demonstrate how to access user data and business logic, and development tooling such as ESLint, Prettier, and MCP Inspector integration. These capabilities allow teams to rapidly prototype AI‑enabled features—like personalized data queries, automated support workflows, or business‑logic automation—while keeping the underlying identity and session management fully managed.

Real‑world use cases span SaaS platforms, customer support portals, data analytics dashboards, and internal workflow automation. For instance, a SaaS product can expose an MCP tool that lets Claude retrieve the authenticated user’s subscription status or usage metrics, enabling conversational billing assistance. In customer support scenarios, the server can provide Claude with authenticated access to ticketing systems or CRM data, ensuring that responses are tailored to the specific user’s context. Because the server runs on Cloudflare Workers, latency is minimized for users worldwide, and the durable‑object session storage guarantees that tool invocations remain consistent across multiple interactions.

Integrating the Clerk MCP Server into an existing workflow is straightforward. Developers add a single authentication route (e.g., ) to their Clerk‑enabled application, which the MCP server calls during the OAuth flow. Once authenticated, Claude can invoke any of the exposed tools via the MCP endpoint, and the server will inject the user’s tokens into the tool payload automatically. This seamless flow allows AI assistants to perform authenticated actions without exposing credentials, providing a secure bridge between the assistant and the user’s data layer.