This repository demonstrates how to use the "Sampling" feature of the Model Context Protocol (MCP) to summarize Gmail emails programmatically. The server is built using the FastMCP library and integrates with the Gmail API to fetch and summarize the latest emails.
- Sampling is technique where tools will provide data and instruction to model and your private model will provide the output. This is a great way to keep your data private and not share it with the model. The sampling feature of MCP allows you to do this in a very easy way.
-
Google API Credentials:
- You need a
credentials.jsonfile from Google to authenticate with the Gmail API. - Follow the instructions at Gmail API Quickstart to set up your Google Cloud project and download the
credentials.jsonfile.
- You need a
-
Python Environment:
- Ensure you have Python installed along with the required dependencies. This project uses
poetryfor dependency management.
- Ensure you have Python installed along with the required dependencies. This project uses
-
Clone this repository:
git clone <repository-url> cd weather
-
Install dependencies using
poetry:poetry install
-
Place your
credentials.jsonfile in the root directory of the project.
-
Authenticate with Gmail:
- The first time you run the server, it will prompt you to authenticate with your Google account. This will generate a
token.jsonfile for subsequent runs.
- The first time you run the server, it will prompt you to authenticate with your Google account. This will generate a
-
Start the MCP server:
poetry run python weather.py
- The server uses the Gmail API to fetch the latest 5 emails from your inbox.
- The
readGmailtool processes these emails and generates a summary using the MCP Sampling feature. - The summary is tailored to help users start their day with a concise overview of their inbox.
weather.py: Contains the MCP server implementation and thereadGmailtool.gmail.py: Handles Gmail API authentication and email fetching.
- Gmail API Quickstart: Learn how to programmatically access Gmail.
- MCP Sampling Documentation: Understand the Sampling feature of MCP.