Skip to main content
Resources in WebMCP are data endpoints that AI agents can read. They expose dynamic or static content like configuration, files, or API data to AI models.
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 calls readResource() 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

Use registerResource() for resources that may change at runtime:
Use for:
  • Session-specific data
  • Component-scoped resources
  • Temporary data access

URI Scheme Conventions

Best Practices

Choose URI schemes that indicate the data type:
Help AI agents parse content correctly:
Return helpful error information:
Return only relevant data. Let AI agents request specific resources rather than dumping everything.
Use clear descriptions so AI agents know what resources are available and what they contain.

Common Patterns

Configuration Resources

Database Records

Real-Time State

Live Resource Examples

Interactive resource demonstrations

Prompts

Generating messages for AI agents

Tool Registration

Executing actions for AI agents

Schemas

Schema validation patterns