VereskLearn

Module 7 · MCP

Lesson 7.3

Resources and prompts

Resources are readable data, and prompts are reusable message templates that a server offers.

Lesson 47 of 621 min read

The problem

Why it matters

Without it

Each app copies documents and templates into its own code. The copies drift, and nobody knows which one is current.

With it

The server owns the data and the templates. Clients list them, then read or fill them when needed.

How it works

  • A resource is data with a uri

    A resource is readable data, identified by a uri. A uri is an address such as docs://refunds. The resources/read request returns the text stored at that address.

    UriText returned
    docs://refundsRefunds take 5 to 7 days.
    docs://shippingOrders ship in 2 business days.
    Two resources that the server offers.
    const resources: Record<string, string> = {  "docs://refunds": "Refunds take 5 to 7 days.",};console.log(resources["docs://refunds"]);

    Output

    Refunds take 5 to 7 days.
  • A prompt fills a template

    A prompt is a reusable message template with a named argument. The client sends the topic, and the server fills it in. For the topic refund, the filled text is Summary of refund FAQ.

    1. Summary of [topic] FAQ
    2. topic = refund
    3. Summary of refund FAQ.
    One prompt, filled in by one argument.
    const summarize = (topic: string) => {  return "Summary of " + topic + " FAQ.";};console.log(summarize("refund"));

    Output

    Summary of refund FAQ.
  • Reading never changes data

    A resource read returns text and changes nothing. A tool is different, because the model asks for it and the tool may change data. Keeping reads and actions apart makes each read safe to repeat.

    Resource

    • The client reads the text
    • Changes no data

    Tool

    • The model asks for it
    • May change data
    Resources and tools, compared.

Full code

Read the program

See the full code

Common mistakes

What goes wrong

  • Using a resource to trigger an action. Reading a resource should never change any data.
  • Listing a uri that cannot be read. Each listed uri must work with resources/read.
  • Treating a prompt as a fixed message. Each use fills in new arguments.

Use it when and skip it when

Is it the right tool?

Use it when

  • Several apps need the same documents or templates.
  • The same text must be read in many places and kept current.

Skip it when

  • One app uses the text, and the text never changes.

Words to know

Terms in this lesson

Resource
Readable data that a server offers, identified by a uri.
Uri
An address that names one resource, such as docs://refunds.
Prompt
A reusable message template with named arguments.
Argument
A value that fills a gap in a template, such as a topic.
Full code