OpsMCP
README.md
# ๐ OpsMCP โ AI-Powered Company Operations Agent
> An AI-powered company operations agent that uses the **Model Context Protocol (MCP)** to securely connect natural-language AI interactions with a PostgreSQL database.
## ๐ Overview
OpsMCP allows users to interact with company data using natural language instead of manually writing SQL queries or navigating complex admin panels.
The system connects an AI agent to a PostgreSQL database through MCP tools, allowing the agent to retrieve information, analyze users, and perform authorized database operations.
For sensitive write operations, the system requires explicit user confirmation before modifying the database.
---
## ๐ฏ Problem
Traditional internal company systems often require users to:
* Navigate multiple administrative dashboards
* Understand database structures
* Write SQL queries
* Perform repetitive operations manually
* Track database modifications separately
This creates unnecessary complexity for routine company operations.
---
## ๐ก Solution
OpsMCP provides a natural-language interface for company operations.
Instead of writing:
```sql
SELECT id, name, email, role
FROM users
ORDER BY id;
```
A user can simply ask:
> "Show me all users."
The AI determines which MCP tool is required, executes it, receives the result, and converts it into a human-friendly response.
---
## ๐ง How It Works
```text
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Web Dashboard โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ AI Agent โ
โ Natural Language โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ
โ
MCP Tool Calling
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Server โ
โ โ
โ Tools โข Resources โ
โ Prompts โข Security โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโ
โ PostgreSQL โ
โ Database โ
โโโโโโโโโโโโโโโโโโโโโโโโ
```
---
## โจ Key Features
### ๐ค Natural-Language Database Operations
Users can interact with company data using normal language.
Examples:
```text
Show me all users.
```
```text
Find user with ID 2.
```
```text
Create a new user named Rahul with role developer.
```
```text
Change Rahul's role to manager.
```
```text
Analyze all users and tell me which role has the most users.
```
---
### ๐ง MCP Tools
The project exposes database operations as MCP tools.
Current tools include:
| Tool | Purpose |
| ------------------ | ------------------------- |
| `get_users` | Retrieve all users |
| `get_user_by_id` | Retrieve a specific user |
| `create_user` | Create a new user |
| `update_user_role` | Update a user's role |
| `analyze_users` | Analyze user distribution |
---
### ๐ MCP Resources
The project also demonstrates MCP resources for providing structured contextual information to the AI agent.
Example:
```text
company://info
```
This resource contains information about:
* Departments
* Company roles
* Organization structure
---
### ๐งฉ MCP Prompts
Reusable MCP prompts are included for structured operations such as user analysis.
Example analysis workflow:
```text
1. Count total users
2. Group users by role
3. Identify unusual roles
4. Generate a summary
```
---
## ๐ Security
Security is an important part of the project.
### API-Key Authentication
The MCP server supports API-key authentication using HTTP authorization headers.
Two permission levels are implemented:
```text
READ_ONLY
READ_WRITE
```
### Authorization
Read operations can be performed using the read-only permission.
Database-changing operations require:
```text
READ_WRITE
```
permission.
---
## โ ๏ธ Confirmation Before Write Operations
Before executing database-changing operations, the AI client asks the user for confirmation.
Example:
```text
โ ๏ธ WRITE OPERATION REQUIRES CONFIRMATION
Tool : update_user_role
Arguments : {
"user_id": 2,
"new_role": "manager"
}
Do you want to continue? (yes/no)
```
The database is modified only after explicit approval.
---
## ๐ก๏ธ Input Validation
User input is validated before database operations.
For example, supported roles are:
```text
developer
designer
product manager
manager
```
Invalid input such as:
```text
aestronuot
```
is rejected instead of being inserted into the database.
---
## ๐ Audit Logging
Database-changing operations are recorded in an audit log.
Example:
```text
action | tool_name | status
----------------+------------------+---------
update_user_role| update_user_role | SUCCESS
```
This provides traceability for sensitive operations.
---
## ๐๏ธ Project Structure
```text
OPSMCP-AI-AGENNT/
โ
โโโ server/
โ โโโ auth/
โ โโโ database/
โ โ โโโ connection.py
โ โ
โ โโโ prompts/
โ โ โโโ user_analysis.py
โ โ
โ โโโ resources/
โ โ โโโ company.py
โ โ
โ โโโ tools/
โ โโโ audit.py
โ โโโ user_tools.py
โ
โโโ static/
โ โโโ app.js
โ โโโ style.css
โ
โโโ templates/
โ โโโ index.html
โ
โโโ ai_client.py
โโโ web_app.py
โโโ run_server.py
โโโ requirements.txt
โโโ .gitignore
โโโ README.md
```
---
## ๐ ๏ธ Tech Stack
### Backend
* Python
* FastAPI
* Uvicorn
### AI
* OpenAI-compatible API
* Function/tool calling
* Natural-language interaction
### Protocol
* Model Context Protocol (MCP)
* Streamable HTTP transport
### Database
* PostgreSQL
* Psycopg
### Frontend
* HTML
* CSS
* JavaScript
### Security
* API-key authentication
* Read/write authorization
* Confirmation-based database mutations
* Input validation
* Audit logging
---
## โ๏ธ Local Setup
### 1. Clone the repository
```bash
git clone https://github.com/Ayushsharma109/OPSMCP-AI-AGENNT.git
cd OPSMCP-AI-AGENNT
```
### 2. Create a virtual environment
Windows:
```powershell
python -m venv .venv
```
Activate it:
```powershell
.venv\Scripts\activate
```
### 3. Install dependencies
```powershell
pip install -r requirements.txt
```
### 4. Configure environment variables
Create a `.env` file:
```env
MCP_API_KEY=your_main_api_key
MCP_READONLY_KEY=your_readonly_api_key
OPENAI_API_KEY=your_api_key
OPENAI_BASE_URL=your_base_url
OPENAI_MODEL=your_model
DB_NAME=mcp_demo
DB_USER=postgres
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432
```
> Never commit `.env` or API keys to GitHub.
### 5. Start PostgreSQL
Make sure PostgreSQL is running and the required database/tables exist.
### 6. Start the MCP server
```powershell
python run_server.py
```
The MCP server runs on:
```text
http://127.0.0.1:8000
```
### 7. Start the web application
Open another terminal:
```powershell
python web_app.py
```
The dashboard will be available at:
```text
http://127.0.0.1:8080
```
---
## ๐งช Example Workflow
### User
```text
Show me all users.
```
### AI Agent
Determines that `get_users` is required.
### MCP
Executes:
```text
get_users()
```
### PostgreSQL
Returns the user records.
### AI
Converts the database result into a natural-language response.
---
## ๐ Write Operation Workflow
```text
User Request
โ
AI Agent
โ
MCP Tool Selection
โ
Permission Check
โ
User Confirmation
โ
Input Validation
โ
PostgreSQL Update
โ
Audit Log
โ
AI Response
```
This design helps prevent accidental database modifications.
---
## ๐ Hackathon MVP
OpsMCP was developed as a focused MVP demonstrating how MCP can be used to connect AI agents with real enterprise data and controlled backend operations.
The project focuses on:
* AI tool calling
* MCP architecture
* Secure database interaction
* Human confirmation for mutations
* Auditability
* Natural-language company operations
---
## ๐ Future Improvements
Potential future improvements include:
* Role-based dashboard access
* More enterprise MCP tools
* Advanced analytics
* Multi-database support
* Better audit-log visualization
* Deployment-ready authentication
* Enterprise SSO integration
* More granular permissions
---
## ๐จโ๐ป Author
**Ayush Sharma**
Built as a solo hackathon project exploring:
**AI Agents + MCP + PostgreSQL + Secure Tool Execution**
---
## ๐ License
This project is intended primarily as a hackathon and learning project.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues