Skip to content

TEJA4704/mcp-agent-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– MCP Agent Framework

Python 3.10+ MCP Compatible License: MIT

Enterprise-grade agent orchestration framework implementing the Model Context Protocol (MCP) standard. Build, deploy, and manage AI agents at scale with standardized interfaces, context management, and observability.


🌟 What is MCP?

Model Context Protocol (MCP) is an open standard by Anthropic that enables AI agents to:

  • Share Context - Maintain consistent state across interactions
  • Communicate - Exchange structured messages and data
  • Collaborate - Work together on complex tasks
  • Integrate - Connect with external tools and data sources

This framework provides a production-ready implementation of MCP for building sophisticated AI agent systems.


✨ Features

  • πŸ”Œ Standardized Agent Interface - Consistent API across all agents
  • 🧠 Context Management - Automatic state tracking and persistence
  • πŸ”„ Agent Orchestration - Sequential, parallel, and conditional workflows
  • πŸ“Š Full Observability - Tracing, metrics, and logging built-in
  • πŸ›‘οΈ Error Recovery - Automatic retries and graceful degradation
  • ⚑ Async-First - Built for high-performance async execution
  • πŸ”§ Extensible - Easy to add custom agents and tools

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       MCP Agent Framework                         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚                   Agent Registry                         β”‚     β”‚
β”‚  β”‚  β€’ Agent Discovery  β€’ Lifecycle Management  β€’ Versioning β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                              ↓                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚                  Agent Orchestrator                      β”‚     β”‚
β”‚  β”‚  β€’ Workflow Execution  β€’ Dependency Resolution  β€’ Retry  β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                              ↓                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚                   Context Manager                        β”‚     β”‚
β”‚  β”‚  β€’ State Storage  β€’ Cross-Agent Sharing  β€’ Persistence   β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                              ↓                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚  Agent 1   β”‚  β”‚  Agent 2   β”‚  β”‚  Agent N   β”‚                  β”‚
β”‚  β”‚(Extraction)β”‚  β”‚(Validation)β”‚  β”‚ (Custom)   β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                              ↓                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚               Observability Layer                        β”‚     β”‚
β”‚  β”‚  β€’ Tracing (OpenTelemetry)  β€’ Metrics  β€’ Structured Logs β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Installation

git clone https://github.com/yourusername/mcp-agent-framework.git
cd mcp-agent-framework
pip install -r requirements.txt

Create Your First Agent

from mcp_framework import BaseAgent, AgentRequest, AgentResponse
from dataclasses import dataclass

@dataclass
class GreetingRequest(AgentRequest):
    name: str

@dataclass  
class GreetingResponse(AgentResponse):
    message: str

class GreetingAgent(BaseAgent):
    """A simple greeting agent."""
    
    async def execute(self, request: GreetingRequest) -> GreetingResponse:
        return GreetingResponse(
            message=f"Hello, {request.name}!",
            success=True
        )

# Use it
agent = GreetingAgent()
response = await agent.execute(GreetingRequest(name="World"))
print(response.message)  # "Hello, World!"

Orchestrate Multiple Agents

from mcp_framework import AgentOrchestrator

orchestrator = AgentOrchestrator()

# Register agents
orchestrator.register("extract", ExtractionAgent())
orchestrator.register("validate", ValidationAgent())
orchestrator.register("store", StorageAgent())

# Execute workflow
result = await orchestrator.execute([
    ("extract", {"source": "document.pdf"}),
    ("validate", {}),  # Uses output from previous step
    ("store", {})
])

πŸ“š Core Components

1. BaseAgent

The foundation for all agents:

from mcp_framework import BaseAgent

class MyAgent(BaseAgent):
    async def execute(self, request):
        # Your agent logic here
        return response
    
    async def initialize(self):
        # Optional: Setup resources
        pass
    
    async def cleanup(self):
        # Optional: Cleanup resources
        pass

2. Context Manager

Share state across agents:

from mcp_framework import ContextManager

context = ContextManager()

# Store context
await context.set("user_id", "12345")
await context.set("session", {"key": "value"}, ttl=3600)

# Retrieve context
user_id = await context.get("user_id")

# Context is automatically shared across agents in a workflow

3. Agent Orchestrator

Compose complex workflows:

