Anmol369/Pattern-Learning-MCP-Server
If you are the rightful owner of Pattern-Learning-MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The Pattern Learning MCP Server is designed to enhance AI code generation by learning from developer corrections, significantly reducing verification time.
🎯 Pattern Learning MCP Server - Demo
A demonstration of verification time reduction through pattern learning for AI code generation
📋 Overview
This demo showcases how an MCP (Model Context Protocol) server can help AI agents like Goose learn from developer corrections, reducing verification time from 20 minutes to 2 minutes (90% reduction).
The Problem
- AI generates code with security vulnerabilities
- Developers spend significant time reviewing and fixing
- Same mistakes happen repeatedly
The Solution
- Store correction patterns when developers fix AI-generated code
- Retrieve and apply these patterns in future code generation
- Reduce verification time dramatically
🚀 Quick Start
1. Install Dependencies
cd pattern-learning-demo
pip install -r requirements.txt
2. Run the Demo
Option A: Python Script (Recommended for Windows)
python demo_script.py
Option B: Bash Script (Linux/Mac)
chmod +x demo_script.sh
./demo_script.sh
3. Test the MCP Server
python mcp_server.py
The server will start and initialize the pattern database with security patterns.
📊 Demo Flow
Before Pattern Learning (Attempt 1)
- Developer asks: "Create Flask login endpoint"
- Goose generates code with timing attack vulnerability (
password == stored_password) - Developer spends 20 minutes reviewing and fixing
- Pattern stored in database
After Pattern Learning (Attempt 2)
- Developer asks: "Create Flask login endpoint" (same prompt)
- Goose calls MCP server to get security patterns
- Goose generates code with
secrets.compare_digest()from the start - Developer verifies in 2 minutes
- 90% time reduction achieved
🏗️ Architecture
┌─────────────────────────────────────────┐
│ GOOSE AGENT │
│ (calls MCP tools via JSON-RPC) │
└───────────────┬─────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ PATTERN LEARNING MCP SERVER │
│ │
│ Tools: │
│ • get_security_patterns() │
│ • validate_code_security() │
│ • store_correction_pattern() │
│ • get_database_stats() │
└───────────────┬─────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ SQLite Pattern Database │
│ (patterns.db) │
└─────────────────────────────────────────┘
🔧 Components
1. pattern_db.py - Database Layer
- SQLite-based pattern storage
- Bayesian confidence scoring
- Pattern retrieval and statistics
2. security_patterns.py - Pattern Definitions
- Pre-defined security patterns
- Vulnerability detection (regex-based)
- Context-aware recommendations
3. mcp_server.py - MCP Server
- Exposes tools via MCP protocol
- Handles pattern storage and retrieval
- Integrates with Goose
4. demo_script.py - Interactive Demo
- Shows before/after comparison
- Visualizes time savings
- Demonstrates the value proposition
📈 Results
| Metric | Before | After | Improvement |
|---|---|---|---|
| Generation Time | 30 sec | 30 sec | - |
| Verification Time | 20 min | 2 min | 90% |
| Vulnerabilities | 1 (HIGH) | 0 | 100% |
| Developer Confidence | Low | High | ✅ |
🎯 Key Features
✅ Automatic Pattern Learning - Learns from every correction ✅ Context-Aware - Recommends patterns based on task type ✅ Confidence Scoring - Bayesian updates strengthen patterns over time ✅ Multiple Categories - Security, performance, style, etc. ✅ MCP Integration - Works seamlessly with Goose ✅ Zero Configuration - SQLite, no external database needed
🔒 Security Patterns Included
-
Timing Attack Prevention
- Detects:
password == stored_password - Fix:
secrets.compare_digest(password, stored_password)
- Detects:
-
SQL Injection Prevention
- Detects: String formatting in SQL queries
- Fix: Parameterized queries
-
Hardcoded Secrets Detection
- Detects:
API_KEY = "secret123" - Fix:
os.environ.get("API_KEY")
- Detects:
-
Insecure Random Prevention
- Detects:
random.randint() - Fix:
secrets.token_hex()
- Detects:
🧪 Testing
# Run tests (when implemented)
pytest tests/
📝 Configuration for Goose
To use this MCP server with Goose, add to your Goose configuration:
{
"mcp_servers": {
"pattern-learning": {
"command": "python",
"args": ["C:/Users/aadis/goose-pattern-demo/pattern-learning-demo/mcp_server.py"]
}
}
}
🎬 Demo Script Output
The demo shows:
- Attempt 1 - Vulnerable code generation and 20-minute fix
- Pattern Storage - Correction saved to database
- Attempt 2 - Secure code generated automatically
- Results - Time savings and metrics
💡 Future Enhancements
- AST-based vulnerability detection (more accurate)
- Vector embeddings for pattern similarity search
- Multi-agent coordination
- Autonomous prompt evolution
- Community pattern sharing
- Performance pattern categories
- Style guide enforcement
📞 Support
For questions or issues:
- Email: your-email@example.com
- GitHub: your-github-username
📄 License
MIT License - Feel free to use and modify
Built for the Goose Grant Interview
Demonstrating verification time reduction through experiential learning.