Skip to main content

What are Resources?

In MCP, resources are data sources that servers expose to clients. Unlike tools (which perform actions), resources provide read-only access to information. Resources are ideal for:
  • Providing contextual data to AI models
  • Exposing database records
  • Sharing configuration data
  • Serving files or documents
  • Delivering API responses

Resource Types

MCP supports two types of resources:

1. Static Resources

Static resources have fixed URIs and are listed in resources/list:

2. Dynamic Resources (Templates)

Dynamic resources use URI templates with variables, listed in resources/templates/list:

Defining Static Resources

Basic Static Resource

From source/servers/basic/src/server.ts:142-164:

Resource Response Format

Resources return an array of content objects:

Defining Dynamic Resources

Resource Templates

From source/servers/basic/src/server.ts:166-211:

URI Template Syntax

URI templates use curly braces for variables:

Reading Resources from Clients

Reading Static Resources

From source/clients/basic-ts/src/index.ts:53-59 and source/clients/basic-py/main.py:43-46:

Reading Dynamic Resources

From source/clients/basic-ts/src/index.ts:61-67 and source/clients/basic-py/main.py:48-51:

Discovering Available Resources

Content Types

Text Content

Most common for JSON, plain text, or formatted data:

Binary Content

For images, PDFs, or other binary data:

Common MIME Types

  • text/plain - Plain text
  • application/json - JSON data
  • text/html - HTML content
  • text/markdown - Markdown
  • image/png, image/jpeg - Images
  • application/pdf - PDF documents

Resource vs Tool: When to Use Which?

  • You’re providing read-only data
  • The data is contextual information for AI models
  • You want to expose files or documents
  • The operation has no side effects
Examples:
  • Configuration files
  • Database records (read-only)
  • API responses (read-only)
  • Documentation
  • You’re performing actions or computations
  • The operation has side effects (create, update, delete)
  • You need to execute logic based on inputs
  • The result depends on complex processing
Examples:
  • Calculations
  • CRUD operations
  • External API calls that modify data
  • File operations (write, delete)

Resource Best Practices

Use Clear URI Schemes

Choose URI schemes that clearly indicate the resource type:

Validate Template Parameters

Always validate dynamic resource parameters:

Handle Missing Data

Return helpful errors when data isn’t found:

Use Appropriate MIME Types

Set the correct MIME type for your content:

Advanced Patterns

Paginated Resources

Filtered Resources

Cached Resources

Resource Change Notifications

If your resources can change, enable the listChanged capability:
This allows clients to be notified when the list of available resources changes, enabling dynamic resource discovery.

Next Steps

Prompts

Learn how to create reusable prompt templates

Tools

Understand how to implement executable tools

Servers

Build complete MCP servers

Clients

Create clients that consume resources