Multi-Agent Research System MCP Server
README.md
# π Multi-Agent Research System MCP Server
> **Advanced Multi-Agent Architecture for VS Code Copilot Integration**
>
> A next-generation Model Context Protocol (MCP) server that demonstrates how to build powerful multi-agent systems with sophisticated tooling, breaking away from traditional specialized-tool-only MCP implementations.
---
## π Table of Contents
- [Overview](#overview)
- [Architecture](#architecture)
- [Key Features](#key-features)
- [Technology Stack](#technology-stack)
- [Project Structure](#project-structure)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Workflow Pipeline](#workflow-pipeline)
- [VS Code Integration](#vs-code-integration)
- [API Reference](#api-reference)
- [Examples](#examples)
- [Development](#development)
---
## π― Overview
This project represents a **paradigm shift in MCP server design**. While traditional MCP servers focus on exposing simple, specialized tools, this implementation leverages **multi-agent orchestration** to create a sophisticated research system that can be seamlessly integrated into VS Code Copilot.
The system combines three specialized AI agents with powerful internal tools to perform comprehensive research tasksβall exposed through simple, intuitive MCP tools.
### Why This Matters
- **Traditional MCP**: Single-purpose tools exposed directly to clients
- **This Approach**: Multi-agent coordination, tool orchestration, and intelligent workflow management wrapped in a clean interface
- **Result**: More powerful, context-aware, and reliable results delivered through familiar tools
---
## ποΈ Architecture
### System Overview
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β VS Code Copilot β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
MCP Protocol (STDIO)
β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β FastMCP Server (Entry Point) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Exposed Tools: β β
β β β’ run_research_graph(query, num_sources) β β
β β β’ workflow_info() β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β Invokes
β
βββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LangGraph Workflow (State Management) β
β β
β START β Research Agent β Validator Agent β Final Output β END
β Agent Agent Agent
ββββββ¬ββββββββββ¬βββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Internal Tools (Not Exposed to Client) β
β ββββββββββββββββββ ββββββββββββββββββββββββββββββββββββ
β β Web Tools β β LLM Agents (Groq - 70B) ββ
β β β’ web_search β β β’ Research Analysis ββ
β β β’ fetch_page β β β’ Validation & Scoring ββ
β β β’ search_news β β β’ Report Generation ββ
β ββββββββββββββββββ ββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
### Agent Pipeline
```
1. RESEARCH AGENT
ββ Performs web searches using DuckDuckGo
ββ Fetches detailed content from URLs
ββ Performs LLM-based analysis
ββ Extracts facts and insights
ββ Outputs: summary, key_facts, insights
2. VALIDATOR AGENT
ββ Evaluates research quality
ββ Scores reliability (0-100)
ββ Identifies issues and gaps
ββ Provides improvement recommendations
ββ Outputs: validation_score, reliability, status
3. FINAL OUTPUT AGENT
ββ Synthesizes all agent outputs
ββ Generates professional markdown report
ββ Organizes findings hierarchically
ββ Includes sources and recommendations
ββ Outputs: final_report (professional documentation)
```
---
## β¨ Key Features
### π€ Multi-Agent Orchestration
- **Three Specialized Agents**: Research, Validation, and Output generation
- **Sequential Workflow**: Each agent refines the previous agent's output
- **State Preservation**: TypedDict-based state management ensures data consistency
### π§ Advanced Tooling
- **Web Search**: DuckDuckGo integration for source discovery
- **Content Extraction**: Beautiful Soup-based webpage parsing
- **News Search**: Specialized news discovery capability
- **All Internal**: Tools not exposed to clientsβonly results are shared
### π§ Intelligent Analysis
- **LLM-Powered**: Groq's Llama 3.3 (70B) for accurate analysis
- **Temperature Control**: Optimized settings per agent (Research: 0.3, Validation: 0.2, Output: 0.4)
- **JSON Parsing**: Structured output with fallback mechanisms
### π Quality Assurance
- **Validation Scoring**: 0-100 confidence scoring system
- **Reliability Assessment**: Multi-factor reliability ratings
- **Error Tracking**: Issue identification and recommendations
### π Secure Integration
- **Environment Variables**: API keys managed via `.env`
- **STDIO Transport**: Safe MCP communication channel
- **No Data Leakage**: Internal tools hidden from client
---
## π οΈ Technology Stack
| Component | Technology | Purpose |
|-----------|-----------|---------|
| **Agent Framework** | LangGraph | Workflow orchestration & state management |
| **LLM Provider** | Groq (Llama 3.3 70B) | Advanced reasoning & analysis |
| **Language** | Python 3.10+ | Implementation language |
| **MCP Framework** | FastMCP | Server protocol & tool exposure |
| **HTTP Client** | HTTPX | Async web requests |
| **HTML Parser** | BeautifulSoup 4 | Content extraction |
| **Chat Models** | LangChain | LLM integration abstraction |
---
## π Project Structure
```
AgentsCrossToolMCP/
βββ server.py # FastMCP server & tool definitions
βββ graph_workflow.py # LangGraph workflow pipeline
βββ state.py # Shared state TypedDict definition
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project metadata
β
βββ agents/ # Multi-agent components
β βββ __init__.py
β βββ research_agent.py # Source discovery & analysis
β βββ validator_agent.py # Quality validation & scoring
β βββ final_output_agent.py # Report generation
β
βββ tools/ # Internal tool library
βββ __init__.py
βββ web_tools.py # Web search, fetch, news search
βββ __pycache__/
```
---
## π¦ Installation
### Prerequisites
- Python 3.10 or higher
- Groq API key (get one at [https://console.groq.com](https://console.groq.com))
- VS Code with Copilot extension
### Setup Steps
1. **Clone or download the project**
```powershell
cd d:\GENAI\AgentsCrossToolMCP
```
2. **Create virtual environment**
```powershell
python -m venv .venv
.\.venv\Scripts\Activate.ps1
```
3. **Install dependencies**
```powershell
pip install -r requirements.txt
```
4. **Configure environment variables**
Create a `.env` file in the project root:
```env
GROQ_API_KEY=your_groq_api_key_here
```
5. **Verify installation**
```powershell
python server.py
```
You should see the FastMCP banner and server startup messages.
---
## βοΈ Configuration
### Environment Variables
```env
# Required
GROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Optional (uses defaults if not set)
GROQ_MODEL=llama-3.3-70b-versatile # Model for all agents
RESEARCH_TEMPERATURE=0.3 # Research agent creativity
VALIDATOR_TEMPERATURE=0.2 # Validator strictness
OUTPUT_TEMPERATURE=0.4 # Output composition creativity
```
### MCP Server Configuration
The MCP server is configured in VS Code through the settings:
```json
{
"mcpServers": {
"my-mcp-server": {
"command": "python",
"args": ["d:\\GENAI\\AgentsCrossToolMCP\\server.py"],
"disabled": false,
"alwaysAllow": ["run_research_graph", "workflow_info"]
}
}
}
```
---
## π Usage
### Via VS Code Copilot
Once connected, you can use the system directly in Copilot:
**Example Prompt:**
```
@my-mcp-server Use run_research_graph to research "AI safety in Large Language Models"
with 5 sources and provide a comprehensive analysis.
```
**Copilot will:**
1. Call `run_research_graph(query, 5)`
2. Display the multi-page research report
3. Cite sources and validation metrics
### Programmatic Usage
```python
from server import run_research_graph
import asyncio
async def main():
result = await run_research_graph(
query="Is Indian GDP growing? Current growth rate and challenges",
num_sources=5
)
print(result)
asyncio.run(main())
```
### Command Line
```powershell
# Start the server
python server.py
# In another terminal, test via MCP client
# (Configure in VS Code settings)
```
---
## π Workflow Pipeline
### Step-by-Step Execution
#### 1οΈβ£ **Initialization**
- User provides query and source count
- System initializes ResearchState object
- Workflow begins
#### 2οΈβ£ **Research Agent Processing**
```
Input: query, num_sources
ββ web_search(query) β 5 search results
ββ fetch_webpage(url) for top 2 results β raw content
ββ LLM Analysis with tools
ββ Output: summary, key_facts, insights
```
#### 3οΈβ£ **Validation Agent Processing**
```
Input: research_summary, key_facts
ββ LLM Assessment of quality
ββ Scoring (0-100)
ββ Reliability rating
ββ Output: validation_score, status, issues
```
#### 4οΈβ£ **Final Output Agent Processing**
```
Input: all previous outputs + sources
ββ Combine all findings
ββ Format as markdown report
ββ Add structure & organization
ββ Output: final_report (professional document)
```
#### 5οΈβ£ **Return to Client**
- MCP server returns final_report
- Copilot displays in editor
- Sources and validation metrics included
---
## π VS Code Integration
### Setup Instructions
1. **Open VS Code Settings** (`Ctrl+,`)
2. **Go to MCP Servers section**
3. **Add configuration:**
```json
"mcpServers": {
"my-mcp-server": {
"command": "python",
"args": ["d:\\GENAI\\AgentsCrossToolMCP\\server.py"],
"disabled": false
}
}
```
4. **Restart VS Code**
5. **Verify in Copilot Chat:**
- Open Copilot Chat (`Ctrl+L`)
- Type `@my-mcp-server`
- Should see available tools
### Usage in Copilot
```
@my-mcp-server Can you research the latest developments in quantum computing
and provide a detailed analysis with key insights?
```
---
## π API Reference
### Tool: `run_research_graph`
**Purpose**: Execute comprehensive research workflow
**Parameters:**
```python
run_research_graph(
query: str, # Research topic/question
num_sources: int = 5 # Number of sources to fetch
) -> str
```
**Returns:**
```
Professional markdown report containing:
- Executive Summary
- Key Findings
- Detailed Analysis
- Research Sources
- Validation Metrics
- Recommendations
```
**Example:**
```python
report = await run_research_graph(
query="Climate change impact on agricultural productivity",
num_sources=5
)
print(report)
```
---
### Tool: `workflow_info`
**Purpose**: Get information about the multi-agent system
**Parameters:** None
**Returns:**
```
String describing:
- Agent roles and responsibilities
- Available capabilities
- Tool information
```
**Example:**
```python
info = await workflow_info()
print(info)
```
---
## π Examples
### Example 1: Economic Research
**Query:**
```
Query: India GDP growth rate 2024 2025 economic challenges obstacles
Sources: 5
```
**Output includes:**
- GDP growth statistics
- Economic challenges identified
- Market obstacles
- Expert recommendations
- Data reliability assessment
---
### Example 2: Technology Trends
**Query:**
```
Query: Latest developments in quantum computing and AI integration
Sources: 8
```
**Output includes:**
- Recent breakthroughs
- Technical insights
- Industry trends
- Research opportunities
- Cross-domain applications
---
## π§βπ» Development
### Project Architecture Principles
1. **Separation of Concerns**
- Agents focus on specific tasks
- Tools handle data fetching
- Server handles protocol translation
2. **State Immutability Pattern**
- TypedDict ensures type safety
- Operator.add for message accumulation
- Clear state transitions
3. **Error Handling**
- Graceful degradation for tool failures
- LLM JSON parsing fallbacks
- Comprehensive error messages
4. **Extensibility**
- Easy to add new agents
- Simple to integrate new tools
- Flexible temperature/model parameters
### Adding New Agents
1. Create new agent class in `agents/`
2. Implement `async __call__(self, state)` method
3. Add to graph in `graph_workflow.py`
4. Update state.py if needed
### Adding New Tools
1. Create tool function in `tools/web_tools.py`
2. Decorate with `@tool`
3. Add to agent's `bind_tools()` call
4. Keep tools internal (not exposed via MCP)
---
## π Troubleshooting
### Issue: "GROQ_API_KEY not found"
**Solution:** Ensure `.env` file exists with valid API key
```powershell
# Verify .env exists
Test-Path .\.env
# Check content (don't share publicly)
Get-Content .\.env
```
### Issue: MCP server won't start
**Solution:** Check dependencies and Python version
```powershell
python --version # Should be 3.10+
pip list | grep -i fastmcp
```
### Issue: Web fetch fails (403 Forbidden)
**Solution:** Some websites block scraping. System handles this gracefully
- Validator agent scores lower
- System uses alternative sources
- Report still generated with available data
### Issue: Slow response times
**Solution:** Configure fewer sources or optimize LLM
```python
# Use fewer sources
run_research_graph(query, num_sources=3)
# Or increase timeout in web_tools.py
timeout=60.0 # Increase from 30.0
```
---
## π Performance Metrics
### Typical Execution Times
- **Web Search**: 2-3 seconds
- **Content Fetch**: 1-2 seconds per page
- **Research Agent**: 3-5 seconds
- **Validation Agent**: 2-3 seconds
- **Final Output Agent**: 2-3 seconds
- **Total**: ~10-15 seconds for 5 sources
### Resource Requirements
- **CPU**: Minimal (network-bound)
- **Memory**: ~200-300 MB
- **Network**: Required (STDIO/HTTP requests)
- **Storage**: <50 MB code
---
## π Security & Privacy
- **No Data Storage**: Results not persisted
- **API Key Protection**: Via environment variables
- **STDIO Transport**: Encrypted by VS Code
- **No Third-Party Analytics**: Pure execution
- **Tool Isolation**: Internal tools never exposed
---
## π Why This Architecture?
### Traditional MCP Limitations
```
User Request
β
Tool Call
β
Simple Result
```
**Problems:**
- No intelligence between tools
- User must coordinate multiple calls
- No quality validation
- Results not synthesized
### This System's Advantages
```
User Request
β
Workflow Graph
ββ Research Agent (intelligent search)
ββ Validator Agent (quality check)
ββ Final Output Agent (synthesis)
β
Professional Report
```
**Benefits:**
- Autonomous orchestration
- Intelligent analysis layers
- Built-in quality validation
- Professional output
- Single-call interface
---
### VSCode Copilot Conversation
<img width="1375" height="745" alt="Screenshot 2025-11-12 170848" src="https://github.com/user-attachments/assets/5d36c8f1-ed2d-451d-a229-385a1a8041e0" />
<img width="1196" height="755" alt="Screenshot 2025-11-12 170936" src="https://github.com/user-attachments/assets/870df046-4dfd-4886-935b-8f6c9a699015" />
<img width="1217" height="649" alt="Screenshot 2025-11-12 170948 - Copy" src="https://github.com/user-attachments/assets/c63b37ff-ba0f-47b7-b747-6768a258eb4b" />
<img width="1238" height="638" alt="Screenshot 2025-11-12 171001" src="https://github.com/user-attachments/assets/eca92598-56cc-4c31-b253-ff130c0e4eba" />
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo issues