Documentation
¶
Overview ¶
Package resource registers static and RFC 6570 URI-template MCP resources.
Read handlers return Text, Blob, JSON, or Raw content. The package supplies the URI and default MIME type except for Raw. Template handlers also receive the concrete URI and extracted Vars.
NewTemplate panics on an invalid template, and Resource.Add panics on an invalid URI. ErrNotFound and ErrTemplateMismatch become the SDK resource not-found error. ErrNoContent reports a nil Content or empty Raw result.
The package does not configure resource subscriptions. Configure subscription handlers when constructing the underlying mcp.Server.
Index ¶
Constants ¶
const ( // MIMEText is the fallback MIME type for Text content. MIMEText = "text/plain" // MIMEBlob is the fallback MIME type for Blob content. MIMEBlob = "application/octet-stream" // MIMEJSON is the fixed MIME type for JSON content. MIMEJSON = "application/json" )
Default MIME types for Content values.
Variables ¶
var ( // ErrNotFound signals a resource (or templated instance) does not exist. ErrNotFound = errors.New("resource not found") // ErrTemplateMismatch signals a read URI did not match the URI template. ErrTemplateMismatch = errors.New("uri does not match template") // ErrInvalidVars signals a template variable could not be converted. ErrInvalidVars = errors.New("invalid template variable") // ErrNoContent signals a nil Content or empty Raw result. ErrNoContent = errors.New("resource produced no content") )
Resource errors are package-specific matchable sentinels.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content interface {
// contains filtered or unexported methods
}
Content produces one resource read result.
type Raw ¶
type Raw struct {
Contents []*mcp.ResourceContents
}
Raw serves non-empty SDK content blocks without modification.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource is a value builder for a static MCP resource.
func (Resource) Add ¶
func (r Resource) Add()
Add registers the resource and panics if its URI is invalid.
func (Resource) WithAnnotations ¶
func (r Resource) WithAnnotations(a *mcp.Annotations) Resource
WithAnnotations attaches client annotations to the resource.
func (Resource) WithDescription ¶
WithDescription overrides the description passed to New.
func (Resource) WithMIMEType ¶
WithMIMEType sets the resource's declared MIME type.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a value builder for an RFC 6570 resource template.
func NewTemplate ¶
func NewTemplate( server *mcp.Server, uriTemplate, name, description string, read TemplateReadFunc, ) Template
NewTemplate creates a builder and panics if uriTemplate is invalid.
func (Template) WithAnnotations ¶
func (t Template) WithAnnotations(a *mcp.Annotations) Template
WithAnnotations attaches client annotations to the template.
func (Template) WithDescription ¶
WithDescription overrides the description passed to NewTemplate.
func (Template) WithMIMEType ¶
WithMIMEType sets the MIME type shared by resources matching the template.
type TemplateReadFunc ¶
TemplateReadFunc reads a concrete URI and its template variables.
type Vars ¶
type Vars struct {
// contains filtered or unexported fields
}
Vars holds the variables extracted from a matched URI template.