Skip to main content

Module resource

Module resource 

Source
Expand description

Type-safe MCP resource definitions

This module provides a high-level API for defining MCP resources with compile-time type checking and automatic JSON generation for the resources/list, resources/templates/list, and resources/read protocol messages.

Structs§

CompiledTemplateMatcher
Pre-compiled URI template matcher. Built once at initialization time so that read_resource dispatch only runs the regex (no compilation overhead per request).
Resource
A resource definition for the resources/list response
ResourceBuilder
Builder for creating resources with a fluent API
ResourceContent
Content of a resource, either text or binary (base64-encoded).
ResourceTemplate
Parameterized resource definition for resources/templates/list and template-based reads.
ResourceTemplateBuilder

Functions§

match_uri_against_template
Match uri against a template string with {var} placeholders.

Type Aliases§

GenericResourceReadHandler
Fallback handler when no static resource or template matches (user parses URI as needed).
ResourceContents
Collection of resource contents (e.g. multi-part resource)
ResourceHandler
Resource read handler function type
TemplateResourceHandler
Handler for a URI template match: receives the request URI and extracted {name} values.