Espen-MCP-server-d6

nieuwoudt/Espen-MCP-server-d6

3.2

If you are the rightful owner of Espen-MCP-server-d6 and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Espen D6 MCP Server is a multi-tenant Model Context Protocol server that integrates Espen.ai with the D6 School Information System, providing a standardized API for educational data.

Tools
  1. get_schools

    List authorized schools

  2. get_learners

    Get learners with academic data

  3. get_learner_marks

    Get marks for specific learner

  4. get_staff

    Get school staff information

  5. get_parents

    Get parent/guardian data

  6. get_lookup_data

    Get reference data (grades, languages, etc.)

  7. get_system_health

    Check D6 integration status

๐Ÿง  Espen D6 MCP Server

Production-ready MCP (Model Context Protocol) server integrating AI models with D6 School Information System

TypeScript Node.js Vercel

๐Ÿš€ DEPLOYMENT READY - Production Status

โœ… LIVE DATA: Currently serving 1,270 learners, 73 staff, and 1,523 parents from D6 production API
โœ… 8 MCP TOOLS: All tools functional and tested
โœ… VERCEL READY: Deploy in 5 minutes with one command
โœ… D6 INTEGRATION: Successfully connected to D6 test school (Integration 1694)

|

๐ŸŽฏ Overview

This MCP server provides AI models with direct access to D6 School Information System data, enabling natural language queries about students, staff, parents, and academic records. Built with the official Vercel MCP adapter for seamless cloud deployment.

Key Features

  • ๐Ÿซ Real D6 Data - Live production data from D6 test school
  • โšก 8 MCP Tools - Comprehensive school data access
  • ๐Ÿ” Production Security - Enterprise-grade D6 API authentication
  • ๐Ÿ“Š Rich Context - Student records, staff info, parent data
  • ๐Ÿ”„ Hybrid Mode - Automatic fallback between real and mock data
  • ๐Ÿš€ Vercel Ready - One-command deployment with official MCP adapter

๐Ÿ“‹ Table of Contents

๐Ÿš€ Quick Start

๐ŸŽฏ 5-Minute Deployment (Recommended)

Deploy to Vercel with real D6 data:

# Clone and deploy
git clone https://github.com/espen-ai/espen-d6-mcp-server.git
cd espen-d6-mcp-server
npm install
vercel --prod

Then configure in your MCP client:

{
  "mcpServers": {
    "espen-d6": {
      "url": "https://your-domain.vercel.app/api/mcp"
    }
  }
}

โžก๏ธ

๐Ÿง  Local Development

Start MCP server locally:

# Clone the repository
git clone https://github.com/espen-ai/espen-d6-mcp-server.git
cd espen-d6-mcp-server

# Install dependencies
npm install

# Start with sandbox data (no D6 credentials needed)
D6_SANDBOX_MODE=true npm run mcp

# Or start with real D6 data
npm run mcp

Configure in your MCP client (Claude Desktop, etc.):

{
  "mcpServers": {
    "espen-d6": {
      "command": "npm",
      "args": ["run", "mcp"],
      "cwd": "/path/to/espen-d6-mcp-server",
      "env": {
        "D6_SANDBOX_MODE": "true"
      }
    }
  }
}

๐Ÿ” Available MCP Tools (8 Total)

ToolDescriptionLive Data Status
get_schoolsSchool informationโœ… 1 D6 school
get_learnersStudent dataโœ… 1,270 students
get_staffStaff informationโœ… 73 staff members
get_parentsParent dataโœ… 1,523 parents
get_learner_marksAcademic marks๐Ÿ”’ Pending D6 activation
get_lookup_dataReference dataโœ… Genders, grades
get_system_healthAPI health statusโœ… Live monitoring
get_integration_infoIntegration detailsโœ… Real D6 setup

Prerequisites

  • Node.js 18+
  • PostgreSQL (or Supabase account)
  • Redis (optional, for caching)
  • D6 School Information System access

Installation

# Copy environment template
cp env.example .env

# Configure your environment variables
# Edit .env with your Supabase, D6, and Redis credentials

# Run database migrations
npm run db:migrate

# Start development server
npm run dev

Environment Setup

Copy env.example to .env and configure:

# Supabase Configuration
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your-supabase-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-supabase-service-role-key

# D6 API Configuration  
D6_API_BASE_URL=https://your-school.d6.co.za/api
D6_API_USERNAME=your-d6-username
D6_API_PASSWORD=your-d6-password

# Server Configuration
PORT=3000
JWT_SECRET=your-super-secret-jwt-key

๐Ÿ—๏ธ Architecture

