AI-Agent-with-MCP-Tools
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 个其他特性。
主要特性
- •MCP Protocol: HTTP + Server-Sent Events (SSE) for efficient communication
- •RBAC Control: PyCasbin-based permission management
- •LangChain Integration: ReAct Agent with OpenAI GPT-4o
- •Enterprise UI: Modern, clean interface built with React and TailwindCSS
- •Real-time Updates: Live document management and permission enforcement
- •Security: Multi-layer defense with logging and audit trails
适用场景
快速开始
# 克隆仓库
git clone https://github.com/AIAnytime/AI-Agent-with-MCP-Tools
# 进入目录
cd AI-Agent-with-MCP-Tools
# 查看文档
cat README.md原文 README
AI Agent with MCP Tools and RBAC
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.
Overview
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.
Key Features
- MCP Protocol: HTTP + Server-Sent Events (SSE) for efficient communication
- RBAC Control: PyCasbin-based permission management
- LangChain Integration: ReAct Agent with OpenAI GPT-4o
- Enterprise UI: Modern, clean interface built with React and TailwindCSS
- Real-time Updates: Live document management and permission enforcement
- Security: Multi-layer defense with logging and audit trails
System Architecture
User Interface (React)
↓
API Server (FastAPI)
↓
LangChain ReAct Agent (GPT-4o)
↓
MCP Client (HTTP + SSE)
↓
MCP Server (FastAPI)
↓
RBAC Manager (PyCasbin) + Document Storage
Role Permissions
| Role | Create | Read | Update | Delete |
|---|---|---|---|---|
| Admin | ✅ | ✅ | ✅ | ✅ |
| Editor | ✅ | ✅ | ✅ | ❌ |
| Viewer | ❌ | ✅ | ❌ | ❌ |
Default Users
- alice (Admin): Full access to all operations
- bob (Editor): Can create, read, and update documents
- charlie (Viewer): Read-only access
Installation
1. Clone and Setup Environment
git clone https://github.com/AIAnytime/AI-Agent-with-MCP-Tools.git
cd AI-Agent-with-MCP-Tools
cd backend
activate .venv
2. Install Python Dependencies
pip install -r requirements.txt
3. Configure Environment Variables
The .env file should contain:
OPENAI_API_KEY=your_openai_api_key_here
4. Install Frontend Dependencies
cd frontend
npm install
cd ..
Running the Application
Option 1: Start All Services at Once (Recommended)
chmod +x start_all.sh
./start_all.sh
This will start:
- MCP Server on
http://localhost:8765 - API Server on
http://localhost:8000 - Frontend on
http://localhost:3000
Usage
Open the application at
http://localhost:3000Select a user from the User Selector (alice, bob, or charlie)
Chat with the AI Agent using natural language:
- "Create a document called 'project-plan' with content 'Q4 Project Planning'"
- "List all documents"
- "Read the document 'project-plan'"
- "Update document 'project-plan' with new content"
- "Delete the document 'project-plan'"
- "Check my permissions"
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
Example Demonstrations
Admin User (alice) - Full Access
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
Editor User (bob) - No Delete Permission
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
Viewer User (charlie) - Read Only
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
Project Structure
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