A Next.js application that leverages multiple AI agents to develop, review, and improve code through a coordinated workflow. The system uses LangChain for orchestration and integrates with external MCP (Model Context Protocol) servers for database operations.
- Multi-Agent System: Coordinator, Developer, and Checker agents working together
- Code Development: Automated code generation using Codestral
- Code Review: Intelligent code analysis and feedback using Gemini 2.5 Flash
- Iterative Improvement: Automatic code refinement based on review feedback
- Persistent Storage: Code reviews stored in PostgreSQL via MCP Toolbox server
- Modern UI: Clean, responsive chat interface built with React and Next.js
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT TIER β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Browser (Next.js Frontend) β β
β β - React Component: chat.tsx β β
β β - User Interface for code requests β β
β β - Message display and interaction β β
β ββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββ
β HTTP/JSON
β POST /api/chat
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β APPLICATION TIER β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Next.js API Routes (route.ts) β β
β β - Handles HTTP requests β β
β β - Validates API keys β β
β β - Orchestrates multi-agent workflow β β
β ββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Multi-Agent System (multi-agent-system.ts) β β
β β β β
β β ββββββββββββββββββββ ββββββββββββββββββββ β β
β β β Coordinator Agentββ βββββββββ βΆ β Developer Agent β β β
β β β (Gemini 2.5) β β (Codestral) β β β
β β ββββββββββββββββββββ ββββββββββββββββββββ β β
β β β² β β
β β β ββββββββββββββββββββ β β
β β βββββββββββββββββββββββ βΆβ Checker Agent β β β
β β β (Gemini 2.5) β β β
β β ββββββββββββββββββββ β β
β ββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Protocol
β HTTP (http://127.0.0.1:5000/mcp)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INTEGRATION TIER β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MCP Toolbox Server (Docker: port 5000) β β
β β - Provides database tools via MCP protocol β β
β β - Tools: store-code-review, get-code-review, etc. β β
β ββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββ
β PostgreSQL Protocol
β (port 5432)
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA TIER β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β PostgreSQL Database (Docker: port 5432) β β
β β - Table: code_reviews β β
β β - Stores: user_request, reviewed_code, timestamps β β
β β - Credentials: toolbox_user / my-password β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- User Input: User enters a code request in the chat interface (chat.tsx)
- API Request: Frontend sends POST request to
/api/chat(route.ts) - Agent Creation: API creates coordinator agent (multi-agent-system.ts)
- Tool Invocation: Coordinator orchestrates the following sequence:
ask_developer: Developer agent creates initial codeask_checker: Checker agent reviews the codeask_developer_to_improve: Developer improves code based on feedbackstore_reviewed_code: Stores final code in database via MCP
- MCP Integration: Toolbox MCP client connects to MCP server (toolbox-mcp-client.ts)
- Database Storage: MCP Toolbox executes SQL operations on PostgreSQL
- Response Flow: Result flows back through all layers
- UI Display: Frontend displays the final code to the user
This project is built on LangChain.js, a powerful framework for developing applications powered by large language models (LLMs).
LangChain is a framework designed to simplify the creation of applications using LLMs. It provides:
- Modular Components: Pre-built abstractions for working with language models
- Chains: Sequences of calls to components, LLMs, or other chains
- Agents: Systems that use LLMs to determine which actions to take
- Memory: Mechanisms to persist state between chain or agent calls
- Tool Integration: Easy connection to external data sources and APIs
LangChain was selected as the foundation of this project because it addresses our core architectural requirements:
LangChain allows us to build complex multi-agent systems by composing simple, reusable components. Our coordinator, developer, and checker agents are independently defined but work together seamlessly.
We can easily swap between different LLM providers (Gemini, Codestral) without changing our application logic. LangChain's unified interface makes multi-model architectures straightforward.
LangChain's tool abstraction made it possible to integrate external systems like our MCP servers for database operations and static analysis.
LangChain provides powerful primitives for orchestrating complex workflows. The framework's agent execution model enables our coordinator to manage the sequential flow of development β review β improvement β storage, with conditional logic.
- Node.js 18+ and npm
- Docker and Docker Compose
- API Keys:
- Google Gemini API key
- Mistral API key
-
Clone the repository:
git clone <repository-url> cd multi-agent-code-assistant
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env.localfile in the root directory:GEMINI_API_KEY=your_gemini_api_key_here MISTRAL_API_KEY=your_mistral_api_key_here
-
Start the MCP Toolbox and Database:
docker compose -f toolbox_postgresql/docker-compose.yml up -d
This starts:
- PostgreSQL database on port 5432
- MCP Toolbox server on port 5000
-
Run the development server:
npm run dev
-
Open your browser: Navigate to http://localhost:3000
- Role: Orchestrates the entire workflow
- Responsibilities:
- Receives user requests
- Delegates tasks to specialist agents
- Manages the development β review β improvement β storage cycle
- Presents final results to users
- Role: Code implementation specialist
- Responsibilities:
- Generates initial code implementations
- Improves code based on review feedback
- Follows best practices and clean code principles
- Outputs only code without explanations
- Role: Code quality and security reviewer
- Responsibilities:
- Reviews code for bugs and errors
- Identifies security vulnerabilities
- Suggests improvements
- Provides structured feedback
testmcp/
βββ src/
β βββ app/
β β βββ api/
β β β βββ chat/
β β β βββ route.ts # API endpoint
β β βββ globals.css
β β βββ layout.tsx
β β βββ page.tsx # Main page
β βββ components/
β β βββ chat.tsx # Chat UI component
β βββ lib/
β βββ multi-agent-system.ts # Agent definitions
β βββ toolbox-mcp-client.ts # MCP client
βββ toolbox_postgresql/
β βββ docker-compose.yml # Docker services
β βββ config/
β βββ init.sql # Database schema
β βββ tools.yaml # MCP tools config
βββ next.config.ts
βββ package.json
βββ tsconfig.json