Skip to main content
Glama
README.md
# ๐Ÿ—“๏ธ AI Calendar Assistant

> Personal calendar management powered by **local LLM** (Ollama), **Google Calendar API**, and **Model Context Protocol (MCP)**

[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Ollama](https://img.shields.io/badge/Ollama-llama3.2-green.svg)](https://ollama.com/)
[![MCP](https://img.shields.io/badge/MCP-Compatible-purple.svg)](https://modelcontextprotocol.io/)

A lightweight, privacy-first AI calendar assistant that runs entirely on your local machine. Chat with your calendar using natural language, powered by **Llama 3.2** running locally via **Ollama** - completely free, no API costs.

![Demo](https://img.shields.io/badge/Status-Working-brightgreen)

---

## โœจ Features

- ๐Ÿค– **Local AI** - Uses Ollama (llama3.2:3b) running on your machine
- ๐Ÿ“… **Google Calendar Integration** - Full read/write access via OAuth2
- ๐Ÿ’ฌ **Natural Language** - Ask questions in plain English
- โšก **Fast** - Responses in 1-2 seconds
- ๐Ÿ”’ **Privacy-First** - LLM runs locally, only calendar sync requires internet
- ๐Ÿ†“ **100% Free** - No API costs, no subscriptions
- ๐Ÿ”Œ **MCP Compatible** - Integrates with Claude Desktop and other MCP clients
- ๐ŸŽจ **Beautiful CLI** - Rich terminal interface with color and formatting

---

## ๐Ÿ—๏ธ Architecture

```
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     MCP Client for Ollama (ollmcp)             โ”‚
โ”‚               Terminal UI - Natural Language Interface          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚                      โ”‚
                  โ”‚ (MCP Protocol)       โ”‚ (Ollama API)
                  โ”‚                      โ”‚
                  โ–ผ                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Calendar MCP Server        โ”‚  โ”‚   Ollama                   โ”‚
โ”‚   (calendar_server.py)       โ”‚  โ”‚   Llama 3.2 3B             โ”‚
โ”‚                              โ”‚  โ”‚   (Local LLM)              โ”‚
โ”‚   Exposes 7 Calendar Tools:  โ”‚  โ”‚                            โ”‚
โ”‚   โ€ข list_events              โ”‚  โ”‚   Handles:                 โ”‚
โ”‚   โ€ข get_today_events         โ”‚  โ”‚   โ€ข Intent parsing         โ”‚
โ”‚   โ€ข create_event             โ”‚  โ”‚   โ€ข Natural language       โ”‚
โ”‚   โ€ข search_events            โ”‚  โ”‚   โ€ข Response generation    โ”‚
โ”‚   โ€ข update_event             โ”‚  โ”‚   โ€ข Tool orchestration     โ”‚
โ”‚   โ€ข delete_event             โ”‚  โ”‚                            โ”‚
โ”‚   โ€ข check_availability       โ”‚  โ”‚                            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
              โ”‚
              โ”‚ (Google Calendar API)
              โ”‚
              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   GoogleCalendarClient       โ”‚
โ”‚   โ€ข OAuth2 Authentication    โ”‚
โ”‚   โ€ข Event CRUD Operations    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
              โ”‚
              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      Google Calendar         โ”‚
โ”‚      (Cloud Storage)         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

**Flow:**
1. You type natural language โ†’ MCP Client (ollmcp)
2. Ollama (Llama 3.2) understands intent and determines which MCP tools to call
3. MCP Client calls appropriate calendar tools via MCP protocol
4. Calendar MCP Server executes Google Calendar operations
5. Response flows back through MCP โ†’ Ollama โ†’ formatted natural language response

---

## ๐Ÿš€ Quick Start

### Prerequisites

- Python 3.8+
- macOS, Linux, or Windows
- Google account
- 4GB RAM (for local LLM)

### Installation

1. **Install Ollama**
   ```bash
   # macOS
   brew install ollama

   # Start Ollama service
   ollama serve

   # Pull the model (in a new terminal)
   ollama pull llama3.2:3b
   ```

2. **Clone & Setup**
   ```bash
   git clone https://github.com/othmane-zizi-pro/ai-calendar-assistant.git
   cd ai-calendar-assistant
   pip install -r requirements.txt
   ```

3. **Get Google Calendar Credentials**
   - Go to [Google Cloud Console](https://console.cloud.google.com/)
   - Create a new project
   - Enable "Google Calendar API"
   - Create OAuth 2.0 credentials (Desktop app)
   - Download JSON and save as `credentials.json`
   - See [detailed setup guide](SETUP.md)

4. **Install MCP Client for Ollama**
   ```bash
   pip install mcp-client-for-ollama
   ```

5. **Run - Start Natural Language Calendar Chat**
   ```bash
   # First run - authenticate with Google (this will open browser)
   python run_calendar_server.py  # Test server once, then Ctrl+C

   # Start interactive MCP chat with Ollama
   ollmcp --servers-json ollmcp_config.json --model llama3.2:3b
   ```

---

## ๐Ÿ’ก Usage

### Interactive MCP-Powered Chat

```bash
# Start the MCP client with Ollama
ollmcp --servers-json ollmcp_config.json --model llama3.2:3b
```

**Example conversation:**
```
You: What's on my calendar today?
AI: Let me check your calendar for today...
    [Calls get_today_events tool via MCP]

    You have 3 events scheduled today:
    1. Team Standup at 9:00 AM
    2. Client Meeting at 2:00 PM
    3. Gym Session at 6:00 PM

You: Create a meeting tomorrow at 3pm for 1 hour called "Project Review"
AI: I'll create that event for you...
    [Calls create_event tool via MCP]

    โœ… Done! Event "Project Review" scheduled for tomorrow 3:00 PM - 4:00 PM

You: Am I free on Friday afternoon?
AI: Let me check your availability...
    [Calls check_availability tool via MCP]

    Yes, you're free after 2:00 PM on Friday!
```

### Available MCP Tools

The calendar MCP server exposes these tools (automatically used by Ollama through the MCP client):

- **list_events** - Get upcoming calendar events
- **get_today_events** - Retrieve today's schedule
- **create_event** - Create new calendar event
- **search_events** - Search events by keyword
- **update_event** - Modify existing event
- **delete_event** - Remove event from calendar
- **check_availability** - Check if time slot is free

### Alternative: Use with Claude Desktop

If you prefer using Claude Desktop instead of the local Ollama setup:

Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "calendar": {
      "command": "python3",
      "args": ["run_calendar_server.py"],
      "cwd": "/path/to/ai-calendar-assistant"
    }
  }
}
```

Restart Claude Desktop - now Claude can access your calendar via MCP!

---

## ๐Ÿ› ๏ธ Technical Stack

### Core Technologies

| Component | Technology | Purpose |
|-----------|-----------|---------|
| **MCP Client** | mcp-client-for-ollama (ollmcp) | Bridges Ollama with MCP servers, terminal UI |
| **Local LLM** | Ollama (Llama 3.2 3B) | Natural language understanding, intent parsing, tool orchestration |
| **MCP Server** | Model Context Protocol SDK | Exposes calendar tools via MCP protocol |
| **Calendar API** | Google Calendar API v3 | Event management, OAuth2 authentication |
| **NLP** | LangChain | Prompt engineering, chain-of-thought |

### Key Features Implementation

#### 1. **MCP Server - Tool Exposure**
```python
# Expose calendar tools via MCP protocol
@app.list_tools()
async def list_tools():
    return [
        Tool(name="list_events", description="List upcoming calendar events", ...),
        Tool(name="create_event", description="Create a new calendar event", ...),
        Tool(name="search_events", description="Search events by keyword", ...),
        Tool(name="get_today_events", ...),
        Tool(name="update_event", ...),
        Tool(name="delete_event", ...),
        Tool(name="check_availability", ...)
    ]

@app.call_tool()
async def call_tool(name: str, arguments: Any):
    client = get_calendar_client()
    if name == "list_events":
        events = client.list_events(...)
        return [TextContent(type="text", text=formatted_output)]
```

#### 2. **OAuth2 Authentication**
```python
# Google Calendar OAuth2 flow
flow = InstalledAppFlow.from_client_secrets_file(
    'credentials.json',
    SCOPES=['https://www.googleapis.com/auth/calendar']
)
creds = flow.run_local_server(port=0)
```

#### 3. **MCP + Ollama Integration**
```bash
# ollmcp connects Ollama to MCP servers
ollmcp --servers-json ollmcp_config.json --model llama3.2:3b

# User types: "What's on my calendar today?"
# โ†’ Ollama (Llama 3.2) understands intent
# โ†’ Calls get_today_events tool via MCP protocol
# โ†’ Calendar server executes Google Calendar API call
# โ†’ Response formatted and returned via MCP
# โ†’ Ollama generates natural language response
```

---

## ๐Ÿ“Š Performance

| Metric | Value |
|--------|-------|
| **Response Time** | 1-2 seconds (local LLM) |
| **Memory Usage** | ~4GB RAM (Llama 3.2 3B) |
| **API Calls** | Only for calendar sync (free tier: 1M requests/day) |
| **Offline Capability** | LLM works offline, calendar requires internet |
| **Cost** | $0/month (100% free) |

### Model Comparison

| Model | Size | RAM | Speed | Quality | Use Case |
|-------|------|-----|-------|---------|----------|
| llama3.2:3b | 2GB | 4GB | โšกโšกโšก | โญโญโญโญ | **Recommended** |
| gemma:2b | 1.4GB | 3GB | โšกโšกโšกโšก | โญโญโญ | Faster, lower RAM |
| phi3:mini | 2.3GB | 4GB | โšกโšกโšก | โญโญโญโญ | Better code understanding |
| mistral:7b | 4.1GB | 8GB | โšกโšก | โญโญโญโญโญ | Highest quality |

---

## ๐Ÿ”ง Project Structure

```
ai-calendar-assistant/
โ”œโ”€โ”€ calendar_assistant/
โ”‚   โ”œโ”€โ”€ mcp_server/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ””โ”€โ”€ calendar_server.py      # MCP server implementation
โ”‚   โ”œโ”€โ”€ llm/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ””โ”€โ”€ local_assistant.py      # Ollama integration
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ””โ”€โ”€ google_calendar.py      # Google Calendar API wrapper
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ cli.py                      # CLI interface
โ”œโ”€โ”€ calendar_assistant.py            # Main entry point
โ”œโ”€โ”€ requirements.txt                 # Dependencies
โ”œโ”€โ”€ verify_setup.py                  # Setup verification script
โ”œโ”€โ”€ .env.example                     # Environment configuration template
โ”œโ”€โ”€ .gitignore                       # Git ignore rules
โ”œโ”€โ”€ README.md                        # This file
โ”œโ”€โ”€ QUICKSTART.md                    # 5-minute setup guide
โ”œโ”€โ”€ SETUP.md                         # Detailed setup instructions
โ””โ”€โ”€ LOCAL_LLM_SETUP.md              # Ollama installation guide
```

---

## ๐ŸŽฏ MCP Tools Available

When integrated with Claude Desktop, the following tools are exposed:

| Tool | Description | Parameters |
|------|-------------|------------|
| `list_events` | Get upcoming calendar events | `max_results`, `days_ahead` |
| `get_today_events` | Retrieve today's schedule | None |
| `create_event` | Create a new calendar event | `summary`, `start_time`, `end_time`, `description`, `location` |
| `search_events` | Search events by keyword | `query`, `max_results` |
| `update_event` | Modify existing event | `event_id`, `summary`, `start_time`, `end_time` |
| `delete_event` | Remove event from calendar | `event_id` |
| `check_availability` | Check if time slot is free | `start_time`, `end_time` |

---

## ๐Ÿ” Privacy & Security

- โœ… **Local LLM** - All AI processing happens on your machine
- โœ… **OAuth2** - Secure Google authentication
- โœ… **No Cloud LLM APIs** - No data sent to OpenAI/Anthropic
- โœ… **Credentials Protected** - `credentials.json` and `token.pickle` in `.gitignore`
- โœ… **Open Source** - Full transparency, audit the code yourself

**Data Flow:**
1. Your query โ†’ Local LLM (Ollama) โ†’ Intent extracted
2. Calendar operation โ†’ Google Calendar API (OAuth2)
3. Response โ†’ Local LLM โ†’ Natural language response

---

## ๐Ÿ“š Documentation

- [Quick Start Guide](QUICKSTART.md) - Get running in 5 minutes
- [Setup Guide](SETUP.md) - Detailed installation instructions
- [Local LLM Setup](LOCAL_LLM_SETUP.md) - Ollama configuration

---

## ๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

---

## ๐Ÿ“ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

## ๐Ÿ™ Acknowledgments

- [Ollama](https://ollama.com/) - Local LLM runtime
- [Model Context Protocol](https://modelcontextprotocol.io/) - AI integration framework
- [Google Calendar API](https://developers.google.com/calendar) - Calendar integration
- [LangChain](https://www.langchain.com/) - LLM orchestration
- [Rich](https://github.com/Textualize/rich) - Beautiful terminal output

---

## ๐Ÿ“ง Contact

**Othmane Zizi** - [othmane.zizi.pro@gmail.com](mailto:othmane.zizi.pro@gmail.com)

Project Link: [https://github.com/othmane-zizi-pro/ai-calendar-assistant](https://github.com/othmane-zizi-pro/ai-calendar-assistant)

---

**โญ Star this repo if you found it helpful!**