Skip to main content

Adding Resources & Prompts — Build Your First Server

← Back to Dashboard
1. Project Scaffolding2. Registering Tools3. Adding Resources & Prompts4. Connecting & Publishing

Adding Resources & Prompts

📚 Build Your First Server⏱ 10 min⭐ 90 XP⌨ Hands-on lab

Completing Your Server's Capabilities

A well-rounded MCP server doesn't just have tools - it also exposes Resources (data the AI can read) and Prompts (templates users can trigger).

Adding Resources

import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";

// Static Resource: Server documentation
server.registerResource(
  "server-readme",
  "file:///docs/README.md",
  { title: "Server README", description: "Server documentation and usage guide", mimeType: "text/markdown" },
  async (uri) => ({
    contents: [{
      uri: uri.href,
      text: "# Notes Server\n\nThis MCP server manages your markdown notes..."
    }]
  })
);

// Dynamic Resource Template: Individual notes
server.registerResource(
  "note",
  new ResourceTemplate("notes://note/{filename}", { list: undefined }),
  { title: "Note File", description: "Read a specific note by filename" },
  async (uri, { filename }) => {
    const content = await readFile(
      join(process.env.NOTES_DIR || "./notes", String(filename)),
      "utf-8"
    );
    return {
      contents: [{ uri: uri.href, text: content }]
    };
  }
);

Adding Prompts

// Prompt: Summarize all notes on a topic
server.registerPrompt(
  "summarize_topic",
  {
    title: "Summarize Topic",
    description: "Summarize all notes related to a topic",
    argsSchema: { topic: z.string().describe("The topic to summarize across all notes") }
  },
  ({ topic }) => ({
    messages: [
      {
        role: "user",
        content: {
          type: "text",
          text: `Search my notes for everything related to "${topic}" and create a complete summary. Include key facts, dates, and action items. Organize by theme.`
        }
      }
    ]
  })
);

// Prompt: Daily review
server.registerPrompt(
  "daily_review",
  { title: "Daily Review", description: "Review notes from the past 7 days" },
  () => ({
    messages: [
      {
        role: "user",
        content: {
          type: "text",
          text: "Review all my recent notes from the last 7 days. Summarize key decisions, flag overdue action items, and suggest priorities for today."
        }
      }
    ]
  })
);

When to Use Each Capability

CapabilityUser InteractionLLM InteractionBest For
ToolInvisible (LLM calls it)Can call autonomouslyActions, API calls, mutations
ResourceCan browse/attach in UICan read when attachedFiles, configs, documentation
PromptClicks to activate in UIReceives as message contextComplex workflows, templates
🎯 Pro Tip: Resources shine when paired with Host UIs. In Claude Desktop, users can attach resources like files. In Cursor, resources appear in the context panel. Design your resources for how users will discover them.
⌨ HANDS-ON LABVerify Resources on Built Server
⭐ +125 XP

Implement a resource handler serving internal application status reports.

1List resources on your built server using inspector CLI.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 1 — type "hint" if stuck
🧪 Knowledge Check
Press 1-4 to select1 of 3
What is the key difference between how Tools and Resources are triggered?
Tools are faster
The LLM calls tools autonomously; resources are attached by users via the Host UI
Resources cost more tokens
There is no difference