Aegis Risk

Aegis Risk

A multi-agent financial portfolio risk analyzer that provides MCP tools for fetching market news and storing compliance-reviewed assessment reports in a local database.

Category
Visit Server

README

🛡️ Aegis Risk: Multi-Agent Financial Portfolio Risk Analyzer

Aegis Risk Architecture

A real-world production-grade AI portfolio project demonstrating Agentic AI, Model Context Protocol (MCP), LangGraph orchestration, State Management, and GCP Cloud Run deployment with Vertex AI.

This project simulates a financial advisory system where multiple specialized AI agents collaborate to analyze market news, calculate portfolio exposure, assess compliance risks, and generate detailed assessment reports stored in a local database.


🏗️ Architecture Overview

The system utilizes a client-server architecture separating the Model Orchestration Client (LangGraph) from the Data & Tools Server (MCP Protocol) to achieve secure, modular data integration.

graph TD
    User([User Web Interface]) <-->|SSE / REST API| FastAPI[FastAPI Backend Server]
    
    subgraph Client Application
        FastAPI <-->|Orchestrates| LG[LangGraph Engine]
        LG <-->|State Checkpoint| Mem[MemorySaver Checkpointer]
        
        subgraph Multi-Agent System
            LG --> Agent1[Researcher Agent]
            LG --> Agent2[Portfolio Analyst Agent]
            LG --> Agent3[Risk Manager Agent]
            LG --> Agent4[Compliance Auditor Agent]
        end
    end

    subgraph Custom MCP Server
        MCP_Client[MCP Client stdio] <-->|JSON-RPC| MCP_Server[MCP Server subprocess]
        Agent1 <-->|Call tools| MCP_Client
        Agent3 <-->|Call tools| MCP_Client
        
        MCP_Server <-->|Scrape & Fetch| Web[Mock Financial News API]
        MCP_Server <-->|Read/Write| DB[(SQLite Database)]
    end

    subgraph Google Cloud Platform
        FastAPI -.->|IAM Auth| Vertex[GCP Vertex AI / Gemini 1.5 Flash]
    end
    
    classDef primary fill:#8b5cf6,stroke:#333,stroke-width:2px,color:#fff;
    classDef secondary fill:#06b6d4,stroke:#333,stroke-width:2px,color:#fff;
    class LG,Agent1,Agent2,Agent3,Agent4 primary;
    class MCP_Server,DB secondary;

🤝 The Multi-Agent Loop

  1. Market News Researcher: Discovers if the stock is currently held in the user's holdings and pulls the latest headlines using custom MCP tools.
  2. Portfolio Analyst: Correlates news catalysts with the current portfolio exposure (shares, average cost basis) and performs quantitative calculations.
  3. Risk Manager: Drafts a detailed Markdown report and classifies risk (Low, Medium, High). Invokes the database tool to save the assessment.
  4. Compliance Auditor: Reviews the drafted report. If compliance rules are met, it approves the report. If not, it issues feedback and routes back to the Risk Manager for revision.

🛠️ Tech Stack & Key Concepts

  • LangGraph: Orchestrates the multi-agent execution DAG with a defined state schema, custom routing edges, and checking loops.
  • Model Context Protocol (MCP): Establishes a standard protocol connection via stdio to run a localized database and scraping toolkit.
  • FastAPI: Manages lifespan connections for the MCP subprocess and serves Server-Sent Events (SSE) to deliver real-time agent console logs to the UI.
  • Tailored UI Aesthetics: Premium glassmorphic design utilizing rich dark palettes, dynamic SVG indicators, pulsing loaders, and a live pipeline visualizer.
  • GCP Vertex AI: Connects to the Gemini models natively via GCP Service Accounts (IAM roles) avoiding manual API key management in production.

🚀 Local Quickstart

Prerequisites

  • Python 3.12+
  • Git
  • An API Key (Google Gemini API key) OR authenticated Google Cloud SDK.

1. Clone & Set Up Environment

# Clone the repository
git clone <your-repo-url>
cd multiagent-mcp-gcp-portfolio

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Configure Environment Variables

Create a .env file in the project root:

# For local testing fallback (Standard Gemini API)
GOOGLE_API_KEY=your_gemini_api_key_here

# For GCP Vertex AI (set to false for local testing with API key)
USE_VERTEX_AI=false

3. Run Verification Tests

Before starting the web server, run the automated integration test to verify the LangGraph-MCP connection:

python test_agents.py

This script will launch the MCP server in a background subprocess, run the agentic workflow, save a report to the SQLite DB, and verify the database entry.

4. Start the Web App

python app.py

Open your browser and navigate to http://localhost:8000.


☁️ GCP Deployment (Cloud Run + Vertex AI)

The production architecture deploys the container to Google Cloud Run, which calls Gemini via Vertex AI. Authentication is managed entirely through GCP Service Accounts.

Prerequisites

  1. Installed and authenticated Google Cloud SDK (gcloud auth login).
  2. A GCP project with billing enabled.

Automated Deployment

We provide an automated bash script to configure permissions and deploy:

chmod +x deploy.sh
./deploy.sh

What this script does under the hood:

  1. Enables GCP APIs: Cloud Run, Artifact Registry, Vertex AI, Cloud Build.
  2. Creates a Service Account (agentic-portfolio-sa).
  3. Binds the roles/aiplatform.user (Vertex AI User) role to the Service Account, granting permission to call Gemini.
  4. Builds the Docker image locally and pushes it to Google Artifact Registry.
  5. Deploys the service to GCP Cloud Run using the Service Account.

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured