Skip to content

FBR65/a2a_mcp

Repository files navigation

A2A-MCP: Agent-to-Agent Model Control Protocol

License: AGPL v3 Python 3.11+ uv

A sophisticated multi-agent system that combines the Model Context Protocol (MCP) with Agent-to-Agent (A2A) communication for intelligent text processing, web interaction, and automated workflows.

🌟 Features

πŸ€– Intelligent Multi-Agent System

  • Smart Agent Coordination: Automatic detection of user intent and routing to appropriate agents
  • A2A Communication: Direct agent-to-agent communication for complex workflows
  • MCP Integration: Standards-compliant Model Context Protocol implementation

πŸ”§ Core Services (MCP Tools)

  • Web Search & Weather: DuckDuckGo integration with weather-specific queries
  • Website Content Extraction: Headless browser-based text extraction
  • Time & Date Services: NTP-synchronized accurate time information
  • File Processing: Multi-format document conversion to PDF
  • Data Anonymization: Intelligent PII detection and removal

🎯 Specialized Agents (A2A)

  • Text Optimizer: Professional email generation and tone adjustment
  • Grammar Corrector (Lektor): German/English grammar and spelling correction
  • Sentiment Analysis: Emotion detection and sentiment scoring
  • Query Refactoring: LLM-optimized query reformulation
  • User Interface Agent: Intelligent request interpretation and routing

🌐 User Interfaces

  • Gradio Web Interface: User-friendly browser-based interaction
  • RESTful API: Programmatic access to all services
  • CLI Integration: Command-line tool compatibility

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    A2A-MCP System                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Gradio Interface (Port 7860)                              β”‚
β”‚  β”œβ”€β”€ File Upload & Processing                              β”‚
β”‚  β”œβ”€β”€ Natural Language Input                                β”‚
β”‚  └── Tonality Selection                                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  User Interface Agent (Intelligent Router)                 β”‚
β”‚  β”œβ”€β”€ Intent Detection                                      β”‚
β”‚  β”œβ”€β”€ Agent Selection                                       β”‚
β”‚  └── Response Coordination                                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  MCP Server (Port 8000)                     A2A Registry   β”‚
β”‚  β”œβ”€β”€ Web Search & Weather                   β”œβ”€β”€ Optimizer  β”‚
β”‚  β”œβ”€β”€ Website Extraction                     β”œβ”€β”€ Lektor     β”‚
β”‚  β”œβ”€β”€ Time/Date Services                     β”œβ”€β”€ Sentiment  β”‚
β”‚  β”œβ”€β”€ File Conversion                        β”œβ”€β”€ Query Ref  β”‚
β”‚  └── Anonymization                          └── UI Agent   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Backend Services                                          β”‚
β”‚  β”œβ”€β”€ Selenium WebDriver                                    β”‚
β”‚  β”œβ”€β”€ DuckDuckGo Search                                     β”‚
β”‚  β”œβ”€β”€ NTP Time Sync                                         β”‚
β”‚  β”œβ”€β”€ PDF Conversion                                        β”‚
β”‚  └── LLM Integration (Ollama)                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Ollama with qwen2.5:latest model
  • Modern web browser (for Gradio interface)

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd a2a_mcp
  2. Install dependencies:

    # Using uv (recommended)
    uv sync
    
    # Or using pip
    pip install -r requirements.txt
  3. Configure environment:

    cp .env.example .env
    # Edit .env with your settings
  4. Start Ollama (if not running):

    ollama serve
    ollama pull qwen2.5:latest

Quick Launch

Start all services with the integrated launcher:

python launcher.py

This will automatically start:

  • MCP Server on http://localhost:8000
  • Gradio Interface on http://localhost:7860
  • A2A Agent Registry (embedded)

🎯 Usage Examples

Web Interface

  1. Open your browser to http://localhost:7860
  2. Try these example requests:
"Wie wird das Wetter morgen in Berlin?"
β†’ Automatic web search with weather optimization

"Korrigiere diesen Text: Das ist ein sehr schlechte Satz mit viele Fehler."
β†’ Grammar correction via Lektor agent

"Optimiere diesen Text fΓΌr eine professionelle E-Mail: Das Produkt ist Schrott!"
β†’ Professional email generation via Optimizer agent

"Analysiere das Sentiment: Ich bin so glücklich über dieses großartige Produkt!"
β†’ Sentiment analysis with emotion detection

"Wie spΓ€t ist es jetzt?"
β†’ NTP-synchronized time retrieval

API Usage

import httpx

# Direct MCP tool call
async with httpx.AsyncClient() as client:
    response = await client.post(
        "http://localhost:8000/mcp/call-tool",
        json={
            "name": "duckduckgo_search",
            "arguments": {"query": "weather Berlin", "max_results": 5}
        }
    )
    print(response.json())

Agent Integration

from agent_server.user_interface import process_input

# Intelligent request processing
result = await process_input("Mache diesen Text freundlicher: Ihre Anfrage wurde abgelehnt.")
print(result.final_result)

πŸ”§ Configuration

Environment Variables

