Skip to content
Back to AI Coding

MCP Resources and Prompts

Expose read-only resources and reusable prompt templates beyond tools.

MCP DevelopmentAdvanced

Why

MCP launched in November 2024; by December 2025 it had 97M+ monthly SDK downloads, and by September 2026 the npm SDK alone reached ~204M monthly downloads (5x growth in 9 months) with 10,000+ published servers. Tools are for actions; resources are for read-only context (schemas, configs) and prompts are reusable templates.

Using all three keeps your server idiomatic: the AI browses resources, calls tools, and instantiates prompts instead of cramming everything into tool descriptions.

When

Add resources when the AI should browse data (table schemas, open tickets). Add prompts for reusable workflows (investigate-incident).

Skip if tools alone cover it.

How

1. Resources: uri scheme + handler returning small text/JSON (<4KB). 2. Prompts: name + arguments + handler returning a prompt string. 3. Register both in the server capabilities. 4. The client lists resources/prompts; the AI reads/instantiates as needed. 5. Keep resource payloads small; paginate larger data.

Example

// Resource: db schema the AI can browse server.setRequestHandler("resources/list", async () => ({ resources: [{ uri: "schema://db/tables", name: "DB tables", mimeType: "application/json" }], })); server.setRequestHandler("resources/read", async (req) => { if (req.params.uri === "schema://db/tables") return { contents: [{ uri: req.params.uri, text: JSON.stringify(await db.schema()) }] }; }); // Prompt: reusable incident workflow server.setRequestHandler("prompts/get", async (req) => { if (req.params.name === "investigate-incident") return { messages: [{ role: "user", content: { type: "text", text: `Investigate incident ${req.params.arguments.id}` } }] }; });

Common Problems

  • ⚠Error: Cannot find module '@modelcontextprotocol/sdk' → run `npm install @modelcontextprotocol/sdk zod`; the SDK requires Node.js 18+.
  • ⚠"Error: transport closed" / server not listed by client → verify the stdio/HTTP transport matches on both sides; check `npx @modelcontextprotocol/inspector` output.
  • ⚠Tool call returns `{"error": "Invalid params"}` → validate the input schema with zod; common cause is missing required field or wrong type.

Best Practices

  • ✓Keep resources read-only and small (<4KB).
  • ✓Use prompts for multi-step workflows with arguments.
  • ✓Measure the outcome with a concrete metric (time saved, defect rate, test coverage) so the practice can be justified and improved.

FAQ

What is MCP Resources and Prompts?

Expose read-only resources and reusable prompt templates beyond tools. It helps developers quickly grasp the core value and use cases of MCP Resources and Prompts.

How do I get started with MCP Resources and Prompts?

To get started with MCP Resources and Prompts, focus on these points first: Resources: uri scheme + handler returning small text/JSON (<4KB).

What are common mistakes with MCP Resources and Prompts?

Common mistakes when using MCP Resources and Prompts include: Error: Cannot find module '@modelcontextprotocol/sdk' → run `npm install @modelcontextprotocol/sdk zod`; the SDK requires Node.js 18+.; "Error: transport closed" / server not listed by client → verify the stdio/HTTP transport matches on both sides; check `npx @modelcontextprotocol/inspector` output.; Tool call returns `{"error": "Invalid params"}` → validate the input schema with zod; common cause is missing required field or wrong type..

What are the best practices for MCP Resources and Prompts?

Best practices for MCP Resources and Prompts include: Keep resources read-only and small (<4KB).; Use prompts for multi-step workflows with arguments.; Measure the outcome with a concrete metric (time saved, defect rate, test coverage) so the practice can be justified and improved..

How do I learn more about MCP Resources and Prompts?

Start with the official docs, then search real-world examples on GitHub. Validate patterns in a small scratch repo before applying them to production code.