alepha@docs:~/docs/.content/release/framework/docs/reference/primitives$
cat $resource.md | pretty
2 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
title string No Human-friendly display title (spec 2025-11-25)
icons McpIcon[] No Optional icons surfaced in client UIs (spec 2025-11-25 / SEP-973).
description string No Description of what this resource contains
mimeType string No MIME type of the resource content
size number No The raw content's size in bytes, before any encoding, when known
annotations McpAnnotations No Audience / priority / lastModified hints (spec 2025-03-26+)
_meta Record<string, unknown> No Arbitrary metadata passed through to clients on the descriptor (spec 2025-06-18+)
ui McpUiResourceMeta No What an MCP Apps view (a ui:// resource) tells the host: the origins its iframe may reach, a dedicated domain, a border
cache Partial<McpCacheHints> No Caching hints for this resource's resources/read result, sent to modern clients only (spec 2026-07-28 ttlMs / cacheScope; a legacy client never sees them)
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}