graph TB
    A[EspenTutor/Teacher/Parent] --> B[MCP Server]
    B --> C[Fastify API]
    C --> D[Auth Middleware]
    C --> E[Tenant Scoping]
    C --> F[Rate Limiting]
    
    C --> G[Context Builder]
    G --> H[Cache Manager]
    G --> I[D6 Client]
    G --> J[Supabase Client]
    
    I --> K[D6 School System]
    J --> L[Supabase Database]
    H --> M[Redis Cache]
    
    subgraph "Data Layer"
        L --> N[Learners]
        L --> O[Marks]
        L --> P[Attendance]
        L --> Q[Discipline]
        L --> R[Context Cache]
    end

๐Ÿ”Œ API Endpoints

Context API

GET /context/:userId

Retrieves comprehensive context for a user (learner, teacher, or parent).

Parameters:

  • userId - User identifier
  • role - User role (learner/teacher/parent)
  • forceRefresh - Skip cache (optional)

Response:

{
  "success": true,
  "data": {
    "id": "learner-123",
    "firstName": "John",
    "lastName": "Doe",
    "academic": {
      "overallAverage": 78.5,
      "subjects": [...],
      "trends": {...}
    },
    "attendance": {...},
    "discipline": {...},
    "insights": {...}
  },
  "cached": true,
  "generatedAt": "2024-01-15T10:30:00Z"
}

Sync API

POST /sync/d6

Manually trigger D6 data synchronization.

GET /sync/status

Get synchronization status and logs.

Health Check

GET /health

Server health and status information.

โš™๏ธ Configuration

Cache TTL Settings

# Context cache (5 minutes)
CACHE_TTL_CONTEXT=300

# Learner data (30 minutes)  
CACHE_TTL_LEARNER_DATA=1800

# Marks data (15 minutes)
CACHE_TTL_MARKS=900

Sync Configuration

# Sync interval (15 minutes)
SYNC_INTERVAL_MINUTES=15

# Retry attempts for failed requests
SYNC_RETRY_ATTEMPTS=3

# Batch size for bulk operations
SYNC_BATCH_SIZE=100

๐Ÿ’ป Development

Scripts

# Development with hot reload
npm run dev

# Build for production
npm run build

# Run tests
npm run test

# Run tests with coverage
npm run test:coverage

# Lint code
npm run lint

# Format code
npm run format

# Type checking
npm run type-check

Project Structure

src/
โ”œโ”€โ”€ api/          # API route handlers
โ”œโ”€โ”€ services/     # Business logic services
โ”œโ”€โ”€ middleware/   # Express middleware
โ”œโ”€โ”€ db/           # Database client and migrations
โ”œโ”€โ”€ utils/        # Utility functions
โ”œโ”€โ”€ types/        # TypeScript type definitions
โ””โ”€โ”€ tests/        # Test files

๐Ÿงช Testing

Running Tests

# Unit tests
npm run test

# Integration tests
npm run test:integration

# Watch mode
npm run test:watch

# Coverage report
npm run test:coverage

Test Structure

  • Unit Tests - Individual function testing
  • Integration Tests - API endpoint testing
  • E2E Tests - Full workflow testing

๐Ÿš€ Deployment

Vercel Deployment

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel

# Production deployment
vercel --prod

Environment Variables

Configure these in your deployment platform:

  • SUPABASE_URL
  • SUPABASE_SERVICE_ROLE_KEY
  • D6_API_BASE_URL
  • D6_API_USERNAME
  • D6_API_PASSWORD
  • JWT_SECRET
  • REDIS_URL (optional)

Database Setup

  1. Create Supabase project
  2. Run the enhanced schema from src/db/schema.sql
  3. Configure Row-Level Security policies
  4. Set up automated backups

๐Ÿ“Š Performance

Benchmarks

  • Context API: < 200ms (cached), < 500ms (uncached)
  • D6 Sync: ~1000 records/minute
  • Concurrent Users: 1000+ per school
  • Cache Hit Rate: > 85%

Monitoring

  • Response time tracking
  • Error rate monitoring
  • Cache performance metrics
  • Database query optimization

๐Ÿ” Security

Features

  • JWT-based authentication
  • Row-Level Security (RLS)
  • Tenant data isolation
  • Rate limiting
  • Input validation
  • SQL injection prevention

Best Practices

  • Regular security audits
  • Dependency updates
  • Environment variable encryption
  • API key rotation

๐Ÿ“– API Documentation

Full API documentation is available at /docs when running the development server.

Authentication

# Get JWT token
curl -X POST /auth/login \\
  -H "Content-Type: application/json" \\
  -d '{"username":"user@school.com","password":"password"}'

