Context Engineering MCP Platform

Context Engineering MCP Platform

A development platform that helps AI developers optimize prompts through intelligent context management, providing tools for analysis, optimization, and template management to reduce costs and improve AI response quality.

Category
Visit Server

README

🧠 Context Engineering MCP Platform

<div align="center">

License: MIT Python Node.js MCP Compatible Powered by Gemini

<h3>Transform your AI development with intelligent context management, optimization, and prompt engineering</h3>

English | 日本語 | Demo | Quick Start | Docs

<img src="https://github.com/user-attachments/assets/context-engineering-demo.gif" alt="Context Engineering Demo" width="100%" />

</div>


🎯 The Problem We Solve

Every AI developer faces these challenges:

<table> <tr> <td width="50%">

❌ Without Context Engineering

  • 💸 $1000s wasted on inefficient prompts
  • 🐌 3-5x slower response times
  • 📉 40% lower accuracy in outputs
  • 🔄 Endless copy-pasting of prompts
  • 😤 Frustrated users from poor AI responses

</td> <td width="50%">

✅ With Context Engineering

  • 💰 52% cost reduction through optimization
  • 2x faster AI responses
  • 📈 92% quality score improvements
  • 🎯 78% template reuse rate
  • 😊 Happy users with consistent results

</td> </tr> </table>

🌟 What is Context Engineering?

Context Engineering is the systematic approach to designing, managing, and optimizing the information provided to AI models. Think of it as DevOps for AI prompts - bringing engineering rigor to what has traditionally been ad-hoc prompt crafting.

Core Principles

  1. 📊 Measure Everything - Quality scores, token usage, response times
  2. 🔄 Optimize Continuously - AI-powered improvements on every interaction
  3. 📋 Standardize Templates - Reusable components for consistent results
  4. 🎯 Focus on Outcomes - Business metrics, not just technical metrics

🚀 Key Features That Set Us Apart

1. 🧪 AI-Powered Analysis Engine

<details> <summary><b>Click to see how our analysis works</b></summary>

# Traditional approach - manual review
context = "You are an AI assistant. You help users. You are helpful..."
# Developer: "Looks good to me!" 🤷

# Context Engineering approach - AI analysis
analysis = await analyze_context(context)
print(f"Quality Score: {analysis.quality_score}/100")
print(f"Issues Found: {analysis.issues}")
print(f"Recommendations: {analysis.recommendations}")

# Output:
# Quality Score: 65/100
# Issues Found: ['Redundant statements', 'Vague instructions']
# Recommendations: ['Combine role definition', 'Add specific examples']

Our AI analyzer evaluates:

  • Semantic Coherence: How well ideas flow together
  • Information Density: Token efficiency metrics
  • Clarity Score: Readability and understandability
  • Relevance Mapping: How well content matches intent

</details>

2. ⚡ Intelligent Optimization Algorithms

<details> <summary><b>See optimization in action</b></summary>

# Before optimization
original_context = """
You are an AI assistant. You are helpful. You help users with their 
questions. When users ask questions, you provide helpful answers. 
You should be helpful and provide good answers to questions.
"""
# Tokens: 50, Quality: 60/100

# After optimization
optimized_context = """
You are a helpful AI assistant that provides comprehensive, 
accurate answers to user questions.
"""
# Tokens: 15 (70% reduction!), Quality: 85/100

Optimization strategies:

  • 🎯 Token Reduction: Remove redundancy without losing meaning
  • 💎 Clarity Enhancement: Improve instruction precision
  • 🔗 Relevance Boosting: Prioritize important information
  • 📐 Structure Improvement: Logical flow optimization

</details>

3. 📋 Advanced Template Management

<details> <summary><b>Explore our template system</b></summary>

# Create a reusable template
template = create_template(
    name="Customer Support Agent",
    template="""
    You are a {company} support agent with {experience} of experience.
    
    Your responsibilities:
    - {primary_task}
    - {secondary_task}
    
    Communication style: {tone}
    
    Current context: {context}
    """,
    category="support",
    tags=["customer-service", "chatbot"]
)

# Use it across different scenarios
rendered = render_template(template, {
    "company": "TechCorp",
    "experience": "5 years",
    "primary_task": "Resolve technical issues",
    "secondary_task": "Ensure customer satisfaction",
    "tone": "Professional yet friendly",
    "context": "Black Friday sale period"
})