# LLM Configuration
BASE_URL=http://localhost:11434/v1
API_KEY=ollama
USER_INTERFACE_MODEL=qwen2.5:latest
OPTIMIZER_MODEL=qwen2.5:latest
LEKTOR_MODEL=qwen2.5:latest
SENTIMENT_MODEL=qwen2.5:latest
QUERY_REF_MODEL=qwen2.5:latest

# Server Configuration
SERVER_HOST=localhost
SERVER_PORT=8000
SERVER_SCHEME=http
GRADIO_HOST=127.0.0.1
GRADIO_PORT=7860

# Debug Options
DEBUG_AGENT_RESPONSES=false
DEBUG_A2A_CALLS=false

# Service Configuration
ANONYMIZER_USE_LLM=false
ANONYMIZER_LLM_ENDPOINT=
ANONYMIZER_LLM_API_KEY=
ANONYMIZER_LLM_MODEL=

Model Requirements

Ensure these models are available in Ollama:

ollama pull qwen2.5:latest  # Primary model for all agents
# Or configure different models per agent in .env

πŸ“š Available Tools & Agents

MCP Tools

Tool Description Parameters
get_current_time NTP-synchronized UTC time None
duckduckgo_search Web search with weather optimization query, max_results
extract_website_text Extract main content from URLs url
anonymize_text Remove PII from text text
convert_to_pdf Convert files to PDF format input_filepath, output_directory

A2A Agents

Agent Purpose Input Output
Optimizer Professional text optimization Raw text + tonality Polished professional text
Lektor Grammar & spelling correction Text with errors Corrected text
Sentiment Emotion & sentiment analysis Any text Sentiment score + emotions
Query Ref LLM query optimization User query Optimized query
User Interface Intelligent request routing Natural language Coordinated response

Supported File Types

Text Processing

  • .txt, .md, .py, .csv, .log, .json, .xml, .html

PDF Conversion

  • Text files: All above formats
  • Images: .jpg, .png, .gif, .bmp, .tiff, .webp
  • Office docs: .docx, .xlsx, .pptx (requires LibreOffice)

πŸ”„ Workflows

Intelligent Text Processing

User Input β†’ Intent Detection β†’ Agent Selection β†’ Processing β†’ Response
     ↓              ↓              ↓              ↓          ↓
"Fix grammar" β†’ Text Processing β†’ Lektor Agent β†’ Correction β†’ Clean Text

Professional Email Generation

Complaint Text β†’ Optimizer Agent β†’ Professional Email β†’ Lektor Check β†’ Final Email

Multi-Step Analysis

Raw Text β†’ Query Refactor β†’ Optimization β†’ Grammar Check β†’ Sentiment Analysis

πŸ› οΈ Development

Project Structure

a2a_mcp/
β”œβ”€β”€ agent_server/           # A2A agents
β”‚   β”œβ”€β”€ user_interface.py   # Main coordination agent
β”‚   β”œβ”€β”€ optimizer.py        # Text optimization
β”‚   β”œβ”€β”€ lektor.py          # Grammar correction
β”‚   β”œβ”€β”€ sentiment.py       # Sentiment analysis
β”‚   └── query_ref.py       # Query refactoring
β”œβ”€β”€ mcp_services/          # MCP service implementations
β”‚   β”œβ”€β”€ mcp_search/        # DuckDuckGo integration
β”‚   β”œβ”€β”€ mcp_website/       # Web scraping
β”‚   β”œβ”€β”€ mcp_time/         # NTP time services
β”‚   β”œβ”€β”€ mcp_anonymizer/   # Data anonymization
β”‚   └── mcp_fileconverter/ # PDF conversion
β”œβ”€β”€ mcp_main.py           # MCP server
β”œβ”€β”€ launcher.py           # Service orchestrator
β”œβ”€β”€ gradio_interface.py   # Web UI
β”œβ”€β”€ a2a_server.py        # A2A registry
└── uploaded_files/      # File upload storage

Adding New Agents

  1. Create agent file in agent_server/:
from pydantic_ai import Agent
from pydantic import BaseModel

class MyAgentResponse(BaseModel):
    result: str

async def my_agent_a2a_function(messages: list) -> MyAgentResponse:
    # Implementation
    pass
  1. Register in A2A server:
# In a2a_server.py
registry.register_a2a_agent("my_agent", my_agent_a2a_function)
  1. Add to user interface agent routing logic

Adding MCP Tools

  1. Implement service in mcp_services/
  2. Add endpoint in mcp_main.py
  3. Register tool in MCP configuration

πŸ§ͺ Testing

Manual Testing

# Test individual agents
python agent_server/sentiment.py
python agent_server/optimizer.py

# Test MCP server
curl http://localhost:8000/health

# Test full workflow
python a2a_server.py

Example Test Cases

# Sentiment analysis
await sentiment_agent("I love this amazing product!")

# Text optimization
await optimizer_agent("Das Produkt ist Schrott!", tonality="professionell")

# Grammar correction
await lektor_agent("Das ist ein sehr schlechte Satz.")

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the AGPL v3 License - see the License.md file for details.

πŸ™ Acknowledgments


Built with ❀️ for intelligent multi-agent workflows

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages