️ DEPRECATED GITLAB INSTANCE ️ This GitLab is now read-only for reference. Please use https://gitlab.iauro.co for all new work.

Migration completed on September 17, 2025

Commit 309e6111 authored by Pratiksha Patil's avatar Pratiksha Patil

9th Assignment of MCP client

parent 07403da6
SMTP_SERVER=smtp.example.com
SMTP_USER=your-email@example.com
SMTP_PASSWORD=yourpassword
# MCP Client
## Overview
This project contains a simple MCP client and a mock MCP server that:
- Fetches user email context
- Queries calendar events via Outlook tool endpoint
- Sends a summary email
## Setup
### Install dependencies
```bash
pip install -r requirements.txt
```
### Run the MCP server
```bash
uvicorn mcp-server:app --reload
```
### Run the client
Update `.env` with your SMTP credentials, then:
```bash
python mcp-client.py
```
import httpx
import smtplib
import os
from email.mime.text import MIMEText
from datetime import datetime, timedelta
from dotenv import load_dotenv
load_dotenv()
MCP_SERVER_URL = "http://localhost:8000"
SMTP_SERVER = os.getenv("SMTP_SERVER")
SMTP_PORT = 587
SMTP_USER = os.getenv("SMTP_USER")
SMTP_PASS = os.getenv("SMTP_PASSWORD")
FROM_EMAIL = os.getenv("SMTP_USER")
def get_user_context():
try:
response = httpx.post(f"{MCP_SERVER_URL}/context", json={})
response.raise_for_status()
context = response.json()
return context.get("email")
except Exception as e:
print(f"[ERROR] Failed to fetch user context: {e}")
return None
def get_calendar_events(user_email: str):
today = datetime.utcnow()
start = today.replace(hour=0, minute=0, second=0, microsecond=0).isoformat() + "Z"
end = (today + timedelta(days=1)).replace(hour=0, minute=0, second=0, microsecond=0).isoformat() + "Z"
payload = {
"tool_name": "get_upcoming_events",
"tool_input": {
"email": user_email,
"start_datetime": start,
"end_datetime": end
}
}
try:
response = httpx.post(f"{MCP_SERVER_URL}/tool", json=payload)
response.raise_for_status()
return response.json().get("events", [])
except Exception as e:
print(f"[ERROR] Failed to fetch calendar events: {e}")
return []
def send_email_summary(to_email, events):
if not events:
body = "You have no events scheduled for today."
else:
summary = "\n".join(
f"- {e['subject']} at {e['start']['dateTime']} (location: {e.get('location', {}).get('displayName', '-')})"
for e in events
)
body = f"Hello,\n\nHere is your schedule for today:\n\n{summary}\n\nRegards,\nMCP Client"
msg = MIMEText(body)
msg["Subject"] = "Today's Outlook Calendar Summary"
msg["From"] = FROM_EMAIL
msg["To"] = to_email
try:
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
server.starttls()
server.login(SMTP_USER, SMTP_PASS)
server.send_message(msg)
print(f"[INFO] Email sent to {to_email}")
except Exception as e:
print(f"[ERROR] Failed to send email: {e}")
if __name__ == "__main__":
print("[INFO] Starting MCP Client...")
user_email = get_user_context()
if not user_email:
print("[ERROR] No user email found. Exiting.")
exit(1)
print(f"Found user: {user_email}")
events = get_calendar_events(user_email)
print(f"Fetched {len(events)} events.")
send_email_summary(user_email, events)
from fastapi import FastAPI
from pydantic import BaseModel
from datetime import datetime, timedelta
app = FastAPI()
@app.post("/context")
def get_context():
return {"email": "dummy.user@example.com"}
class ToolInput(BaseModel):
email: str
start_datetime: str
end_datetime: str
class ToolRequest(BaseModel):
tool_name: str
tool_input: ToolInput
@app.post("/tool")
def get_tool_data(req: ToolRequest):
now = datetime.utcnow()
events = [
{"subject": "Team Standup", "start": {"dateTime": (now + timedelta(hours=1)).isoformat()}, "location": {"displayName": "Zoom"}},
{"subject": "Client Call", "start": {"dateTime": (now + timedelta(hours=3)).isoformat()}, "location": {"displayName": "MS Teams"}}
]
return {"events": events}
httpx
python-dotenv
fastapi
uvicorn
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment