This document explains how to use the Model Context Protocol (MCP) server that has been integrated into the fullstack_demo application. This allows AI agents like Claude Desktop to securely interact with your todos through a standardized protocol.
Model Context Protocol (MCP) is a standardized way for AI assistants to securely connect to external tools and services. This implementation allows Claude Desktop and other MCP-compatible AI agents to:
- View all your todos
- Create new todos
- Update existing todos
- Delete todos
- Access your Clerk user data
All operations are authenticated using Clerk OAuth tokens, ensuring secure access to your data.
The MCP server is built using:
- @vercel/mcp-adapter: Handles the core MCP protocol logic
- @clerk/mcp-tools: Integrates Clerk OAuth authentication with MCP
- Next.js App Router: Provides the API endpoints
-
MCP Route Handler (
src/app/[transport]/route.ts)- Defines MCP tools for todo operations
- Supports both
/mcp(HTTP) and/sse(Server-Sent Events) transports - Authenticates requests using Clerk OAuth tokens
-
OAuth Metadata Endpoints
/.well-known/oauth-protected-resource/mcp- Resource metadata/.well-known/oauth-authorization-server- Authorization server metadata (backward compatibility)
-
Middleware (
src/middleware.ts)- Updated to allow public access to
.well-knownendpoints - Maintains authentication for all other routes
- Updated to allow public access to
IMPORTANT: Before the MCP server can work, you must enable dynamic client registration in your Clerk Dashboard.
- Go to the Clerk Dashboard
- Navigate to Configure → OAuth Applications
- Toggle on Dynamic client registration
This allows MCP-compatible clients to automatically register themselves during the OAuth flow.
cd /Users/anthonymays/source/forks/code-society-25-2/lib/javascript/fullstack_demo
npm run devThe server will start on http://localhost:3000 (or your configured port).
The easiest way to connect AI agents to your MCP server is using the mcp-remote utility:
npx -y mcp-remote http://localhost:3000/mcpThis command:
- Automatically configures the MCP client
- Handles OAuth authentication with Clerk
- Works with any MCP-compatible AI agent
- Requires no manual configuration file editing
If you prefer to manually configure your AI agent:
-
Locate your Claude Desktop configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
-
Add your MCP server configuration:
{
"mcpServers": {
"fullstack_demo_todos": {
"url": "http://localhost:3000/mcp",
"transport": "streamable-http",
"auth": {
"type": "oauth2",
"authorizationUrl": "http://localhost:3000/.well-known/oauth-authorization-server"
}
}
}
}Note: The tokenUrl is automatically discovered from the authorization server metadata.
-
Restart your AI agent
-
When the agent tries to use the MCP server, you'll be prompted to authenticate via Clerk OAuth.
When deploying to production:
-
Connect to your production MCP server using
mcp-remote:npx -y mcp-remote https://your-production-domain.com/mcp
Or update your AI agent's configuration manually:
{ "mcpServers": { "fullstack_demo_todos": { "url": "https://your-production-domain.com/mcp", "transport": "streamable-http", "auth": { "type": "oauth2", "authorizationUrl": "https://your-production-domain.com/.well-known/oauth-authorization-server" } } } } -
Ensure your production environment has all required environment variables set:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYCLERK_SECRET_KEY- Database connection strings
- Any other app-specific variables
Gets all todos for the authenticated user.
Parameters: None
Example Response:
[
{
"id": 1,
"text": "Buy groceries",
"completed": false
},
{
"id": 2,
"text": "Finish homework",
"completed": true
}
]Creates a new todo for the authenticated user.
Parameters:
text(string, required): The text content of the todocompleted(boolean, optional): Whether the todo is completed (defaults to false)
Example Response:
{
"id": 1234567890,
"text": "New todo item",
"completed": false
}Updates an existing todo for the authenticated user.
Parameters:
id(number, required): The ID of the todo to updatetext(string, optional): The new text content of the todocompleted(boolean, optional): Whether the todo is completed
Example Response:
{
"id": 1234567890,
"text": "Updated todo text",
"completed": true
}Deletes a todo for the authenticated user.
Parameters:
id(number, required): The ID of the todo to delete
Example Response:
{
"success": true,
"deletedId": 1234567890
}Gets data about the Clerk user that authorized the request.
Parameters: None
Example Response:
{
"id": "user_xxxxxxxxxxxxx",
"firstName": "John",
"lastName": "Doe",
"emailAddresses": [...],
...
}Once configured, you can interact with your todos naturally through Claude:
Example Prompts:
- "Show me all my todos"
- "Create a new todo to buy milk"
- "Mark todo #123 as completed"
- "Delete the todo about buying groceries"
- "What todos do I have pending?"
Claude will use the appropriate MCP tools to interact with your todo list securely.
- All MCP requests are authenticated using Clerk OAuth tokens
- The middleware ensures
.well-knownendpoints are publicly accessible for OAuth discovery - All other routes remain protected by Clerk authentication
- Each user can only access their own todos (enforced by the todoRepository)
- Verify the development server is running
- Check that dynamic client registration is enabled in Clerk Dashboard
- Ensure the URLs in Claude Desktop config match your server URLs
- Check browser/Claude console for error messages
- Verify your Clerk API keys are set correctly in
.env - Ensure the Clerk Frontend API URL in Claude config is correct
- Try re-authenticating by disconnecting and reconnecting the MCP server in Claude
- Check the Next.js server logs for detailed error messages
- Verify the database is accessible and properly configured
- Ensure the authenticated user has permission to perform the action
src/app/[transport]/route.ts- Main MCP server handlersrc/app/.well-known/oauth-protected-resource/mcp/route.ts- OAuth resource metadatasrc/app/.well-known/oauth-authorization-server/route.ts- OAuth server metadata
src/middleware.ts- Updated to allow public access to.well-knownendpointspackage.json- Added MCP dependencies
@vercel/mcp-adapter- MCP protocol handler@clerk/mcp-tools- Clerk OAuth integration for MCP