alepha@docs:~/docs/reference/primitives$
cat $resource.md1 min read
#$resource
#Import
typescript
1import { $resource } from "alepha/mcp";
#Overview
Creates an MCP resource primitive for exposing read-only data.
Resources represent any kind of data that an LLM might want to read, such as files, database records, API responses, or computed data.
Key Features
- URI-based identification for resources
- Support for text and binary content
- MIME type specification
- Lazy loading via handler function
#Options
| Option | Type | Required | Description |
|---|---|---|---|
uri |
string |
Yes | The URI that identifies this resource |
name |
string |
No | Human-readable name for the resource |
description |
string |
No | Description of what this resource contains |
mimeType |
string |
No | MIME type of the resource content |
handler |
ResourceHandler |
Yes | Handler function that returns the resource content |
#Examples
ts
1class ProjectResources { 2 readme = $resource({ 3 uri: "file:///readme", 4 description: "Project README file", 5 mimeType: "text/markdown", 6 handler: async () => ({ 7 text: await fs.readFile("README.md", "utf-8"), 8 }), 9 });10 11 config = $resource({12 uri: "config://app",13 name: "Application Configuration",14 mimeType: "application/json",15 handler: async () => ({16 text: JSON.stringify(this.configService.getConfig()),17 }),18 });19}