# Use token in requests
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \\
  /context/learner-123?role=learner

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Ensure all tests pass
  6. Submit a pull request

Code Standards

  • ESLint configuration
  • Prettier formatting
  • TypeScript strict mode
  • 100% test coverage for critical paths

๐Ÿ“„ License

This project is licensed under the MIT License - see the file for details.

๐Ÿ™‹โ€โ™‚๏ธ Support

๐ŸŽญ Sandbox Mode

The Espen D6 MCP Server includes a comprehensive Sandbox Mode with realistic mock data, perfect for development, testing, and demos without requiring D6 API credentials or school authorizations.

Features

โœ… Realistic South African School Data - Authentic names, languages, and educational structure
โœ… Complete API Coverage - All endpoints work with mock data
โœ… Instant Responses - No network delays or API rate limits
โœ… Offline Development - Works without internet connection
โœ… Consistent Testing - Predictable data for reliable tests
โœ… No Credentials Required - Start developing immediately

Mock Data Available

  • ๐Ÿซ Schools: 3 mock schools with different API access levels
  • ๐Ÿ‘จโ€๐ŸŽ“ Learners: Diverse student data across multiple grades
  • ๐Ÿ‘จโ€๐Ÿซ Staff: Teachers and administrators with subjects
  • ๐Ÿ‘ช Parents: Parent contacts with relationships
  • ๐Ÿ“Š Marks: Academic performance data across subjects
  • ๐Ÿ“‹ Lookups: Genders, grades, languages, ethnic groups

Quick Start with Sandbox

# Demo the mock data
npm run demo:sandbox

# Or see it in action
node scripts/demo-sandbox.js

Enabling Sandbox Mode

Method 1: Environment Variables
export NODE_ENV=development
export D6_SANDBOX_MODE=true
npm run dev
Method 2: Code Configuration
const d6Service = D6ApiServiceHybrid.getInstance({
  baseUrl: 'https://integrate.d6plus.co.za/api/v2',
  username: 'any', // Not used in sandbox mode
  password: 'any', // Not used in sandbox mode  
  enableMockData: true,
  useMockDataFirst: true, // Forces sandbox mode
});

Dynamic Mode Switching

// Switch to sandbox mode
d6Service.setSandboxMode(true);

// Switch back to production (if APIs available)
d6Service.setSandboxMode(false);

// Check current mode
const info = d6Service.getClientInfo();
console.log(`Current mode: ${info.mode}`); // 'sandbox', 'production', or 'hybrid'

Sample Mock Data

The sandbox includes realistic South African educational data:

Schools:

  • Greenwood Primary School (Admin+ API)
  • Riverside High School (Curriculum+ API)
  • Sunnydale Academy (Finance+ API)

Learners:

  • Amara Ngcobo (Grade 7, Zulu)
  • Liam Van Der Merwe (Grade 8, Afrikaans)
  • Kgothatso Molefe (Grade 9, Setswana)

Staff:

  • Patricia Mthembu (Mathematics Teacher)
  • David Williams (English Teacher)

API Response Format

All sandbox responses follow the same format as production D6 APIs:

// Learners endpoint
const learners = await d6Service.getLearners(1001);
// Returns: D6Learner[] with proper field mapping

// Marks endpoint  
const marks = await d6Service.getMarks(2001);
// Returns: D6Mark[] with realistic academic data

// Health check shows sandbox status
const health = await d6Service.healthCheck();
// Returns: { status: 'degraded', mock_data_available: true, ... }

Perfect For

  • ๐Ÿš€ Rapid Prototyping - Start building immediately
  • ๐Ÿงช Testing - Consistent data for unit/integration tests
  • ๐Ÿ“š Learning - Explore D6 API structure without credentials
  • ๐ŸŽฏ Demos - Show functionality without real school data
  • ๐Ÿ”ง Development - Build features before D6 integration approval

Production vs Sandbox

FeatureProductionSandbox
Data SourceReal D6 APIsMock data service
Network Requiredโœ… YesโŒ No
Credentialsโœ… RequiredโŒ Optional
Rate Limitsโœ… YesโŒ No
School Authorizationโœ… RequiredโŒ No
Response Time~200-500ms~1-5ms
Data Consistencyโš ๏ธ Changesโœ… Consistent

Hybrid Fallback

The service automatically falls back to sandbox mode when:

  • D6 APIs are unavailable
  • Network connectivity issues
  • Authentication failures
  • Rate limits exceeded
// Automatic fallback sequence:
// 1. Try D6 v2 API
// 2. Try D6 v1 API  
// 3. Use mock data (if enabled)
// 4. Throw error (if mock disabled)

Built with โค๏ธ by the Espen.ai team