🧠 MCP Context Engine

A minimal context-aware middleware that bridges real-world data (like your calendar) to AI systems — enabling intelligent, time-aware responses and decisions.


🚀 Inspiration

I wanted to explore how AI agents can reason with real-world signals like user schedules, meetings, and time zones — similar to how the Model Context Protocol (MCP) aims to unify AI context access.
The goal was to build something small but production-grade, showing how a model could answer:

“Am I free tomorrow morning for a 45-minute meeting?”

This led to the creation of a lightweight context provider API that reads .ics calendar data, interprets natural-language queries, and returns structured JSON context — ready for AI reasoning.


🧩 How I Built It

The system was designed with a layered FastAPI architecture, emphasizing modularity and extensibility.

⚙️ Core Design

  • FastAPI for high-performance async API endpoints
  • httpx for external data fetching
  • icalendar for robust .ics parsing
  • pydantic-settings for environment configuration
  • dateutil / tzdata for accurate timezone conversion

🧱 Milestones

Milestone Description
M0 FastAPI scaffold with config, logging, and error handling
M1 Health & diagnostics routes
M2 Google Calendar (ICS) provider with event parsing and diagnostics
M3 Natural-language availability + slot suggestion engine ✅

🧠 What I Learned

  • How MCP-like context protocols structure metadata for LLMs
  • Parsing and normalizing ICS calendar data for time-based reasoning
  • Handling time zone consistency in scheduling logic
  • Designing natural language interfaces to structured time data
  • Writing clean modular FastAPI services that scale

💡 Challenges Faced

  • Parsing and interpreting recurring events from .ics data
  • Aligning human time expressions (like “tomorrow morning”) with concrete UTC timestamps
  • Managing time zone drift between calendar and query input
  • Building a natural-language slot finder that respects event overlaps and buffer windows

🧮 Example Queries

Query Output
“Am I free tomorrow at 03:10?” {"busy": true, "event": "Daily Sync"}
“Any slot tomorrow morning for 45 min?” {"start": "09:30", "end": "10:15"}

🧰 Tech Stack

  • Backend: FastAPI, Uvicorn
  • Parsing: icalendar, dateutil
  • Networking: httpx
  • Environment: pydantic-settings, dotenv
  • Testing: pytest, curl / Swagger

📸 Screenshots

🧭 Swagger Home

Swagger Home

📅 Busy Check

Calendar Busy

⏰ Slot Suggestion

Calendar Slot


🧾 Example: Slot Suggestion Logic (LaTeX)

The slot engine computes free intervals by taking the complement of all busy periods within a given time window:

[ \text{Free Slots} = \text{All Slots} \setminus \text{Busy Intervals} ]

For a 45-minute duration ( d ), the algorithm searches:

[ \exists\, t \in [t_\text{start}, t_\text{end}] \;\text{s.t.}\; (t, t + d) \cap \text{Busy} = \emptyset ]


🌟 Summary

The MCP Context Engine demonstrates how AI systems can connect with live human context — like schedules and time — through a simple yet powerful middleware layer.
It’s a step toward contextually intelligent AI, capable of reasoning not just with data, but with your world.

Built With

Share this project:

Updates