Features:

  • 🤖 AI-Generated Templates: Describe your need, get a template
  • 📊 Usage Analytics: Track which templates work best
  • 🔄 Version Control: Roll back to previous versions
  • 🧪 A/B Testing: Compare template performance

</details>

4. 🌐 Multi-Modal Context Support

<details> <summary><b>Beyond text - full multi-modal support</b></summary>

Handle complex, real-world scenarios:

# Create a multi-modal context
context = create_multimodal_context(
    text="Analyze this product image and create a description",
    images=["product_photo.jpg", "dimension_diagram.png"],
    documents=["product_specs.pdf"],
    metadata={
        "target_audience": "technical buyers",
        "tone": "professional",
        "length": "200-300 words"
    }
)

# Automatic optimization for each modality
optimized = await optimize_multimodal(context)

Supported formats:

  • 📝 Text: Markdown, plain text, code
  • 🖼️ Images: JPEG, PNG, WebP
  • 🎵 Audio: MP3, WAV (transcription)
  • 📹 Video: MP4 (frame extraction)
  • 📄 Documents: PDF, DOCX, XLSX

</details>

5. 🔌 Native MCP Integration

<details> <summary><b>Seamless Claude Desktop integration</b></summary>

// Just add to your Claude Desktop config:
{
  "mcpServers": {
    "context-engineering": {
      "command": "node",
      "args": ["./mcp-server/context_mcp_server.js"]
    }
  }
}

Then use natural language in Claude:

  • "Optimize my chatbot's context for clarity"
  • "Create a template for code review"
  • "Analyze why my AI responses are slow"
  • "Compare these two prompt strategies"

15 powerful tools at your fingertips!

</details>

📊 Real-World Performance Metrics

Based on production usage across 1000+ contexts:

<table> <tr> <th>Metric</th> <th>Before</th> <th>After</th> <th>Improvement</th> </tr> <tr> <td><b>Average Token Count</b></td> <td>2,547</td> <td>1,223</td> <td><b>52% reduction</b> 📉</td> </tr> <tr> <td><b>Response Time (p50)</b></td> <td>3.2s</td> <td>1.8s</td> <td><b>44% faster</b> ⚡</td> </tr> <tr> <td><b>Context Quality Score</b></td> <td>65/100</td> <td>92/100</td> <td><b>42% increase</b> 📈</td> </tr> <tr> <td><b>User Satisfaction (NPS)</b></td> <td>32</td> <td>71</td> <td><b>122% increase</b> 😊</td> </tr> <tr> <td><b>Template Reuse Rate</b></td> <td>12%</td> <td>78%</td> <td><b>550% increase</b> 🔄</td> </tr> <tr> <td><b>Monthly API Costs</b></td> <td>$4,230</td> <td>$2,028</td> <td><b>52% savings</b> 💰</td> </tr> </table>

🎬 Live Demo

<div align="center">

See it in action - Context Optimization

┌────────────────────────────────────────────────────┐
│                BEFORE OPTIMIZATION                  │
├────────────────────────────────────────────────────┤
│ Tokens: 2,547          Quality: 65/100      ❌     │
│ Cost: $0.051           Speed: 3.2s                 │
│                                                    │
│ Context:                                           │
│ "You are an AI assistant. You are helpful.        │
│  You should help users. When users ask you        │
│  questions, you should answer them helpfully..."   │
│                                                    │
│ Issues:                                            │
│ - High redundancy (42%)                           │
│ - Vague instructions                              │
│ - Poor structure                                  │
└────────────────────────────────────────────────────┘
                        ⬇️
              [🤖 AI OPTIMIZATION MAGIC]
                        ⬇️
┌────────────────────────────────────────────────────┐
│                 AFTER OPTIMIZATION                  │
├────────────────────────────────────────────────────┤
│ Tokens: 1,223          Quality: 92/100      ✅     │
│ Cost: $0.024           Speed: 1.8s                 │
│                                                    │
│ Context:                                           │
│ "You are a knowledgeable AI assistant providing   │
│  accurate, comprehensive answers. Focus on:        │
│  • Direct, actionable responses                   │
│  • Evidence-based information                     │
│  • Clear, structured explanations"                │
│                                                    │
│ Improvements:                                      │
│ ✓ 52% token reduction                            │
│ ✓ Clear role definition                          │
│ ✓ Specific guidelines                            │
└────────────────────────────────────────────────────┘

Real-time Dashboard Preview

