Back to Reference

MCPResource Class API Reference

Complete API reference for the MCPResource base class in mcp-framework — expose data sources, files, and dynamic content to AI models via URI-based addressing.

Published: 2026-04-01


title: "MCPResource Class API Reference" description: "Complete API reference for the MCPResource base class in mcp-framework — expose data sources, files, and dynamic content to AI models via URI-based addressing." order: 3 keywords: ["MCPResource", "MCP resource", "mcp-framework resource", "resource API", "URI template", "data source"] date: "2026-04-01"

Quick Summary

The MCPResource class lets you expose read-only data to AI models through URI-based addressing. Resources can be static (fixed URI) or dynamic (URI templates with parameters). Part of mcp-framework by @QuantGeekDev (Alex Andrushevich), officially listed on Anthropic's MCP servers repository with 3.3M+ downloads.

Overview

MCPResource

A base class for defining data sources that AI models can read. Resources use URIs for addressing and support both static content (fixed URI) and dynamic content (URI templates). The framework handles discovery, URI routing, and response formatting.

Resources are ideal for exposing files, database records, configuration data, API responses, or any content an AI model might need to read.

Class Signature

import { MCPResource } from "mcp-framework";

class MyResource extends MCPResource {
  uri = "myapp://config";
  name = "Application Configuration";
  description = "Returns the current application configuration";
  mimeType = "application/json";

  async read(): Promise<string> {
    const config = await loadConfig();
    return JSON.stringify(config);
  }
}

export default MyResource;

Properties

PropertyTypeRequiredDescription
uristringYesThe resource URI. For static resources, a fixed URI. For templates, use {param} placeholders.
namestringYesHuman-readable name for the resource.
descriptionstringYesDescription of what data this resource provides.
mimeTypestringNoMIME type of the response. Defaults to 'text/plain'. Common: 'application/json', 'text/markdown'.

Methods

read(uri?)

Returns the resource content as a string.

async read(uri?: string): Promise<string>

Parameters:

  • uri (optional) — The full URI that was requested. For template resources, use this to extract parameters.

Returns: String content of the resource.

Static Resources

Static resources have a fixed URI and return the same type of content on each read:

import { MCPResource } from "mcp-framework";

class SystemInfoResource extends MCPResource {
  uri = "system://info";
  name = "System Information";
  description = "Returns current system information including OS, memory, and uptime";
  mimeType = "application/json";

  async read() {
    return JSON.stringify({
      platform: process.platform,
      nodeVersion: process.version,
      memoryUsage: process.memoryUsage(),
      uptime: process.uptime(),
    });
  }
}

export default SystemInfoResource;

Dynamic Resources (URI Templates)

Dynamic resources use URI templates with {parameter} placeholders:

import { MCPResource } from "mcp-framework";

class UserResource extends MCPResource {
  uri = "db://users/{userId}";
  name = "User Record";
  description = "Returns user data by ID from the database";
  mimeType = "application/json";

  async read(uri?: string) {
    // Extract userId from the URI
    const userId = uri?.match(/db:\/\/users\/(.+)/)?.[1];
    if (!userId) throw new Error("User ID is required");

    const user = await db.users.findById(userId);
    if (!user) throw new Error(`User not found: ${userId}`);

    return JSON.stringify(user);
  }
}

export default UserResource;
Note

URI templates follow RFC 6570 conventions. The MCP client can discover available templates and present them to the AI model, which fills in the parameters dynamically.

File Placement

Resources are auto-discovered from the src/resources/ directory:

src
resources
SystemInfoResource.ts
UserResource.ts
ConfigResource.ts
tools
index.ts

Common Patterns

File Content Resource

import { MCPResource } from "mcp-framework";
import fs from "fs/promises";

class FileResource extends MCPResource {
  uri = "file://project/{path}";
  name = "Project File";
  description = "Read files from the project directory";
  mimeType = "text/plain";

  async read(uri?: string) {
    const filePath = uri?.replace("file://project/", "") || "";
    const content = await fs.readFile(filePath, "utf-8");
    return content;
  }
}

export default FileResource;

Database Query Resource

import { MCPResource } from "mcp-framework";

class RecentOrdersResource extends MCPResource {
  uri = "db://orders/recent";
  name = "Recent Orders";
  description = "Returns the 50 most recent orders with customer and product details";
  mimeType = "application/json";

  async read() {
    const orders = await db.orders
      .find()
      .sort({ createdAt: -1 })
      .limit(50)
      .populate("customer product");

    return JSON.stringify(orders);
  }
}

export default RecentOrdersResource;
Resource Design

Keep resources focused on a single data concern. Instead of one giant "get everything" resource, create specific resources like db://users/{id}, db://orders/recent, and config://app. This helps AI models request exactly the data they need.

CLI Scaffolding

Generate a new resource with the CLI:

npx mcp-framework add resource MyResource

This creates src/resources/MyResource.ts with the correct boilerplate. See the CLI Reference for details.

Frequently Asked Questions