Skip to content

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Cortex MCP Orchestrator

Cortex is an advanced AI Agent Orchestrator built on the Model Context Protocol (MCP). It uses a split-architecture design where a central "Brain" (Orchestrator) communicates with a local "Tool Server" via standard input/output (stdio), allowing for secure, modular, and extensible tool usage.

It features a premium, ChatGPT-style UI with real-time streaming, collapsible "Chain of Thought" reasoning logs, and Markdown rendering.

React Vite Python FastAPI LangChain Groq Langfuse


✨ Key Features

  • ⚑ Model Context Protocol (MCP): Decouples the LLM from the tools using a standardized server-client architecture.
  • πŸ€– LangGraph Orchestration: Uses a ReAct (Reason + Act) agent loop to plan, execute, and refine answers.
  • 🧠 Advanced RAG: Built-in "Memory" using ChromaDB and HuggingFace Embeddings (all-MiniLM-L6-v2) to ingest and recall information from URLs.
  • πŸš€ Real-Time Streaming: Full token-by-token streaming from the backend to the React UI.
  • πŸ›‘οΈ Robust Windows Support: Custom launcher.py architecture to handle stdio pipes and event loops correctly on Windows.
  • 🎨 Modern UI: Dark-themed React interface with "Chain of Thought" accordions, typing indicators, and auto-scrolling.

πŸ—οΈ Architecture

graph LR
    A[React Frontend] <-->|"Stream API"| B[FastAPI Orchestrator]
    B <-->|"Stdio Pipe (MCP)"| C[Launcher Script]
    C <-->|"Subprocess (Stderr Log)"| D[MCP Tool Server]
    D <-->|"Search/RAG"| E[External APIs & ChromaDB]
Loading

πŸ› οΈ Tech Stack

  • Backend: Python, FastAPI, LangChain, LangGraph, mcp (Python SDK), ChromaDB.
  • LLM Provider: Groq (Llama-3-70b).
  • Frontend: React (Vite), CSS Modules (No Tailwind dependency), Lucide Icons, React Markdown.
  • Observability: Langfuse (Optional, for tracing).

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • Node.js & npm
  • A Groq API Key (Get one here)
  • A SerpApi Key (For Google Search)

1. Backend Setup

  1. Clone the repository and navigate to the backend folder:

    cd backend
  2. Create a Virtual Environment:

    python -m venv venv
    # Windows
    venv\Scripts\activate
    # Mac/Linux
    source venv/bin/activate
  3. Install Dependencies:

    pip install fastapi uvicorn mcp langchain-groq langgraph langchain-community langchain-chroma langchain-huggingface sentence-transformers python-dotenv langfuse
  4. Configure Environment: Create a .env file in the backend folder:

    GROQ_API_KEY=gsk_your_key_here
    SERPAPI_API_KEY=your_serpapi_key
    # Optional: Langfuse for tracing
    LANGFUSE_PUBLIC_KEY=pk-lf-...
    LANGFUSE_SECRET_KEY=sk-lf-...
    LANGFUSE_HOST=https://cloud.langfuse.com

2. Frontend Setup

  1. Navigate to the frontend folder:

    cd ../frontend
  2. Install Node Modules:

    npm install
    npm install lucide-react react-markdown remark-gfm
  3. Configure Environment: Create a .env file in the frontend root:

    VITE_API_URL=http://localhost:8002/api/chat

πŸƒβ€β™‚οΈ Usage

Step 1: Start the Backend (Orchestrator)

The Orchestrator will automatically manage the Tool Server process.

# In the backend/ folder (with venv activated)
python orchestrator.py

You should see: Uvicorn running on http://0.0.0.0:8002

Step 2: Start the Frontend

# In the frontend/ folder
npm run dev

Open your browser to http://localhost:5173


πŸ“‚ Project Structure

/project-root
β”œβ”€β”€ /backend
β”‚   β”œβ”€β”€ orchestrator.py    # Main API & Agent Logic
β”‚   β”œβ”€β”€ launcher.py        # Windows Pipe Handler (CRITICAL)
β”‚   β”œβ”€β”€ server.py          # MCP Tool Server (Weather, RAG, Search)
β”‚   β”œβ”€β”€ .env               # API Keys
β”‚   └── chroma_db_mcp/     # Vector Database Storage
β”‚
β”œβ”€β”€ /frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ ChatInterface.jsx  # Main Chat Component
β”‚   β”‚   β”œβ”€β”€ ChatInterface.css  # Styles & Animations
β”‚   β”‚   β”œβ”€β”€ App.jsx            # App Entry
β”‚   β”‚   └── main.jsx           # React Root (Strict Mode disabled)
β”‚   β”œβ”€β”€ .env               # Frontend Config
β”‚   └── package.json
β”‚
└── README.md

πŸ› Troubleshooting

1. CRITICAL ERROR: Orchestrator Error: unhandled errors in a TaskGroup

  • Cause: The MCP Server crashed on startup, usually due to a missing library or API key.
  • Fix: Check the backend/server_debug.log file generated by the launcher.py. It will show the exact error (e.g., ModuleNotFoundError).

2. "Double Text" Glitch (e.g., "The weather isThe weather is...")

  • Cause: React Strict Mode runs effects twice in development.
  • Fix: Ensure main.jsx does not have <StrictMode> wrapping the <App />.

3. Connection Closed Error

  • Cause: print() statements in server.py corrupting the JSON stream.
  • Fix: Use the launcher.py script (already integrated), which redirects all unexpected output to stderr/log files.

🧩 Example Prompts to Try

  • RAG: "Ingest https://example.com/article. After learning it, tell me the main summary."
  • Complex Logic: "Find the birth city of the current CEO of Microsoft, check the weather there, and tell me a fun fact about that city."
  • Reasoning: "I have a Python recursion error. Explain why it happens and write code to fix it."

πŸ“œ License

Distributed under the MIT License. See LICENSE for more information.

πŸ“Έ Interface Preview

Main Chat Interface
The Cortex Agent handling a complex multi-step request.

🧠 Chain of Thought & Reasoning

Process Log Open
Real-time Tool Logs
Reasoning Step
Markdown Rendering

About

🧠 Cortex: An advanced AI Orchestrator built on the Model Context Protocol (MCP). Features a premium React UI with real-time "Chain of Thought" reasoning logs, streaming responses, and a decoupled Python backend using LangGraph, Groq, and local RAG.mcp-protocol ai-agent langgraph react fastapi groq rag llm-orchestrator chain-of-thought vite

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages