Lesson 06 Resources & Prompts
Theme:

Homework — Extend resources and prompts

Lesson 06 · MCP Servers · ~35 min

The lab gave you a static resource, a templated resource, and a single-message prompt. These three tasks push each primitive a step further. Tasks 1 and 2 add code to your existing PKB server; Task 3 is a paper exercise that builds the mental model you will reach for whenever you design a new MCP server.

Task 1 — Add a second resource template

Add a new resource template at pkb://search/{query} that returns the JSON list of matching note titles for query. The Inspector should expose it under the Resources tab next to your existing pkb://notes/{title} template.

Hint: reuse pkb.tools.search with its default limit — do not reimplement the search logic. Remember that FastMCP resources expect a string (or bytes), not a Python list, so json.dumps(...) the result before returning.

✓ Self-check: reading pkb://search/hello in Inspector returns ["hello"].

Task 2 — Add a multi-message prompt

Add a prompt summarize_prompt(topic: str) that returns a list[mcp.types.PromptMessage] with three messages, in order:

  1. user — “Please summarize my notes on {topic}.”
  2. assistant — “Of course! Let me search…”
  3. user — “Use pkb.search with query={topic}, then synthesize.”

Hint: see mcp.types.PromptMessage and TextContent. Each PromptMessage needs a role and a content object; for plain text use TextContent(type="text", text=...).

✓ Self-check: Inspector shows 3 messages when invoking summarize_prompt.

Task 3 — Decide: tool, resource, or prompt?

For each of the following four hypothetical features, decide which MCP primitive it should be: a tool, a resource, or a prompt. No implementation needed — just write the answer plus a one-sentence justification.

  1. “Get the current weather for a city.”
  2. “Get the contents of the user’s most recent note.”
  3. “Generate an email template for following up after a meeting.”
  4. “Delete all notes older than 30 days.”

✓ Self-check: (a) tool — varies over time and takes input; (b) resource — read-only, discoverable; (c) prompt — reusable template; (d) tool — mutates state.

View solutions →