Google Calendar AI Agent MCP Server
Enables natural language interaction with Google Calendar through AI agent tools for scheduling, event management, and availability checking.
README
Google Calendar AI Agent
A production-ready Google Calendar AI Agent built on the Agent + Driver architecture. The Agent reasons in natural language, delegates actions to modular Tools, and uses the Driver to communicate with the Google Calendar API. It is powered by the Groq API with tool calling execution loops and supports both SQLite and PostgreSQL backends.
Architecture Overview
calendar-agent/
│
├── agents/
│ ├── calendar_agent.py # Reasoning loop using Groq Llama-3.3 Function Calling
│ └── prompts.py # System instructions & few-shot patterns
│
├── drivers/
│ ├── google_calendar_driver.py # Communicates with official Google APIs & handles ICS
│ └── auth.py # Initiates OAuth 2.0 flow & stores tokens in DB
│
├── tools/
│ ├── base.py # Defines BaseTool exposing MCP-compliant metadata
│ ├── create_event.py # Create events with double booking conflict checks
│ ├── list_events.py # Lists upcoming events
│ ├── update_event.py # Modifies event values
│ ├── delete_event.py # Cancels events
│ ├── search_events.py # Text search & advanced post-filters
│ ├── free_time.py # Smart availability slot finder (24-hour day scans)
│ └── recurring.py # Formats recurrence rule strings
│
├── models/
│ └── schemas.py # Pydantic validation schemas
│
├── memory/
│ └── chat_memory.py # SQLite & PostgreSQL database adapter
│
├── tests/ # Test suite covering driver, agents, and conflicts
│ └── test_agent.py
│
├── config.py # Application configurations
├── main.py # FastAPI API router & interactive dashboard console
└── Dockerfile # Docker runtime setup
Core Technologies
- Python 3.12+
- FastAPI & Uvicorn (REST Endpoints)
- Google Calendar API (via official
google-api-python-client) - Google OAuth 2.0 (with database token storage)
- Pydantic v2 & Pydantic Settings
- Groq API (
groqSDK withllama-3.3-70b-versatile) - icalendar (ICS serialization)
- SQLite (Local development database)
- PostgreSQL (Production database, e.g., Neon Postgres)
Google Cloud Console Setup
To connect the application to the Google Calendar API, you must configure an OAuth Client ID:
- Go to the Google Cloud Console.
- Create or select a project.
- Search for and enable the Google Calendar API.
- Navigate to APIs & Services > OAuth consent screen:
- Choose External user type.
- Fill in app name, developer support email, and save.
- In the Scopes step, add
.../auth/calendarand.../auth/calendar.events. - In the Audience (or Test users) step, add your Gmail account as an approved tester.
- Navigate to Credentials > Create Credentials > OAuth client ID:
- Application Type: Web application.
- Authorized redirect URIs: Add
http://localhost:8080/oauth2callback(and your production URL if hosting). - Click Create and copy your Client ID and Client Secret.
Installation & Setup
-
Clone the repository:
git clone <repository_url> cd calendar-agent -
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate -
Install dependencies:
pip install -r requirements.txt -
Configure Environment Variables: Create a
.envfile in the root directory:GROQ_API_KEY="your-groq-api-key" GOOGLE_CLIENT_ID="your-google-oauth-client-id" GOOGLE_CLIENT_SECRET="your-google-oauth-client-secret" GOOGLE_REDIRECT_URI="http://localhost:8080/oauth2callback" DB_PATH="calendar_agent.db" DATABASE_URL=""(Note: Leave
DATABASE_URLempty to use local SQLite, or enter a Postgres connection string to connect to a PostgreSQL database).
Running Locally
To run the FastAPI server and UI dashboard locally:
python -m uvicorn main:app --host 0.0.0.0 --port 8080 --reload
Open http://localhost:8080 in your web browser.
- Click Connect Google Calendar to authenticate.
- Sign in with your test Google Account and approve the permissions.
- You will be redirected back to the dashboard, which will load your upcoming events and let you chat with the AI Agent!
Production Deployment on Render
This project is fully ready for deployment on Render (Free Tier):
- Go to Render and create a new Web Service.
- Connect your GitHub repository.
- Select Docker as the Runtime (Render automatically detects your
Dockerfile). - Set the Instance Type to Free.
- Add the following Environment Variables:
GROQ_API_KEY=gsk_...GOOGLE_CLIENT_ID=...GOOGLE_CLIENT_SECRET=...DATABASE_URL=your-neon-postgres-connection-string(highly recommended to persist tokens across container restarts!)GOOGLE_REDIRECT_URI=https://<your-subdomain>.onrender.com/oauth2callbackOAUTHLIB_INSECURE_TRANSPORT=1
- Click Create Web Service.
- Add
https://<your-subdomain>.onrender.com/oauth2callbackto your Authorized redirect URIs in the Google Cloud Console.
Example Prompt Interactions
You can ask the agent natural language commands:
- Scheduling:
- "Schedule a meeting tomorrow at 3 PM for 45 minutes called 'Project Review' and invite test@gmail.com"
- "Schedule gym every Monday at 7am"
- Move/Reschedule:
- "Move my 3 PM dentist appointment tomorrow to Friday at 1 PM"
- List / Summarize:
- "Summarise my schedule today"
- "What's on my calendar next week?"
- Availability:
- "Am I free after 5 PM today?"
- "Find a one-hour free slot tomorrow morning"
- Add virtual meetings:
- "Add a Google Meet link to my interview event tomorrow"
- Conflict Resolution:
- If a slot overlaps, the Agent will ask: "There is an overlap with 'Weekly Sync'. Would you like me to book it anyway or schedule it right after at 4 PM instead?"
API Endpoints
Calendar Management
GET /events: List events with optionaltime_minandtime_maxparameters.POST /events: Create an event.PATCH /events/{id}: Modify an existing event.DELETE /events/{id}: Delete an event.
AI & Analytics
POST /chat: Interact with the agent. Payload:{"message": "string", "session_id": "string"}.GET /summary: Returns a short AI-generated schedule summary of the day.GET /analytics: Computes statistics like meeting hours today, weekly workload, monthly meeting time, busiest weekdays, and workload overload alerts.
Model Context Protocol (MCP)
GET /mcp/tools: Exposes all agent tools in MCP format.POST /mcp/execute: Executes an MCP tool.
Contribution Guide
- Ensure all code is typed and formatted using Ruff.
- Run Ruff check:
ruff check . - Run tests using
pytest:pytest tests/
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。