Resources are part of the Model Context Protocol (MCP) specification. WebMCP implements resources for browser environments, enabling web applications to expose data to AI agents.
Overview
When to Use Resources
Configuration Data
Expose application settings and preferences
File Systems
Provide access to virtual or real file content
Dynamic State
Share current application state with AI
External Data
Proxy API responses and external content
Static Resources
Register a resource with a fixed URI:Template Resources
Use URI templates with{param} placeholders for dynamic access:
Multiple Parameters
Templates can have multiple parameters:How AI Agents Read Resources
When an AI agent wants to read a resource, it callsreadResource() through the MCP protocol. This invokes your registered read() handler:
The
readResource() method is called by AI agents through the MCP protocol, not directly from your application code. Your read() handler is invoked automatically when an agent requests the resource.Listing Resources
Multiple Contents
Resources can return multiple content items:Binary Content
Resources can return binary content using base64 encoding:Dynamic vs Static Registration
- Dynamic (registerResource)
- Static (provideContext)
Use Use for:
registerResource() for resources that may change at runtime:- Session-specific data
- Component-scoped resources
- Temporary data access
URI Scheme Conventions
Best Practices
Use meaningful URI schemes
Use meaningful URI schemes
Choose URI schemes that indicate the data type:
Always specify MIME types
Always specify MIME types
Help AI agents parse content correctly:
Handle errors gracefully
Handle errors gracefully
Return helpful error information:
Keep content focused
Keep content focused
Return only relevant data. Let AI agents request specific resources rather than dumping everything.
Document available resources
Document available resources
Use clear descriptions so AI agents know what resources are available and what they contain.
Common Patterns
Configuration Resources
Database Records
Real-Time State
Related Documentation
Live Resource Examples
Interactive resource demonstrations
Prompts
Generating messages for AI agents
Tool Registration
Executing actions for AI agents
Schemas
Schema validation patterns
