Getting Started with Model Context Protocol
Lesson 4: Resources and Prompts – The Other Two Primitives
Lesson Objectives
By the end of this lesson, students should be able to:
- Explain what MCP resources are and when to expose data as a resource vs. a tool
- Explain what MCP prompts are and how they differ from tool definitions
- Implement a resource handler in an MCP server
- Implement a prompt definition in an MCP server
Lesson Content
Resources – data, not functions.
Resources expose data for reading. A resource is identified by a URI and returns content when requested. Unlike tools (which execute a function), resources provide data that Claude or the user can read.
Examples of data appropriate for resources:
- A file or document (e.g.,
file:///path/to/document.md) - A database record (e.g.,
db://customers/12345) - A configuration object (e.g.,
config://app/settings)
When to use a resource vs. a tool: if the primary operation is reading static or semi-static data – use a resource. If the operation executes a function, makes a decision, or modifies state – use a tool.
Resource implementation pattern.
@app.list_resources()
async def list_resources() -> list[types.Resource]:
return [
types.Resource(
uri="docs://api-reference",
name="API Reference",
description="The full API reference documentation",
mimeType="text/markdown"
)
]@app.read_resource()
async def read_resource(uri: str) -> str:
if uri == "docs://api-reference":
return Path("api_reference.md").read_text()
raise ValueError(f"Unknown resource: {uri}")
Prompts – reusable instruction templates.
Prompts are pre-defined instruction templates that users or AI clients can invoke by name. They produce a configured message ready to send to Claude – with or without dynamic parameters.
Examples:
- A code review prompt template with customizable language parameter
- A summarization prompt with configurable length and format parameters
- A debugging prompt template parameterized for error type
Prompts are reusable, shareable instructions – they capture best-practice prompt patterns and make them invocable by name across applications.
When to use which primitive.
- Primitive: Tool; Primary Use: Execute functions, take actions, retrieve dynamic data; Returns: Result of execution
- Primitive: Resource; Primary Use: Expose static or semi-static data for reading; Returns: Document content
- Primitive: Prompt; Primary Use: Provide reusable instruction templates; Returns: Configured message
Enroll to continue this lesson.
The preview above shows the lesson objectives and opening lesson content. Enroll to view the full lesson, complete the practice work, and take the lesson quiz.