from mcp_framework import AgentOrchestrator

orchestrator = AgentOrchestrator()

# Sequential execution
result = await orchestrator.execute_sequential([agent1, agent2, agent3])

# Parallel execution
results = await orchestrator.execute_parallel([agent1, agent2, agent3])

# Conditional branching
result = await orchestrator.execute_conditional(
    condition=lambda ctx: ctx.get("type") == "premium",
    if_true=premium_agent,
    if_false=standard_agent
)

πŸ€– Built-in Agent Types

Knowledge Graph Agents

from mcp_framework.agents.kg import (
    EntityExtractionAgent,
    RelationshipDiscoveryAgent,
    KnowledgeGraphBuilder
)

Retrieval Agents

from mcp_framework.agents.retrieval import (
    VectorSearchAgent,
    WebContentLoaderAgent,
    DocumentReaderAgent
)

Validation Agents

from mcp_framework.agents.validation import (
    DataQualityAgent,
    SchemaValidationAgent,
    ContentModerationAgent
)

Extraction Agents

from mcp_framework.agents.extraction import (
    StructuredDataExtractor,
    JSONExtractor,
    TableExtractor
)

πŸ“ Project Structure

mcp-agent-framework/
β”œβ”€β”€ mcp_framework/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ base_agent.py       # BaseAgent class
β”‚   β”‚   β”œβ”€β”€ orchestrator.py     # AgentOrchestrator
β”‚   β”‚   β”œβ”€β”€ context.py          # ContextManager
β”‚   β”‚   β”œβ”€β”€ registry.py         # Agent registry
β”‚   β”‚   └── protocol.py         # MCP protocol types
β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”œβ”€β”€ kg/                 # Knowledge graph agents
β”‚   β”‚   β”œβ”€β”€ retrieval/          # Data retrieval agents
β”‚   β”‚   β”œβ”€β”€ validation/         # Validation agents
β”‚   β”‚   └── extraction/         # Data extraction agents
β”‚   └── integrations/
β”‚       β”œβ”€β”€ langfuse.py         # Observability
β”‚       β”œβ”€β”€ redis.py            # Context persistence
β”‚       └── qdrant.py           # Vector storage
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ basic_agent.py
β”‚   β”œβ”€β”€ multi_agent_workflow.py
β”‚   └── context_sharing.py
β”œβ”€β”€ tests/
β”œβ”€β”€ requirements.txt
└── README.md

βš™οΈ Configuration

Environment Variables

# Context storage (optional - defaults to in-memory)
MCP_CONTEXT_STORE=redis://localhost:6379

# Observability (optional)
LANGFUSE_PUBLIC_KEY=pk-lf-...
LANGFUSE_SECRET_KEY=sk-lf-...

# Tracing (optional)
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317

Agent Configuration

# config/agents.yaml
agents:
  - name: entity_extractor
    class: mcp_framework.agents.extraction.EntityExtractor
    config:
      model: gemini-1.5-pro
      max_entities: 100
      
  - name: validator
    class: mcp_framework.agents.validation.DataValidator
    config:
      strict_mode: true

πŸ” Observability

Built-in support for tracing and metrics:

from mcp_framework import BaseAgent, trace

class MyAgent(BaseAgent):
    @trace("my_agent_execution")
    async def execute(self, request):
        with self.tracer.span("processing"):
            result = await self.process(request)
        
        self.metrics.increment("requests_processed")
        return result

πŸ’‘ Best Practices

1. Single Responsibility

Each agent should do one thing well.

2. Use Dataclasses

Define clear request/response types.

3. Handle Errors Gracefully

class RobustAgent(BaseAgent):
    async def execute(self, request):
        try:
            return await self.primary_method(request)
        except PrimaryError:
            return await self.fallback_method(request)

4. Clean Up Resources

class ResourceAgent(BaseAgent):
    async def initialize(self):
        self.connection = await create_connection()
    
    async def cleanup(self):
        await self.connection.close()

🀝 Contributing

Contributions welcome! Please read our contributing guidelines.


πŸ“„ License

MIT License - See LICENSE for details.


πŸ“¬ Contact

Ravi Teja K - AI/ML Engineer

Releases

No releases published

Packages

 
 
 

Contributors

Languages