Spaces:
Sleeping
Sleeping
| import os | |
| import httpx | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| class AdminClient: | |
| """ | |
| Communicates with the Admin MCP governance server. | |
| """ | |
| def __init__(self): | |
| self.base_url = os.getenv("ADMIN_MCP_URL") | |
| self.alert_endpoint = f"{self.base_url}/alert" | |
| async def alert(self, tenant_id: str, message: str, redflag: dict): | |
| """ | |
| Sends redflag violation to admin server. | |
| """ | |
| try: | |
| async with httpx.AsyncClient() as client: | |
| response = await client.post( | |
| self.alert_endpoint, | |
| json={ | |
| "tenant_id": tenant_id, | |
| "message": message, | |
| "violations": redflag.get("matches", []), | |
| } | |
| ) | |
| return response.status_code == 200 | |
| except Exception as e: | |
| print("Admin Client Error:", e) | |
| return False | |