Tools are model-controlled. Resources are application-controlled context identified by a URI. Prompts are user-controlled templates. Treating all three as “tools” produces a server that is harder to secure and harder for clients to present well.
When to use a resource
Use a resource when the data has an identity and a lifecycle outside a single call:
- A document, issue, design file, or log stream.
- A configuration file the user selects.
- A generated report the application can subscribe to or cache.
Use a tool when the model needs to perform an action or a bounded query. A resource read should not have side effects.
Register a static resource
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
const server = new McpServer({ name: "docs-mcp", version: "0.1.0" });
server.registerResource(
"editorial-guide",
"docs://editorial/guide",
{
title: "Editorial guide",
description: "The current writing and sourcing rules for this project.",
mimeType: "text/markdown",
},
async (uri) => ({
contents: [
{
uri: uri.href,
mimeType: "text/markdown",
text: "# Editorial guide\n\nEvery factual claim needs a source...",
},
],
}),
);
The URI scheme is yours to define, but it should be stable and meaningful. The MIME type tells the client how to render or parse the content. Do not return HTML from a resource labeled as Markdown, and do not return secrets that the resource URI does not imply.
For a dynamic resource, use the SDK’s resource template API and validate the URI parameters. A template that accepts arbitrary paths is a filesystem traversal risk if you use it to read local files:
// Validate and normalize template parameters before touching the filesystem.
const safeName = name.replace(/[^a-zA-Z0-9_-]/g, "");
if (safeName !== name) throw new Error("Invalid resource name");
Register a prompt
A prompt is a reusable template the user can invoke, often from a slash command or menu. It can accept arguments and return messages:
server.registerPrompt(
"review-change",
{
title: "Review a change",
description: "Ask for a review focused on correctness and missing tests.",
argsSchema: {
summary: z.string().min(10).describe("What changed and why."),
diff: z.string().min(1).describe("The unified diff to review."),
},
},
({ summary, diff }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Review this change.\n\nIntent: ${summary}\n\nDiff:\n${diff}\n\nList blocking issues first, then missing tests.`,
},
},
],
}),
);
Prompts should not perform privileged actions. They shape the conversation. If a prompt needs fresh data, fetch it through a resource or tool rather than embedding a stale snapshot in the template.
Keep context bounded
A resource that returns a 10 MB document will consume the client’s context and may be truncated unpredictably. Return a summary, a page, or a link, and let the user choose the full document. If the client supports resource links, use them for large artifacts.
Resources should be deterministic for a given URI and version. If the underlying data changes, update a version or timestamp in the content so the client can decide whether to refresh.
Capability negotiation
Clients can declare whether they support resources, prompts, and resource subscriptions. Do not assume a client implements them. The server advertises its capabilities; the client decides what to display. A server that only exposes a prompt is valid, but a client may not surface it.
If a client calls a method you do not implement, it should receive method-not-found rather than a crash. See the -32601 guide for the failure mode.
Test the presentation
For each resource:
- List it and confirm the URI, name, description, and MIME type.
- Read it and verify the content matches the type.
- Try a malformed URI and confirm a clear error.
- Check size limits and escaping.
For each prompt:
- List it and inspect the argument schema.
- Invoke it with valid arguments.
- Invoke it with missing arguments.
- Confirm the output is a set of messages, not an action.
The best resource is one a user can find by name and trust by its source. The best prompt is one that saves a step without hiding what it will do. Tools, resources, and prompts are different contracts; keeping them separate is what makes an MCP server usable.
Sources
Sources were checked on Oct 23, 2026. Versions and client behavior can change; confirm the current documentation before relying on a configuration.