┌─────────────────────────────────────────────────────┐
│          Context Engineering Dashboard               │
├─────────────────────────────────────────────────────┤
│                                                     │
│  Active Sessions: 24    Total Contexts: 1,847      │
│  Templates Used: 89     Optimizations: 3,201       │
│                                                     │
│  ┌─────────────────┐    ┌─────────────────┐       │
│  │ Quality Scores  │    │  Token Usage    │       │
│  │                 │    │                 │       │
│  │  92 ████████░   │    │  45% ████░░░░   │       │
│  │  87 ███████░░   │    │                 │       │
│  │  94 █████████   │    │  Saved: 2.3M    │       │
│  └─────────────────┘    └─────────────────┘       │
│                                                     │
│  Recent Optimizations:                              │
│  ├─ Customer Support Bot     -47% tokens ✅        │
│  ├─ Code Review Assistant    -52% tokens ✅        │
│  └─ Content Generator        -38% tokens ✅        │
│                                                     │
└─────────────────────────────────────────────────────┘

</div>

🏃 Quick Start

Get up and running in just 2 minutes:

Prerequisites

  • Python 3.10+ and Node.js 16+
  • Google Gemini API key (Get one free)

1️⃣ Clone and Configure (30 seconds)

# Clone the repository
git clone https://github.com/ShunsukeHayashi/context_-engineering_MCP.git
cd "context engineering_mcp_server"

# Set up environment
cp .env.example .env
echo "GEMINI_API_KEY=your_key_here" >> .env

2️⃣ Install and Launch (90 seconds)

# Option A: Quick start script (Recommended)
./quickstart.sh

# Option B: Manual setup
# Terminal 1 - Context Engineering API
cd context_engineering
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
python context_api.py

# Terminal 2 - MCP Server (for Claude Desktop)
cd mcp-server
npm install
node context_mcp_server.js

3️⃣ Your First Optimization (30 seconds)

# Run the example
python examples/quick_start.py

Or use the API directly:

# Create a session
curl -X POST http://localhost:9001/api/sessions \
  -H "Content-Type: application/json" \
  -d '{"name": "My First Session"}'

# Create and optimize a context
# ... (see examples/quick_start.py for full flow)

🎉 That's it! You're now optimizing AI contexts like a pro!

📚 Use Cases & Examples

🤖 AI Agent Development

<details> <summary><b>Build better AI agents with optimized contexts</b></summary>

# Create a specialized AI agent
agent_session = create_session("Customer Service Agent")
window = create_context_window(agent_session, max_tokens=4096)

# Add role-specific context
add_context_element(window, {
    "content": "You are Emma, a senior customer service specialist...",
    "type": "system",
    "priority": 10
})

# Add company knowledge
add_context_element(window, {
    "content": "Company policies: ...",
    "type": "system",
    "priority": 8
})

# Analyze and optimize
analysis = analyze_context(window)
if analysis.quality_score < 80:
    optimized = optimize_context(window, goals=["clarity", "relevance"])

Results: 40% faster response time, 85% customer satisfaction

</details>

💬 Chatbot Optimization

<details> <summary><b>Transform chatbot performance</b></summary>

# Before: Generic chatbot
old_prompt = "You are a chatbot. Answer questions."

# After: Optimized with templates
template = generate_template(
    purpose="Technical support chatbot for SaaS platform",
    examples=["User login issues", "API integration help"],
    constraints=["Max 2 paragraphs", "Include links to docs"]
)

# Deploy optimized version
optimized_bot = render_template(template, {
    "product": "CloudAPI Pro",
    "docs_url": "https://docs.cloudapi.com"
})

Results: 60% reduction in escalations, 2x faster resolution

</details>

📝 Content Generation

<details> <summary><b>Consistent, high-quality content at scale</b></summary>

# Create content generation templates
blog_template = create_template(
    name="Technical Blog Post",
    template="""Write a {word_count}-word blog post about {topic}.
    
    Target audience: {audience}
    Tone: {tone}
    Include: {requirements}
    
    SEO keywords: {keywords}
    """,
    category="content"
)

# Generate consistent content
for topic in topics:
    content = generate_with_template(blog_template, {
        "topic": topic,
        "word_count": 1500,
        "audience": "developers",
        "tone": "informative yet engaging",
        "requirements": ["code examples", "best practices"],
        "keywords": ["API", "integration", "tutorial"]
    })

Results: 5x content output, consistent quality scores >90%

</details>

🔬 Research Assistant

<details> <summary><b>Handle complex research tasks efficiently</b></summary>

