Skip to main content

Resources

Resources are read-only but dynamic data that applications can expose to AI agents. Unlike Tools (which perform actions), Resources provide contextual information that helps the AI understand your environment.

How Resources Work

Resources are application-driven — the client application decides how to use them:
ActorControl TypeExample
UserSelects which resources to include”Add my calendar as context”
ApplicationDecides how to consume resourcesBuild embeddings, cache, transform
AI ModelReads resource dataUses context to generate better responses
Client Support Matters: Resources are only useful if the client application provides UI for users to select and manage them. If your client doesn’t expose resource controls, users can’t leverage this feature effectively.

Real-World Examples

Resources aren’t just for code editors. They provide context in any domain:
Use CaseResource Examples
Coding (Cursor, Windsurf)Open files, project structure, git history
Travel AgentCalendar schedule, travel preferences, past itineraries
Customer SupportUser profile, order history, support tickets
Research AssistantPDF documents, bookmarks, notes
Personal AssistantEmail drafts, contacts, reminders

Basic Resource

import { Resource } from "@leanmcp/core";

export class StatusService {
  // Function name "getServerStatus" becomes resource name
  @Resource({ description: "Server status", mimeType: "application/json" })
  getServerStatus() {
    return {
      status: "running",
      uptime: process.uptime(),
      memory: process.memoryUsage()
    };
  }
}

Resource with Configuration

@Resource({ description: "System configuration", mimeType: "application/json" })
getConfig() {
  return {
    version: "1.0.0",
    environment: process.env.NODE_ENV,
    features: {
      analytics: true,
      notifications: true
    }
  };
}

Async Resources

Resources can be async for database queries or API calls:
@Resource({ description: "Database statistics", mimeType: "application/json" })
async getDatabaseStats() {
  const stats = await db.getStats();
  return {
    connections: stats.connections,
    queries: stats.queryCount,
    uptime: stats.uptime
  };
}

Resource with Dynamic Data

@Resource({ description: "Available models", mimeType: "application/json" })
getAvailableModels() {
  return {
    contents: [{
      uri: "models://available",
      mimeType: "application/json",
      text: JSON.stringify({
        "gpt-4": "Advanced reasoning",
        "gpt-3.5": "Fast, cost-effective",
        "gemini-pro": "Multimodal"
      })
    }]
  };
}

The Three MCP Primitives

Understanding when to use each:
PrimitiveControlPurposeExample
ToolsModel-drivenActions the AI performsSend email, create task, query API
ResourcesApplication-drivenContext data for AIFiles, preferences, schedules
PromptsUser-drivenTemplates users invoke/analyze, /review, /support

Next Steps