I wrote an MCP server to give LLMs read-only access to my emails. Here is the chat log.
ME:
I need to know Donovan’s son’s name. It is buried in some email somewhere. Devise a strategy for finding it. Do NOT use any tools till we’ve discussed it through.
GEMINI:
Okay, I will devise a strategy to find Donovan’s son’s name and discuss it with you.
Strategy:
- Search for emails from Donovan: Use the search_emails tool with a query like “from:Donovan”. This will give us a list of email threads.
- Search for keywords within Donovan’s emails: Refine the search to include keywords that might be associated with a son. For example: “from:Donovan son”, “from:Donovan boy”, “from:Donovan name is”. We can also try terms related to birth announcements if we suspect the name might be in one, e.g., “from:Donovan born”, “from:Donovan baby”.
- Examine promising threads/messages: If the search yields specific messages or threads, I will suggest we look at their content using get_thread_by_id or get_message_content_by_id.
- Iterate: If the initial searches are not successful, we can try broader keywords or look for emails to Donovan that might congratulate him or mention his son.
Do you want to proceed with the first step, or would you like to refine this strategy?
ME:
OK. Go ahead and try them. No need to prompt me any more.
GEMINI:
The search “from:Donovan son” returned a promising result:
Subject: SonFrom: Donovan Nolan <donovan@gmail.com>Date: Sat, 30 May 2015 23:32:41 +0500ID: CAMJZR9aPWpGbd3VLyPA+B-=LjcNo4YTmtw03TvQri4wxHfrA@mail.gmail.comThread ID: 0000000000007a96I’ll get the content of this message.
This email is about Donovan’s cousin Aliyah’s son, Albert Hamming, not Donovan’s own son.
I’ll try other keywords.
The search “from:Donovan baby” yielded one result:
Subject: powertoddler!
From: Donovan Nolan <donovan@gmail.com>Date: Fri, 25 Mar 2011 00:32:58 +0500Thread ID: 0000000000004e70I’ll check this message.This email links to a YouTube video and mentions “the baby”. This is a strong lead. However, the email is from 2011. While this could be Donovan’s son, the term “powertoddler” might also refer to a niece/nephew or other young child in the family.
Since the direct approach didn’t yield a definitive answer, I’ll try searching for emails sent to Donovan with congratulatory terms.
This search found two emails from “Mark Nagy” with the subject “Re: Hello” in June 2009. This looks promising. I’ll retrieve the thread.
This thread is also about a cousin’s son, Norbert’s son, named Fulham Rod. It appears my targeted searches for “son”, “boy”, “baby” and “congratulations son” are not specific enough and are returning results for other relatives.
I need to look for more direct mentions. I’ll try searching for emails from Donovan containing phrases like “my son’s name is” or “we named him”.
Those searches didn’t return any results. It’s possible the name is mentioned in a more indirect way.
Let’s go back to the “powertoddler” email (ID: AANLkTikcbrSPX745z+bXcW6uUNa7QirnfKJTwMG28Uhd@mail.gmail.com from 2011). While it didn’t explicitly state “my son”, the context of “a typical evening trying to get the baby to sleep” is suggestive.
Could there be other emails in that same thread (ID: 0000000000004e70) that might contain the name?
Unfortunately, the other email in that thread is a correction to the YouTube link and doesn’t add more information about the child’s name.
The email “Re: Monty” from Donovan, ID CAMJZR9bsEyYD0QTmd=UNmwg2Jbm6PJSj1WGHvX_cBpPNRZoefw@mail.gmail.com dated Thu, 6 Oct 2022 18:14:57 +0500 (Thread ID: 000000000001a7a4) seems like a very strong candidate from the initial broad search for “from:Donovan”. The subject itself is a name. Let’s check the content of this message.
This email discusses the reading preferences of “he” and mentions “Monty” in the subject line. This strongly suggests that Monty is Donovan’s son.
Donovan’s son’s name is likely Monty.
It was spot on. Incidentally, that email never refers to him as his son. It is about Monty’s interests.
How did I do this?
I index all my emails using notmuch. I wrote an MCP server for it. [1] It has only three tools:
- search: Lets the LLM execute a search with any query. It returns a list of all matches’ metadata: from, to, date, subject, ID, and thread ID. Fortunately, Gemini knows notmuch search syntax.
- get_message_content_by_id: Retrieves the text contents of a particular email given its ID.
- get_thread_by_id: Returns the whole email thread given the thread ID.
That’s all I needed to let Gemini figure out my nephew’s name. [2]
It was instructive to see its tool usage in determining his name:
query: "from:Donovan" query: "from:Donovan son" get_message_content_by_id query: "from:Donovan boy" query: "from:Donovan name is" query: "from:Donovan born" query: "from:Donovan baby" get_message_content_by_id query: "to:Donovan congratulations" get_thread_by_id query: "from:Donovan \"my son's name is\"" query: "from:Donovan \"we named him\"" get_thread_by_id get_message_content_by_id
Most of those queries led to dead ends. When it finally figured it out in the last get_message_content_by_id, it was going off a result from the very first query.
Interesting thought process!
[1] | There already exists an MCP server for notmuch, but at the moment I don’t trust any third-party servers. The risks are too high, and it was much simpler to write the tools that I need and have them function exactly how I need them to. And of course, I got Gemini to write the bulk of the code anyway. |
[2] | OK, OK. There were nuances. I do limit the number of results returned, but I also provide a means for pagination in case the LLM wants to search further. I truncate any long emails and I also return only the text content, not attachments and HTML. |
Comments
You can view and respond to this post in the Fediverse (e.g. Mastodon), by clicking here. Your comment will then show up here. To reply to a particular comment, click its date.