# Multi-modal research context
research_context = create_multimodal_context(
    text="Analyze market trends for electric vehicles",
    documents=["market_report_2024.pdf", "competitor_analysis.xlsx"],
    images=["sales_charts.png", "technology_roadmap.jpg"],
    metadata={
        "focus_areas": ["battery technology", "charging infrastructure"],
        "output_format": "executive summary with recommendations"
    }
)

# Optimize for comprehensive analysis
optimized = optimize_multimodal(research_context, 
    goals=["completeness", "actionable_insights"])

Results: 70% time savings, 95% accuracy in insights

</details>

🏗️ Architecture

<div align="center">

graph TB
    subgraph "Client Layer"
        A[Claude Desktop]
        B[Web Dashboard]
        C[API Clients]
    end
    
    subgraph "MCP Server"
        D[MCP Protocol Handler]
        E[15 Context Tools]
    end
    
    subgraph "Context Engineering Core"
        F[Session Manager]
        G[Context Windows]
        H[Analysis Engine]
        I[Optimization Engine]
        J[Template Manager]
    end
    
    subgraph "AI Layer"
        K[Gemini 2.0 Flash]
        L[Semantic Analysis]
        M[Content Generation]
    end
    
    subgraph "Storage"
        N[(Context Store)]
        O[(Template Library)]
        P[(Analytics DB)]
    end
    
    A -->|MCP Protocol| D
    B -->|WebSocket| F
    C -->|REST API| F
    
    D --> E
    E --> F
    
    F --> G
    G --> H
    H --> I
    G --> J
    
    H --> K
    I --> K
    J --> K
    
    K --> L
    K --> M
    
    G --> N
    J --> O
    H --> P
    
    style A fill:#e1f5fe
    style B fill:#e1f5fe
    style C fill:#e1f5fe
    style K fill:#fff3e0
    style N fill:#f3e5f5
    style O fill:#f3e5f5
    style P fill:#f3e5f5

</div>

Component Overview

  • 🔌 MCP Server: Native Claude Desktop integration with 15 specialized tools
  • 🧠 Analysis Engine: AI-powered context quality evaluation
  • ⚡ Optimization Engine: Multi-strategy context improvement
  • 📋 Template Manager: Reusable prompt components with versioning
  • 💾 Storage Layer: Efficient context and template persistence
  • 📊 Analytics: Real-time metrics and usage tracking

🛠️ Advanced Features

Automatic Context Optimization

# Let AI decide the best optimization strategy
result = await auto_optimize_context(window_id)

# AI analyzes and applies:
# - Token reduction (if verbose)
# - Clarity enhancement (if ambiguous)  
# - Structure improvement (if disorganized)
# - Relevance boosting (if unfocused)

RAG Integration

# Combine retrieval with context engineering
rag_context = create_rag_context(
    query="How to implement OAuth2?",
    documents=knowledge_base.search("OAuth2"),
    max_tokens=2000
)

# Automatic relevance ranking and summarization
optimized_rag = optimize_rag_context(rag_context)

Workflow Automation

# Define context engineering workflows
workflow = create_workflow(
    name="Daily Report Generator",
    steps=[
        ("fetch_data", {"source": "analytics_api"}),
        ("create_context", {"template": "daily_report"}),
        ("optimize", {"goals": ["brevity", "clarity"]}),
        ("generate", {"model": "gpt-4"})
    ]
)

# Execute automatically
schedule_workflow(workflow, cron="0 9 * * *")

📊 API Reference

Core Endpoints

<details> <summary><b>Context Management APIs</b></summary>

Session Management

POST   /api/sessions              # Create new session
GET    /api/sessions              # List all sessions
GET    /api/sessions/{id}         # Get session details
DELETE /api/sessions/{id}         # Delete session

Context Windows

POST   /api/sessions/{id}/windows # Create context window
GET    /api/contexts/{id}         # Get context details
POST   /api/contexts/{id}/elements # Add context element
DELETE /api/contexts/{id}/elements/{elem_id} # Remove element

Analysis & Optimization

POST   /api/contexts/{id}/analyze # Analyze context quality
POST   /api/contexts/{id}/optimize # Optimize with goals
POST   /api/contexts/{id}/auto-optimize # AI-driven optimization
GET    /api/optimization/{task_id} # Check optimization status

Template Management

POST   /api/templates             # Create template
POST   /api/templates/generate    # AI-generate template
GET    /api/templates             # List templates
GET    /api/templates/{id}        # Get template
POST   /api/templates/{id}/render # Render with variables
PUT    /api/templates/{id}        # Update template
DELETE /api/templates/{id}        # Delete template

