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 inresources/list:
2. Dynamic Resources (Templates)
Dynamic resources use URI templates with variables, listed inresources/templates/list:
Defining Static Resources
Basic Static Resource
Fromsource/servers/basic/src/server.ts:142-164:
Resource Response Format
Resources return an array of content objects:Defining Dynamic Resources
Resource Templates
Fromsource/servers/basic/src/server.ts:166-211:
URI Template Syntax
URI templates use curly braces for variables:Reading Resources from Clients
Reading Static Resources
Fromsource/clients/basic-ts/src/index.ts:53-59 and source/clients/basic-py/main.py:43-46:
Reading Dynamic Resources
Fromsource/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 textapplication/json- JSON datatext/html- HTML contenttext/markdown- Markdownimage/png,image/jpeg- Imagesapplication/pdf- PDF documents
Resource vs Tool: When to Use Which?
Use Resources When...
Use Resources When...
- 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
- Configuration files
- Database records (read-only)
- API responses (read-only)
- Documentation
Use Tools When...
Use Tools When...
- 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
- 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 thelistChanged 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