MCP ExplorerExplorer

Zenstack Mcp Auth

@jiashengguoon 10 days ago
4 MIT
FreeCommunity
AI Systems
ZenStack MCP Server providing auto-generated CRUD tools with authentication.

Overview

What is Zenstack Mcp Auth

zenstack-mcp-auth is a Model Context Protocol (MCP) Streamable HTTP server that supports auto-generated CRUD tools for database operations with built-in authorization and credential authentication.

Use cases

Use cases include building a blog application with user and post models, creating an e-commerce site with product management, and developing a content management system for dynamic content.

How to use

To use zenstack-mcp-auth, install dependencies with ‘npm install’, set up the database using ‘npx zenstack generate’ and ‘npx prisma db push’, optionally seed the database, and start the server with ‘npm run dev’.

Key features

Key features include support for multiple simultaneous MCP server connections, credential authentication, and automatic generation of CRUD operation tools such as findUnique, create, update, and delete.

Where to use

zenstack-mcp-auth can be used in web applications that require a robust backend for managing data with user authentication, such as blogs, e-commerce platforms, and content management systems.

Content

ZenStack Remote MCP Server with Authorization

A Model Context Protocol (MCP) Streamable HTTP server supporting auto-generated CRUD tools of database with Authorization and credential Authentication.

Features

  • MCP Streamable HTTP Protocol: Multiple simultaneous MCP server connections with credential Authentication support.
  • ZenStack Integration: Automatically generates MCP tools for the CRUD operations of the models defined in the ZenStack schema. This demo will use a simple blog application with User and Post models.

Auto-generated Tools

The server automatically generates MCP tools for each model defined in the ZenStack schema. Here are the supported tools:

  • findUnique
  • findFirst
  • findMany
  • create
  • createMany
  • delete
  • deleteMany
  • update
  • updateMany
  • upsert
  • aggregate
  • groupBy
  • count

You can opt-in available tools for functionNames variable in mcp-server.ts

Quick Start

  1. Install dependencies:

    npm install
    
  2. Set up the database:

    npx zenstack generate
    npx prisma db push
    
  3. Seed the database (optional):

    npx prisma db seed
    

    It create 3 users with posts. The passwords for all users are password123.

  4. Start the server:

    npm run dev
    

Testing the MCP Server

MCP Inspector

The easiest way to test the MCP server is to run

npx @modelcontextprotocol/inspector

MCP Client

If your chosen MCP client supports remote OAuth2 MCP server, you can directly connect. Otherwise, you can use mcp-remote to do it
All the most popular MCP clients (Claude Desktop, Cursor, Github Copilot) use the following config format:

{
  "servers": {
    "my-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://localhost:3001/mcp"
      ]
    }
  }
}

Troubleshooting

Clear your ~/.mcp-auth directory

If you encounter an invalid client error when connecting to the MCP server, it may be due to that mcp-remote only register oauth client for the first time.you can fix it by removing the cached client state:

rm -rf ~/.mcp-auth

Delete old versions of Node in NVM for Claude Desktop

When using Claude Desktop, if you didn’t see any OAuth window open in your browser, it may be due to the fact that Claude Desktop is using an old version of Node.js even if you have a newer version installed. You can fix it by deleting old versions of Node.js in NVM.

Tools

No tools

Comments