Skip to main content
These authoring exports live in @toolgrain/mcp. Wire types such as TextResourceContents, BlobResourceContents, and protocol Resource come directly from @toolgrain/protocol.

resource

Returns a frozen branded definition and preserves the reader’s inferred return type. The reader must be a function. Metadata is validated and copied when the definition is registered with a server; construction does not read content.

ResourceDefinition and ResourceMetadata

ResourceDefinition<Result> combines readonly protocol resource metadata with read(uri: string, ctx: ToolContext): Result. ResourceMetadata is the readonly protocol resource description. Resource<Result> is a type-only export describing the branded definition; construct it with resource(). Like tools, compatible duplicate package copies recognize each other’s definitions. Object spreads must pass through the helper again before registration.

ResourceReadResult

This sketch omits recursive readonly details. Nested authoring arrays and metadata also accept readonly inputs. Text/blob entries supply their own absolute URI and optional MIME type/metadata. Toolgrain does not fill these fields from listing metadata or automatically encode binary data. Return base64 strings for blob. Empty contents are valid for an existing resource. Results and metadata are validated and copied at server conversion; direct read() calls bypass this work.

Server registration

ServerOptions.resources?: readonly Resource[] registers the static resource list. The optional array enables the capability even when empty. Duplicate URIs, invalid metadata, or unbranded definitions fail construction. tools remains required; resource-only applications pass tools: {}. The same reader and metadata serve both supported revisions and every authorized caller. Context uses existing auth accessors, lazy providers, and cooperative cancellation. See resource behavior for response fields, error codes, and deferred features.