MCP Resources and Prompts: Addressable Context for Stateless Servers
Tools perform operations. Resources expose addressable content. Prompts package user-selected message templates. A good MCP server keeps those contracts separate and predictable. Choose among tools, resources, and prompts from the consumer's intent. Advertise the resource and prompt surface through mandatory server/discover. Build deterministic resources/list and prompts/list results. Apply ttlMs and cacheScope without leaking user-specific data. Return JSON-RPC error -32602 for an invalid or unknown resource URI. Open a subscriptions/listen POST-response stream and correlate every event by subscription ID. Treat resource content and prompt templates as untrusted server output. The easiest way to misuse MCP is to begin with implementation code. A database query becomes a tool because functions are familiar. A reusable workflow becomes a resource because it is stored in a file. A prompt becomes hidden policy because the host can inject it. Begin with who chooses and what they expect. A note at notes://note-1 is a resource because it is addressable content. deletenote is a tool because it changes state. reviewnote is a prompt because a user chooses a prepared review workflow. Do not expose one operation as all three merely to look complete. Each extra surface needs discovery, authorization, caching, error handling, tests, and documentation. This lesson targets MCP protocol revision 2026-07-28. There is no initialization handshake or protocol session in this profile. Every request carries its…
MCP Resources and Prompts: Addressable Context for Stateless Servers: Tools perform operations. Resources expose addressable content. Prompts package…
This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.
Browse the complete course catalog or open this lesson on GitHub.