Read an authorized resource bundle¶
Resources are an optional container beside the operation registry. Register each resource explicitly, then provide a resolver, a per-item reader and a resource policy. The resolver returns a complete ordered plan before the module reads any bodies.
requested, err := mcp.NewResourceTarget(mcp.ResourceTargetSpec{URI: "bundle://project/preview"})
if err != nil {
return err
}
image, err := mcp.NewResourceTarget(mcp.ResourceTargetSpec{
URI: "asset://project/image/thumbnail",
Representation: "thumbnail",
AuthorizationData: json.RawMessage(`{"asset":"image","revision":3}`),
})
if err != nil {
return err
}
plan, err := mcp.NewResourceReadPlan(requested, []mcp.ResourceTarget{image})
ResourceBinding.Resolve returns this plan after validating the untrusted match variables and deriving application-canonical
identities. Its Read callback receives one authorized target and returns NewResourcePayload(ResourceBlob(bytes),
"image/png", metadata) or a text payload. It cannot change the output URI or append unplanned assets.
All four resource policy callbacks are required. Discover controls registered descriptions; Visible controls inclusion
in the caller's selection and optional issue-URI disclosure; Read controls body access; ScopeKey binds listing cursors
to the effective principal and permission revision. A visible read denial produces a warning if another item survives.
A hidden item produces no warning, count or body read.
Call resources.Read(ctx, uri) and check its error first. A nil error can mean a complete bundle or a usable partial bundle:
inspect Partial(), Issues() and IssuesOmitted(). Partial Items() starts with the generated warning, followed by whole
application items in plan order. Whole-read errors return no bundle. Keep body reads bounded in your storage adapter and
use the same stable target/representation when enforcing storage permissions.
The executable ExampleResources_Read in resource_example_test.go shows a complete registration and a partial read.
The resource reference defines routing, authorization, reporting and sizing contracts.