@Resource
@Resource declares an MCP resource: data at a fixed URI, like policy://sla, that a client can list and read. The client application decides when to read it, usually to attach it to a conversation. For a family of URIs that share a pattern, like ticket://{id}, use @ResourceTemplate.
@Resource(options)
class MyResource extends ResourceContext {
async execute(uri) { /* ... */ }
}
Reference
@Resource(options)
Apply @Resource to a class that extends ResourceContext, and list the class in an app's resources array.
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({
name: "sla",
uri: "policy://sla",
description: "How fast the help desk replies, by ticket priority",
mimeType: "application/json",
})
class SlaPolicy extends ResourceContext {
async execute() {
return { high: "4 hours", normal: "1 business day", low: "3 business days" };
}
}Options
Required:
| Option | Type | Description |
|---|---|---|
name | string | Identifies the resource. Unique within the server. |
uri | string | The address clients read. It must start with a scheme and ://, like policy://sla or file:///docs/faq.md. |
Optional:
| Option | Type | Description |
|---|---|---|
enabled | EnabledOption | Optional; defaults to on. A boolean or { get(context?), subscribe(listener), remedy? }. Off entries are omitted from lists and refused with FEATURE_OFF. Changes announce list_changed. See live availability. |
from | ResourceKey | Optional. A key from resourceStore(); writes announce resource updates. Extend MaterializedResourceContext to serve the value and its revision. |
worker | boolean | { budgetMs?: number } | Optional; off by default. Runs the resource's reads in the offload pool, on Node; the budget defaults to the server's offload.budgetMs, 30000 ms unless set. |
title | string | A display name for people. Clients show it instead of name. |
description | string | What the data is and when it's useful. Clients and models read it in resources/list. |
mimeType | string | The content type, like application/json. Listed in resources/list, and used for the content blocks FrontMCP builds from what execute() returns. Without it, FrontMCP picks one per block. Blocks you return in { contents } are sent as they are. |
icons | Icon[] | Images clients can show: src, and optionally mimeType, sizes and theme ("light" or "dark"). |
annotations | ResourceAnnotations | Hints for clients: audience (["user"], ["assistant"] or both), priority (from 0 to 1) and lastModified (an ISO 8601 date). |
_meta | Record<string, unknown> | Extra metadata, sent as is in resources/list. Use reverse-DNS keys, like com.example/owner. |
availableWhen | EntryAvailability | Only offer the resource on certain platforms, runtimes or deployments. Elsewhere it isn't listed, and reading it fails with -32003. See Environment awareness. |
execute(uri, params)
FrontMCP calls execute() every time a client reads the resource.
uri: the URI that was read. For a@Resource, that's always itsurioption.params: template parameters. Always{}for a@Resource.- Returns the content. FrontMCP turns it into the
contentsarray of theresources/readresult:
execute() returns | The client receives |
|---|---|
An object or number, like { high: "4 hours" } | One text block with the value as JSON. MIME type application/json. |
| A string | One text block. The MIME type comes from the URI's extension (.md is text/markdown) or the text itself, and is text/plain otherwise. |
A Uint8Array or Buffer | One blob block, base64-encoded. MIME type application/octet-stream, unless you set mimeType. |
An object with a text or blob string | That block, with the resource's URI. |
| An array | One block per item, converted as above. Items without their own uri get #0, #1… appended to the resource's URI. |
{ contents: [...] } | Exactly those blocks. Use this for full control. |
Inside execute(), this is the ResourceContext: this.uri and this.params hold the same values as the arguments, this.get() returns providers, this.fetch() makes outbound HTTP requests, this.context and this.auth describe the request and the caller, and this.notifyUpdated() tells subscribed clients that the content changed. this.notify(), this.progress() and this.elicit() belong to tools, not resources.
resource(options)(handler)
The function form takes the same options. The handler receives (uri, params) and returns a ReadResourceResult, the { contents: [...] } shape.
Caveats
- The class must extend
ResourceContext. Using@Resourceon any other class is a compile error. urimust have a scheme followed by://. Otherwise the server doesn't start, and reports "URI must have a valid scheme".- Reads match the URI exactly.
policy://sla/andpolicy://SLAare different URIs, and reading them fails with "Resource not found". - A resource takes no arguments. For data that depends on an id, use
@ResourceTemplate. If a resource and a template both match a URI, the resource wins. - If
execute()throwsResourceNotFoundError(uri), the client gets the same error as for a URI that matches nothing:-32602,Resource not found: …. APublicMcpErroralso gives-32602, with your error's message as the whole message. - Any other error is an internal one: JSON-RPC error
-32603, withResource "…" read failed:and your error's message in development. WithNODE_ENV=production, FrontMCP hides the message and sendsInternal FrontMCP error. Please contact support with error ID: …instead. See troubleshooting. this.fail(error)fails the read the same way asthrow errorfor aPublicMcpError. For any other error it's still-32603, but the message is your error's message without theread failed:prefix, anddata.codeisSERVER_ERRORinstead ofRESOURCE_READ_ERROR. Production hides it the same way.
resourceStore(options?)
Creates a store of values with revisions, which @Resource({ from }) serves. store.key(name, { initial? }) returns a key: get(), set(value), update(change) and subscribe(listener). The store's own subscribe(topic, listener) and publish(topic) follow the change feed, where a key's topic is its name; an sse route listens there. New in 1.11.0.
| Option | Type | Default | Description |
|---|---|---|---|
storage | StorageConfig with type "memory", "redis" or "sqlite" | memory | Backend with atomic compare-and-set. Redis and SQLite share values and changes between processes. |
pollIntervalMs | number | 250 | Positive whole milliseconds between SQLite change checks. |
coalesceMs | number | 50 | Nonnegative whole milliseconds in which writes to a key produce one announcement. |
onError | (error: unknown) => void | none | Receives failed polls, subscriptions, announcements and listeners. |
Usage
Exposing data at a fixed URI
Give the resource a URI with your own scheme and a description that says what's in it. Return a plain object and FrontMCP sends it as JSON.
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({
name: "sla",
title: "Reply-time policy",
uri: "policy://sla",
description: "How fast the help desk replies, by ticket priority. Read it before promising a customer a reply time.",
})
export class SlaPolicy extends ResourceContext {
async execute() {
return { high: "4 hours", normal: "1 business day", low: "3 business days" };
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Open the Capabilities tab to see the resource as resources/list describes it. Clients read it with resources/read and the URI.
Choosing what the client receives
What execute() returns decides the content blocks and their MIME types.
Content types
Example 1 of 4
Text
A string becomes one text block. The URI ends in .md, so the MIME type is text/markdown.
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({ name: "reply-guide", uri: "guide://replies.md", description: "How to word replies to customers" })
export class ReplyGuide extends ResourceContext {
async execute() {
return "# Replying to customers\n\n- Greet them by name.\n- Say what you did, then what happens next.\n- Link the ticket id, like T-1.";
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Example 2 of 4
Full control
Return { contents } to set every field yourself, here a CSV export.
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({ name: "open-tickets-csv", uri: "export://tickets/open.csv", description: "Open tickets as CSV" })
export class OpenTicketsCsv extends ResourceContext {
async execute(uri: string) {
const csv = "id,title,priority\nT-1,Cannot log in,high\nT-3,Login link expired,normal";
return { contents: [{ uri, mimeType: "text/csv", text: csv }] };
}
}Example 3 of 4
Binary
Bytes arrive base64-encoded in blob. Set mimeType, or clients get application/octet-stream.
import { Resource, ResourceContext } from "@frontmcp/sdk";
// The first bytes of a PNG file, to keep the example short.
const png = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
@Resource({ name: "logo", uri: "brand://logo.png", mimeType: "image/png", description: "The help desk logo" })
export class Logo extends ResourceContext {
async execute() {
return png;
}
}Example 4 of 4
Several blocks
Return an array for several blocks. Blocks without a uri get #0, #1… after the resource's URI.
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({ name: "handbook", uri: "policy://handbook", description: "The support handbook, one block per section" })
export class Handbook extends ResourceContext {
async execute(uri: string) {
return [
{ text: "Escalate high-priority tickets after 2 hours.", mimeType: "text/plain" },
{ uri: `${uri}#hours`, mimeType: "application/json", text: JSON.stringify({ open: "08:00", close: "18:00" }) },
];
}
}Reading from a provider
Get shared services with this.get(), and register the provider in the same app's providers array.
import { Resource, ResourceContext } from "@frontmcp/sdk";
import { Rota } from "./rota";
@Resource({ name: "on-duty", uri: "desk://on-duty", description: "Which agents are on duty right now" })
export class OnDuty extends ResourceContext {
async execute() {
return { agents: this.get(Rota).onDuty() };
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Describing a resource for clients
Everything except availableWhen goes out in resources/list. Clients use title and icons for display, and annotations to decide who the content is for and how prominent it should be. The test below reads the list the way a client would.
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({
name: "sla",
title: "Reply-time policy",
uri: "policy://sla",
description: "How fast the help desk replies, by ticket priority",
mimeType: "application/json",
annotations: { audience: ["assistant"], priority: 0.8, lastModified: "2026-09-01T09:00:00Z" },
_meta: { "com.example/owner": "support-ops" },
})
export class SlaPolicy extends ResourceContext {
async execute() {
return { high: "4 hours", normal: "1 business day", low: "3 business days" };
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Writing a resource as a function
For a resource that doesn't need context, the function form is shorter. Its handler returns the full { contents } shape, which is sent as it is, so set each block's mimeType there.
import { resource } from "@frontmcp/sdk";
export const openingHours = resource({
name: "opening-hours",
uri: "policy://hours",
mimeType: "application/json",
description: "When the help desk answers tickets",
})((uri) => ({
contents: [{ uri, mimeType: "application/json", text: JSON.stringify({ weekdays: "08:00-18:00", weekends: "closed" }) }],
}));Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Serving a stored value
A materialized resource serves a value that tools or another process write. The store uses memory by default; storage also takes a Redis or SQLite configuration for createStorage(). Memory, Redis and SQLite are the backends with the atomic compare-and-set its writes need. Redis and SQLite are refused in a browser. pollIntervalMs defaults to 250 for SQLite change checks; coalesceMs defaults to 50 for update announcements; onError(error) receives feed failures. New in 1.11.0.
key(name, { initial }) starts at revision 0. get(), set(value) and update(change) return { value, revision, updatedAt? }. Each write increments the revision. Keep change pure: a concurrent write can make it run again. Values are JSON copies. subscribe(listener) returns a function that stops listening.
import { MaterializedResourceContext, Resource, resourceStore, Tool, ToolContext } from "@frontmcp/sdk";
export const store = resourceStore();
export const board = store.key("board", { initial: { open: 2 } });
@Resource({ name: "board", uri: "desk://board", from: board })
export class Board extends MaterializedResourceContext {}
@Tool({ name: "close_ticket", inputSchema: {} })
export class CloseTicket extends ToolContext {
async execute() { return (await board.update((current) => ({ open: current.open - 1 }))).value; }
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Resource reads also inherit the app's output.budget, then the server's, when set. UI widget resources are never cut.
Reads include _meta["frontmcp/materialized"] with the revision and write time. Access to a ResourceKey in your code can write it, so the store itself is not an authorization boundary. Custom stores should pair connect() with close(); the server manages these for its resources.
Telling subscribers about a write
A write to a materialized resource's key announces its URI: clients subscribed to it get notifications/resources/updated, also for a write from another process that shares a Redis or SQLite store. A subscription is refused as a read would be, including by the resource's authorities.
Changed in 1.11.0: before, resources/subscribe didn't check the resource's authorities, and subscriptions/listen acknowledged every URI it was asked for. Now resources/subscribe refuses a caller the rule refuses, subscriptions/listen acknowledges only the URIs the caller may read, and it checks access again for an update to a resource under an acknowledged URI.
import { App, FrontMcp, MaterializedResourceContext, Resource, resourceStore } from "@frontmcp/sdk";
export const store = resourceStore();
export const board = store.key("board", { initial: { open: 2 } });
@Resource({ name: "board", uri: "desk://board", from: board, authorities: { roles: { any: ["agent"] } } })
class Board extends MaterializedResourceContext {}
@App({ name: "Desk", resources: [Board] })
class Desk {}
export const config = {
info: { name: "desk", version: "1.0.0" },
apps: [Desk],
authorities: { claimsMapping: { roles: "roles" } },
};
@FrontMcp(config)
export default class Server {}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Troubleshooting
The server doesn't start: "URI must have a valid scheme"
The uri option needs a scheme followed by ://. policy:sla and /policy/sla are rejected; policy://sla works.
Resource output validation failed (…)
The resource returned content the protocol cannot serve. The INVALID_OUTPUT development message includes the validation reason. Production hides it. Changed in 1.11.3: before, the resource message omitted that reason.
Reads fail with -32602 "Resource not found"
No resource or template matches the URI exactly, or execute() threw ResourceNotFoundError. Check for a trailing slash, different letter case, or a typo, and compare with resources/list. Under MCP 2026-07-28 this error has code -32602; earlier protocol versions use -32002. A resource whose availableWhen.surface leaves out "mcp" gets the same answer: MCP clients can't read it.
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({ name: "sla", uri: "policy://sla" })
export class SlaPolicy extends ResourceContext {
async execute() {
return { high: "4 hours" };
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Reads fail with -32603 "Resource … read failed"
execute() threw an error that isn't a PublicMcpError, so FrontMCP treats it as a failure of the server. In development, the message after read failed: is your error's message:
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({ name: "sla", uri: "policy://sla" })
export class SlaPolicy extends ResourceContext {
async execute(): Promise<unknown> {
// 🚩 A server failure, and production hides the message
throw new Error("The SLA policy hasn't been published yet");
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
With NODE_ENV=production, the client only gets Internal FrontMCP error. Please contact support with error ID: …. If the client should read the message, throw a PublicMcpError. The read then fails with -32602 and your message, in production too:
import { PublicMcpError, Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({ name: "sla", uri: "policy://sla" })
export class SlaPolicy extends ResourceContext {
async execute(): Promise<unknown> {
// ✅ The client sees exactly this message
throw new PublicMcpError("The SLA policy hasn't been published yet");
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
A message ending in read failed: Resource output not found means execute() returned nothing. Return the content, or end with this.respond(), which works in resources since 1.9.3.
Reads fail with -32003 "Resource "…" is not available in the current environment"
The resource's availableWhen doesn't match where the server runs. It's left out of resources/list, and a client that reads it by URI gets this error, with what the resource requires and what the server is:
import { Resource, ResourceContext } from "@frontmcp/sdk";
@Resource({ name: "deploy-notes", uri: "policy://deno-deploy", mimeType: "text/plain", availableWhen: { runtime: ["deno"] } })
export class DeployNotes extends ResourceContext {
async execute() {
return "Deploy with deployctl.";
}
}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
The message lists the server's OS, runtime and deployment, in production too. If the resource should be readable here, fix its availableWhen.
My resource isn't in resources/list
Check, in order:
- The class is in its app's
resourcesarray, and the app is in@FrontMcp({ apps }). - It's a
@Resource. Templates are listed separately, inresources/templates/list. - Its
availableWhenmatches the environment the server runs in.