</details>

MCP Tools

<details> <summary><b>Available Claude Desktop Tools</b></summary>

// Context Engineering Tools
- create_context_session(name, description)
- create_context_window(session_id, max_tokens)
- add_context_element(window_id, content, type, priority)
- analyze_context(window_id)
- optimize_context(window_id, goals)
- auto_optimize_context(window_id)
- get_context_stats()

// Template Management Tools  
- create_prompt_template(name, template, category)
- generate_prompt_template(purpose, examples)
- list_prompt_templates(category, tags)
- render_template(template_id, variables)

// AI Guides Tools (Bonus)
- list_ai_guides()
- search_ai_guides(query)
- search_guides_with_gemini(query)
- analyze_guide(title)

</details>

🚀 Deployment

Docker Deployment

# Production build
docker build -t context-engineering:latest .

# Run with docker-compose
docker-compose up -d

# Scale horizontally
docker-compose up -d --scale api=3

Cloud Deployment

<details> <summary><b>Deploy to AWS/GCP/Azure</b></summary>

AWS ECS

# Build and push to ECR
aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_URI
docker build -t context-engineering .
docker tag context-engineering:latest $ECR_URI/context-engineering:latest
docker push $ECR_URI/context-engineering:latest

# Deploy with CloudFormation
aws cloudformation create-stack --stack-name context-engineering \
  --template-body file://aws/ecs-stack.yaml

Google Cloud Run

# Build and deploy
gcloud builds submit --tag gcr.io/$PROJECT_ID/context-engineering
gcloud run deploy context-engineering \
  --image gcr.io/$PROJECT_ID/context-engineering \
  --platform managed \
  --allow-unauthenticated

Kubernetes

# Apply manifests
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl apply -f k8s/ingress.yaml

</details>

Production Considerations

  • 🔒 Security: API key management, rate limiting
  • 📈 Scaling: Horizontal scaling for API servers
  • 💾 Persistence: PostgreSQL for production storage
  • 📊 Monitoring: Prometheus + Grafana integration
  • 🔄 CI/CD: GitHub Actions workflows included

🤝 Contributing

We love contributions! See CONTRIBUTING.md for guidelines.

Priority Areas

  • 🌍 Internationalization: More language support
  • 🧪 Testing: Increase coverage to 90%+
  • 📚 Documentation: More examples and tutorials
  • 🔌 Integrations: OpenAI, Anthropic, Cohere APIs
  • 🎨 UI/UX: Dashboard improvements

Development Setup

# Clone your fork
git clone https://github.com/YOUR_USERNAME/context_-engineering_MCP.git

# Install dev dependencies
pip install -r requirements-dev.txt
npm install --save-dev

# Run tests
pytest --cov=. --cov-report=html
npm test

# Format code
black .
npm run lint:fix

📈 Success Stories

"We reduced our GPT-4 costs by 60% while improving response quality. This platform paid for itself in the first week."
Sarah Chen, CTO at TechStartup

"Context Engineering transformed how we build AI features. What took days now takes hours."
Michael Rodriguez, AI Lead at Fortune 500

"The template system alone saved us 100+ engineering hours per month."
Emma Watson, Director of Engineering

🔮 Roadmap

Q1 2025

  • [ ] Cloud-native deployment options
  • [ ] Team collaboration features
  • [ ] Advanced caching strategies
  • [ ] GraphQL API support

Q2 2025

  • [ ] Visual context builder
  • [ ] A/B testing framework
  • [ ] Cost prediction models
  • [ ] Enterprise SSO

Q3 2025

  • [ ] Multi-tenant architecture
  • [ ] Compliance certifications
  • [ ] Advanced analytics
  • [ ] Mobile SDKs

📚 Resources

📄 License

MIT License - see LICENSE for details.

🙏 Acknowledgments

Built with ❤️ using:


<div align="center">

⭐ Star us on GitHub to support the project!

<a href="https://github.com/ShunsukeHayashi/context_-engineering_MCP/stargazers"> <img src="https://img.shields.io/github/stars/ShunsukeHayashi/context_-engineering_MCP?style=social" alt="GitHub stars"> </a>

<a href="https://github.com/ShunsukeHayashi/context_-engineering_MCP/network/members"> <img src="https://img.shields.io/github/forks/ShunsukeHayashi/context_-engineering_MCP?style=social" alt="GitHub forks"> </a>

<h4>Made with ❤️ by developers, for developers</h4>

</div>

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured