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:
| Actor | Control Type | Example |
|---|
| User | Selects which resources to include | ”Add my calendar as context” |
| Application | Decides how to consume resources | Build embeddings, cache, transform |
| AI Model | Reads resource data | Uses 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 Case | Resource Examples |
|---|
| Coding (Cursor, Windsurf) | Open files, project structure, git history |
| Travel Agent | Calendar schedule, travel preferences, past itineraries |
| Customer Support | User profile, order history, support tickets |
| Research Assistant | PDF documents, bookmarks, notes |
| Personal Assistant | Email 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:
| Primitive | Control | Purpose | Example |
|---|
| Tools | Model-driven | Actions the AI performs | Send email, create task, query API |
| Resources | Application-driven | Context data for AI | Files, preferences, schedules |
| Prompts | User-driven | Templates users invoke | /analyze, /review, /support |
Next Steps