cerbos-mcp-authorization-demo

cerbos/cerbos-mcp-authorization-demo

3.3

If you are the rightful owner of cerbos-mcp-authorization-demo and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This project demonstrates how to implement role-based access control for AI Assistant tools using Model Context Protocol (MCP) and Cerbos.

Tools
  1. list_expenses

    Lists expenses

  2. add_expense

    Adds an expense

  3. approve_expense

    Approves an expense

  4. reject_expense

    Rejects an expense

  5. delete_expense

    Deletes an expense

  6. superpower_tool

    Grants superpowers

Cerbos MCP Authorization

This project demonstrates how to implement role-based access control for AI Assistant tools using Model Context Protocol (MCP) and Cerbos.

Overview

This application creates an MCP server that exposes expense management tools to AI assistants like GitHub Copilot, while enforcing role-based access control using Cerbos policies. Different user roles (admin, manager, user) have different permissions to access specific tools.

Features

  • Role-Based Access Control: Dynamically enables/disables MCP tools based on user roles
  • Declarative Policy Definition: Uses YAML files to define access control policies
  • Centralized Authorization: Leverages Cerbos PDP (Policy Decision Point) for authorization decisions

Getting Started

Prerequisites

  • Node.js (v16+)
  • Docker (for running Cerbos PDP)

Installation

  1. Clone this repository
  2. Install dependencies:
npm install

Running the Application

Step 1: Start the Cerbos PDP

Run the Cerbos Policy Decision Point in Docker:

docker run --rm -it -p 3593:3593 \
  -v "$(pwd)/policies":/policies \
  ghcr.io/cerbos/cerbos:latest

Step 2: Start the MCP Server

npm start

The server will run on port 3000.

Authorization Policies

The application uses the following role-based permissions:

ToolDescriptionAllowed Roles
list_expensesLists expensesadmin, manager, user
add_expenseAdds an expenseuser
approve_expenseApproves an expenseadmin, manager
reject_expenseRejects an expenseadmin, manager
delete_expenseDeletes an expenseadmin
superpower_toolGrants superpowersadmin

These permissions are defined in policies/mcp_expenses.yaml.

Testing Different User Roles

In a real application, the MCP would authentictae the user against an OAuth server to retrieve this information. For simplicity you can ttest different user roles, by modifying the roles array in index.js:

app.use((req, res, next) => {
  req.user = { id: "user-123", roles: ["admin"] }; // Change roles here
  next();
});

Available roles: admin, manager, user

Testing with MCP Clients

Claude

Add the following to your claude_desktop_config.json file:

{
  "mcpServers": {
    "cerbos-demo": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:3000/mcp"]
    }
  }
}

VSCode

  1. Install the MCP Client extension in VS Code
  2. Open the Command Palette (Ctrl+Shift+P) and select "MCP: Add Server"
  3. Enter your server URL: http://localhost:3000/mcp
  4. Connect to the server to see which tools are available based on your role

Example Interactions by Role

Try these examples after setting different roles in index.js:

  • As a user (roles: ['user']):
    • "Add an expense for $100" → Succeeds
    • "Approve the expense" → Fails (Tool not available)
  • As a manager (roles: ['manager']):
    • "Approve expense 123" → Succeeds
    • "Delete expense 123" → Fails (Tool not available)
  • As an admin (roles: ['admin']):
    • "Delete expense 123" → Succeeds
    • All tools are available

Implementation Details

The application integrates MCP with Cerbos by:

  1. Defining all tools in the MCP server
  2. Checking permissions with Cerbos for each tool based on user role
  3. Dynamically enabling/disabling tools based on authorization results
  4. Notifying the MCP client of tool availability changes