0Pricing
MCP Academy · Lesson

Implement Tools, Resources & Prompts

Build all three primitives for the use case.

Implement Tools, Resources & Prompts is a free MCP Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MCP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Build All Three Primitives

With a plan in hand, you now write real code. This lesson wires up your tools, resources, and prompts into one working server. 🛠️

Set Up the Backend

First, give the server something to act on. A tiny store, like a list or a SQLite file, holds the notes every primitive will share.

import sqlite3

db = sqlite3.connect("notes.db")
db.execute("CREATE TABLE IF NOT EXISTS notes(id INTEGER PRIMARY KEY, title TEXT, body TEXT)")

Write the Add Tool

Your first tool creates a note. The decorator publishes it, and the type hints turn the arguments into a schema the model can fill.

@mcp.tool()
def add_note(title: str, body: str) -> str:
    db.execute("INSERT INTO notes(title, body) VALUES (?, ?)", (title, body))
    db.commit()
    return "Saved."

Write the Search Tool

Add a second tool that searches notes by keyword. Returning a short list of matches keeps the result easy for the model to use.

@mcp.tool()
def search_notes(query: str) -> list[str]:
    rows = db.execute("SELECT title FROM notes WHERE body LIKE ?", (f"%{query}%",))
    return [r[0] for r in rows]

Describe Tools Clearly

Give each tool a plain docstring. That text becomes its description, and a clear one helps the model pick the right tool at the right time.

Expose a Resource

Now serve read-only context. A resource uri lets the model fetch one note without changing anything in your store.

@mcp.resource("note://{note_id}")
def get_note(note_id: int) -> str:
    row = db.execute("SELECT body FROM notes WHERE id = ?", (note_id,)).fetchone()
    return row[0] if row else "Not found."

Capture the URI Variable

The braces in the uri become a function argument. MCP pulls note_id straight from the path, so each read targets exactly one record.

Register a Prompt

Add a reusable prompt the user can trigger. It frames a request so callers get consistent, high-quality instructions every time.

@mcp.prompt()
def summarize(note_id: int) -> str:
    return f"Read note://{note_id} and summarize it in three bullet points."

Return Useful Text

Keep every result concise and human-readable. Short, clear strings save model tokens and make the user-facing output far easier to read.

Mix, But Keep Roles Clear

Tools act, resources read, and prompts instruct. Keeping each role distinct means clients and the model always know what to expect from each.

Wire the Entry Point

End the file by running the server so a client can connect. The run call starts the loop and hands control to the transport.

if __name__ == "__main__":
    mcp.run()

Quick Check

Let us check the resource uri detail.

Recap

You implemented all three primitives: tools that act, a resource that reads, and a prompt that instructs. The capstone server now does real work. 🎯

Frequently asked questions

Is the “Implement Tools, Resources & Prompts” lesson free?

Yes — the full text of “Implement Tools, Resources & Prompts” is free to read here on the web, and the MCP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MCP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Implement Tools, Resources & Prompts”?

Build all three primitives for the use case. You practise MCP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start MCP Academy?

No prior experience is required. MCP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Implement Tools, Resources & Prompts” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this MCP Academy lesson?

Yes. Every MCP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Scope the Project & Tools
  2. Implement Tools, Resources & Prompts
  3. Test, Inspect & Harden
  4. Document & Publish the Server
← Back to MCP Academy