Lesson 22 of 30, Module 3: Make It Trustworthy. It refuses to leave the folder, asks before it overwrites, and remembers your answers.
What you can do after this lesson
A tool is correct when it gives the expected answers, not when it matches the reference solution. Put one door in front of a data source, here Notes, so a change behind the door costs nothing.
The problem we inherited
A server that can write can write over the wrong document, and there is no undo you can reach from a chat.
Code in this lesson
Every block the lesson shows on screen, in the order it appears.
def find_note(word: str) -> str:
hits = [n for n in _notes()
if word.lower() in n["note"].lower()]
if not hits:
return f"No note mentions {word}."
return "\n".join(f"{n['on']}: {n['note']}" for n in hits)
@mcp.tool()
def find_note(word: str) -> str:
"""Find every note that mentions one word."""
hits = [n for n in _notes()
if word.lower() in n["note"].lower()]
if not hits:
return f"No note mentions {word}."
return "\n".join(f"{n['on']}: {n['note']}" for n in hits)
Use scribe to find the note about openings.
Use scribe to find the note about zebras.
Downloads
- Module 3 checkpoint (scribe-checkpoint-m3.zip): working code as the module leaves it, so a broken session costs you nothing
- The course GitHub repo: every checkpoint, the README and the full lesson list
Prefer to read?
The written version of this part of the course is on Substack: https://genaiunplugged.substack.com/p/give-your-ai-agents-memory-mcp-shared.
Lesson transcript
My find note, and where we are
Here is my find_note. Yours does not have to look like it.
Hello, and welcome to lesson 22 of the MCP Masterclass. Last lesson I set you an assignment, a tool that finds a past decision by 1 word. Today I show you how I built mine. And we start with our map, as always.
13 lit boxes, and nothing new today. This tool lives inside the memory box you already lit.
Yours is right if
Well, before I show you a line, I want to say this clearly. If your tool gives the 2 expected answers, it is right. There are 5 or 6 good ways to write this, and mine is only 1 of them. Do not rewrite yours to match mine.
Building it in 5 steps
Okay. Step 1. The plain Python function.
def find_note(word: str) -> str:
hits = [n for n in _notes()
if word.lower() in n["note"].lower()]
if not hits:
return f"No note mentions {word}."
return "\n".join(f"{n['on']}: {n['note']}" for n in hits)
Five lines. Let me walk them.
The first 2 lines are the filter. Take every note, and keep the ones whose text contains the word. Both sides go through lower, so capital letters do not matter. That was requirement number 1.
Then, if nothing matched, a plain sentence. No note mentions that word. Requirement number 2.
And the last line gives back the matching notes, the date and then the note, exactly the way recall shows them. Requirement number 3.
Notice the thing I did not do. I did not open the file. Notes does that, and I only called it.
Step 2 and step 3. The @mcp line, and the docstring.
@mcp.tool()
def find_note(word: str) -> str:
"""Find every note that mentions one word."""
hits = [n for n in _notes()
if word.lower() in n["note"].lower()]
if not hits:
return f"No note mentions {word}."
return "\n".join(f"{n['on']}: {n['note']}" for n in hits)
The docstring is the whole job in 1 line, because that is what Claude reads to decide when to reach for it.
Step 4. Restart Claude Desktop. Step 5. Ask Claude to use it.
Use scribe to find the note about openings.
On screen: Claude Desktop calls find_note with "openings". "2026-09-30: keep my openings under 12 words."
One note, the right one. And the zebra.
Use scribe to find the note about zebras.
On screen: Claude calls find_note with "zebras". "No note mentions zebras."
No note mentions zebras. Both expected answers, and no error anywhere.
Other ways that work
Now, a few of the ways yours might differ, and why they are all fine.
You may have used a for loop instead of the filter in square brackets. Same result, 2 more lines.
You may have made the word optional, so an empty word gives back everything. That is recall again, and it is a fair design.
You may have searched the date as well as the note. Then asking for a month gives you that month's decisions, which is a genuinely useful tool. I did not think of it until I saw it.
The one thing to change
The 1 thing I would push back on is reading the file yourself instead of calling notes. Not because it is wrong today. Because in module 4 the memory file may move, and the tools that use notes will not notice, and the tool that opened the file by hand will break.
That is the same idea as the wrapper around Google in lesson 17. One door in, so a change behind the door costs you nothing.
What it cost, and what is next
So what did the fifth tool cost you? Five lines, and 5 steps you can now run in your sleep. And that was the point of the assignment. Not the tool. The proof that you can add one alone.
So where does our map stand at the end of this lesson?
13 boxes lit. Your server has 5 tools now, 2 resources and 1 prompt, and it is safe to trust.
Next lesson is the module 3 recap. Five points, and then module 4.
Bye now, and I will see you in the next lesson.