Documentation Index Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
Use this file to discover all available pages before exploring further.
Basic Usage
import { Resource , ResourceContext } from ' @frontmcp/sdk ' ;
@ Resource ({
name : ' app-config ' ,
uri : ' config://app ' ,
mimeType : ' application/json ' ,
description : ' Application configuration ' ,
})
class AppConfigResource extends ResourceContext {
async execute ( uri : string ) {
return {
contents : [{
uri ,
mimeType : ' application/json ' ,
text : JSON . stringify ({ version : ' 1.0.0 ' , debug : false }),
}],
};
}
}
Signature
function Resource ( opts : ResourceMetadata ): TypedClassDecorator
Type Safety
The @Resource decorator validates at compile time that the decorated class extends ResourceContext. Using it on a plain class produces a descriptive compile error.
The same applies to @ResourceTemplate.
Configuration Options
Required Properties
Property Type Description namestringUnique resource identifier uristringResource URI (must be valid per RFC 3986)
Optional Properties
Property Type Description titlestringHuman-readable title descriptionstringResource description mimeTypestringMIME type (e.g., ‘application/json’) iconsIcon[]Icons for display
URI Schemes
Resources can use any valid URI scheme:
// File scheme
@ Resource ({
name : ' readme ' ,
uri : ' file:///docs/README.md ' ,
mimeType : ' text/markdown ' ,
})
// Custom scheme
@ Resource ({
name : ' database-schema ' ,
uri : ' db://schema/users ' ,
mimeType : ' application/json ' ,
})
// HTTPS scheme
@ Resource ({
name : ' api-spec ' ,
uri : ' https://api.example.com/openapi.json ' ,
mimeType : ' application/json ' ,
})
Resources must return ReadResourceResult:
interface ReadResourceResult {
contents : Array <{
uri : string ;
mimeType ?: string ;
text ?: string ; // Text content
blob ?: string ; // Base64-encoded binary content
}>;
}
Text Content
@ Resource ({ name : ' text-file ' , uri : ' file://readme.txt ' })
class TextResource extends ResourceContext {
async execute ( uri : string ) {
return {
contents : [{
uri ,
mimeType : ' text/plain ' ,
text : ' Hello, World! ' ,
}],
};
}
}
Binary Content
@ Resource ({ name : ' image ' , uri : ' file://logo.png ' , mimeType : ' image/png ' })
class ImageResource extends ResourceContext {
async execute ( uri : string ) {
const imageBuffer = await readFile ( ' /path/to/logo.png ' );
return {
contents : [{
uri ,
mimeType : ' image/png ' ,
blob : imageBuffer . toString ( ' base64 ' ),
}],
};
}
}
Function-Based Alternative
import { resource } from ' @frontmcp/sdk ' ;
const appConfig = resource ({
name : ' app-config ' ,
uri : ' config://app ' ,
mimeType : ' application/json ' ,
})(( uri , params ) => ({
contents : [{
uri ,
mimeType : ' application/json ' ,
text : JSON . stringify ({ version : ' 1.0.0 ' }),
}],
}));
Context Methods
The ResourceContext base class provides:
async execute ( uri : string , params : Record < string , string >) {
// Dependency injection
const db = this . get ( DatabaseToken );
// Logging
this . logger . info ( ' Reading resource ' , { uri });
// Authentication
const auth = this . getAuthInfo ();
// Access scope
const tools = this . scope . tools ;
// Error handling
if (! exists ) {
this . fail ( new ResourceNotFoundError ( uri ));
}
// Early return
this . respond ({ contents : [...] });
}
Full Example
import { Resource , ResourceContext , App , FrontMcp } from ' @frontmcp/sdk ' ;
@ Resource ({
name : ' system-status ' ,
uri : ' status://system ' ,
title : ' System Status ' ,
description : ' Current system health and metrics ' ,
mimeType : ' application/json ' ,
})
class SystemStatusResource extends ResourceContext {
async execute ( uri : string ) {
this . mark ( ' fetching-metrics ' );
const metrics = {
uptime : process . uptime (),
memory : process . memoryUsage (),
timestamp : new Date (). toISOString (),
};
return {
contents : [{
uri ,
mimeType : ' application/json ' ,
text : JSON . stringify ( metrics , null , 2 ),
}],
};
}
}
@ App ({
name : ' monitoring ' ,
resources : [ SystemStatusResource ],
})
class MonitoringApp {}
@ FrontMcp ({
info : { name : ' Monitor ' , version : ' 1.0.0 ' },
apps : [ MonitoringApp ],
})
export default class MonitorServer {}
@ResourceTemplate Dynamic URI templates
ResourceContext Context class details
ResourceRegistry Resource registry API
Resource Errors Resource-related errors