AI Agent with MCP Tools and RBAC。主要特性包括:MCP Protocol: HTTP + Server-Sent Events (SSE) for efficient communication、RBAC Control: PyCasbin-based permission management、LangChain Integration: ReAct Agent with OpenAI GPT-4o。还包含 2 个其他特性。
AI Agent with MCP Tools and RBAC。主要特性包括:MCP Protocol: HTTP + Server-Sent Events (SSE) for efficient communication、RBAC Control: PyCasbin-based permission management、LangChain Integration: ReAct Agent with OpenAI GPT-4o。还包含 2 个其他特性。
A production-ready AI Agent system that combines the Model Context Protocol (MCP), LangChain ReAct Agent, and Role-Based Access Control (RBAC) using PyCasbin. This application demonstrates secure AI agent operations with enterprise-grade permission management.
This application implements a document management system where users with different roles (Admin, Editor, Viewer) interact with an AI agent. The agent autonomously selects and executes tools based on natural language queries, with all operations protected by RBAC policies.
User Interface (React)
↓
API Server (FastAPI)
↓
LangChain ReAct Agent (GPT-4o)
↓
MCP Client (HTTP + SSE)
↓
MCP Server (FastAPI)
↓
RBAC Manager (PyCasbin) + Document Storage
| Role | Create | Read | Update | Delete |
|---|---|---|---|---|
| Admin | ✅ | ✅ | ✅ | ✅ |
| Editor | ✅ | ✅ | ✅ | ❌ |
| Viewer | ❌ | ✅ | ❌ | ❌ |
git clone https://github.com/AIAnytime/AI-Agent-with-MCP-Tools.git
cd AI-Agent-with-MCP-Tools
cd backend
activate .venv
pip install -r requirements.txt
The .env file should contain:
OPENAI_API_KEY=your_openai_api_key_here
cd frontend
npm install
cd ..
chmod +x start_all.sh
./start_all.sh
This will start:
http://localhost:8765http://localhost:8000http://localhost:3000Open the application at http://localhost:3000
Select a user from the User Selector (alice, bob, or charlie)
Chat with the AI Agent using natural language:
View Documents in the Documents tab to see all created documents
Check Permissions in the Permissions tab to see the RBAC matrix
Learn About the System in the System Architecture tab
Query: "Create a document called 'quarterly-report' with content 'Q4 2024 Report'"
Result: ✅ Document created successfully
Query: "Delete the document 'quarterly-report'"
Result: ✅ Document deleted successfully
Query: "Create a document called 'meeting-notes' with content 'Team Meeting Notes'"
Result: ✅ Document created successfully
Query: "Delete the document 'meeting-notes'"
Result: ❌ Permission denied: Editor role cannot delete documents
Query: "Read the document 'meeting-notes'"
Result: ✅ Document content displayed
Query: "Update document 'meeting-notes' with 'Updated Notes'"
Result: ❌ Permission denied: Viewer role cannot update documents
mcp-rbac-app/
├── backend/
│ ├── api/
│ │ └── main.py # FastAPI backend for frontend
│ ├── agent/
│ │ └── langchain_agent.py # LangChain ReAct Agent
│ ├── mcp/
│ │ ├── mcp_server.py # MCP HTTP Server
│ │ ├── mcp_client.py # MCP Client
│ │ └── document_tools.py # Document CRUD tools
│ ├── rbac/
│ │ ├── model.conf # Casbin RBAC model
│ │ ├── policy.csv # Casbin policies
│ │ └── rbac_manager.py # RBAC enforcement
│ └── storage/
│ └── document_storage.py # Document persistence
├── frontend/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── api/ # API client
│ │ ├── App.jsx # Main app component
│ │ └── main.jsx # Entry point
│ ├── package.json
│ └── vite.config.js
├── data/
│ └── documents/ # Document storage (auto-created)
├── .env # Environment variables
├── requirements.txt
# 克隆仓库
git clone https://github.com/AIAnytime/AI-Agent-with-MCP-Tools
# 进入目录
cd AI-Agent-with-MCP-Tools
# 查看文档
cat README.md