mcp-order-management-rbac
MCP server that enforces role-based access control for order management, allowing users to view, refund, or delete orders based on their role (USER, MANAGER, ADMIN) with a JWT-authenticated FastAPI frontend.
README
Order Management — RBAC with MCP
Role-Based Access Control enforced inside the MCP server, not the
FastAPI client. FastAPI only authenticates (issues/validates JWTs);
every permission decision is made by permissions.py and applied by
the MCP tools in order_checking.py.
Client -> FastAPI (auth: JWT) -> MCP Server (authz: RBAC) -> MySQL
Roles
| Action | USER | MANAGER | ADMIN |
|---|---|---|---|
| View own order | Y | Y | Y |
| View managed user's order | N | Y | Y |
| View another user's order | N | N | Y |
| Refund own order | Y | Y | Y |
| Refund managed user's order | N | Y | Y |
| Refund anyone | N | N | Y |
| Delete order | N | N | Y |
| Create manager | N | N | Y |
| View users | N | managed users | all |
Setup
-
Create the database and tables:
mysql -u root -p < sql/schema.sql -
Copy
.env.exampleto.envand fill in real values (at minimum set a strongJWT_SECRETand your realDATABASE_URL), then export them into your shell / process manager. -
Install dependencies:
pip install -r requirements.txt -
Seed example users/orders (akash=ADMIN, raj=MANAGER, aman/vivek=USER managed by raj):
python sql/seed.py -
Run the MCP server:
python order_checking.py -
Run the FastAPI app (separate process/terminal):
uvicorn main:app --reload
Usage
# Log in, get a JWT
curl -X POST http://127.0.0.1:8000/login \
-H "Content-Type: application/json" \
-d '{"username": "raj", "password": "managerpass123"}'
# Use the token on protected routes
curl http://127.0.0.1:8000/order_status/ORD101 \
-H "Authorization: Bearer <token>"
curl -X POST http://127.0.0.1:8000/refund/ORD101 \
-H "Authorization: Bearer <token>"
Files
| File | Responsibility |
|---|---|
config.py |
Env-driven settings (DB URL, JWT secret, ports) |
auth.py |
Password hashing, JWT issuing/validation, get_current_user dependency |
permissions.py |
The RBAC rules -- the only place authorization decisions are made |
database.py |
SQL access: users, orders, audit log writes |
audit.py |
Logs every tool call (allowed or denied) to file + DB |
order_checking.py |
The MCP server -- tools call permissions.authorize() before touching data |
main.py |
FastAPI app: /login + JWT-protected routes that forward identity to MCP |
schemas.py |
Pydantic request/response models |
sql/schema.sql |
Table definitions (users, orders, audit_logs) |
sql/seed.py |
Creates example users/orders matching the permission matrix above |
Security notes
- The MCP server trusts the
username/rolepassed in from FastAPI. In this design FastAPI is the only client allowed to reach the MCP server (bind it to localhost / an internal network, not the public internet) -- the JWT check happens once, at the FastAPI edge. - Every tool call is written to
audit_logs(andlogs/app.log) with the outcome and reason, whether allowed or denied. - Rotate
JWT_SECRETvia environment variable / secret manager -- never commit it.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.