Expose data and content from your servers to LLMs
Resources are a core primitive in the Model Context Protocol (MCP) that allow servers to expose data and content that can be read by clients and used as context for LLM interactions.
Resources are designed to be application-controlled, meaning that the client application can decide how and when they should be used. Different MCP clients may handle resources differently. For example:
Server authors should be prepared to handle any of these interaction patterns when implementing resource support. In order to expose data to models automatically, server authors should use a model-controlled primitive such as Tools.
Resources represent any kind of data that an MCP server wants to make available to clients. This can include:
Each resource is identified by a unique URI and can contain either text or binary data.
Resources are identified using URIs that follow this format:
[protocol]://[host]/[path]
For example:
file:///home/user/documents/report.pdf
postgres://database/customers/schema
screen://localhost/display1
The protocol and path structure is defined by the MCP server implementation. Servers can define their own custom URI schemes.
Resources can contain two types of content:
Text resources contain UTF-8 encoded text data. These are suitable for:
Binary resources contain raw binary data encoded in base64. These are suitable for:
Clients can discover available resources through two main methods:
Servers expose a list of resources via the resources/list
request. Each resource includes:
{
uri: string; // Unique identifier for the resource
name: string; // Human-readable name
description?: string; // Optional description
mimeType?: string; // Optional MIME type
size?: number; // Optional size in bytes
}
For dynamic resources, servers can expose URI templates that clients can use to construct valid resource URIs:
{
uriTemplate: string; // URI template following RFC 6570
name: string; // Human-readable name for this type
description?: string; // Optional description
mimeType?: string; // Optional MIME type for all matching resources
}
To read a resource, clients make a resources/read
request with the resource URI.
The server responds with a list of resource contents:
{
contents: [
{
uri: string; // The URI of the resource
mimeType?: string; // Optional MIME type
// One of:
text?: string; // For text resources
blob?: string; // For binary resources (base64 encoded)
}
]
}
Servers may return multiple resources in response to one resources/read
request. This could be used, for example, to return a list of files inside a directory when the directory is read.
MCP supports real-time updates for resources through two mechanisms:
Servers can notify clients when their list of available resources changes via the notifications/resources/list_changed
notification.
Clients can subscribe to updates for specific resources:
resources/subscribe
with resource URInotifications/resources/updated
when the resource changesresources/read
resources/unsubscribe
Here’s a simple example of implementing resource support in an MCP server:
const server = new Server({
name: "example-server",
version: "1.0.0"
}, {
capabilities: {
resources: {}
}
});
// List available resources
server.setRequestHandler(ListResourcesRequestSchema, async () => {
return {
resources: [
{
uri: "file:///logs/app.log",
name: "Application Logs",
mimeType: "text/plain"
}
]
};
});
// Read resource contents
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
const uri = request.params.uri;
if (uri === "file:///logs/app.log") {
const logContents = await readLogFile();
return {
contents: [
{
uri,
mimeType: "text/plain",
text: logContents
}
]
};
}
throw new Error("Resource not found");
});
When implementing resource support:
When exposing resources:
Was this page helpful?