resources

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package resources provides the resource registry for the MCP server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(r *Registry, uri, name, description string, handler func(ctx context.Context, uri string) (Result, error), opts ...Option) error

Register adds a static resource to the registry.

func RegisterTemplate

func RegisterTemplate(r *Registry, uriTemplate, name, description string, handler func(ctx context.Context, uri string) (Result, error), opts ...Option) error

RegisterTemplate adds a URI template resource to the registry.

Types

type ContentBlock

type ContentBlock struct {
	Blob     string `json:"blob,omitempty"`
	MimeType string `json:"mimeType,omitempty"`
	Text     string `json:"text,omitempty"`
	URI      string `json:"uri"`
}

ContentBlock represents a single content item in a resource read result.

type Option

type Option func(*Resource)

Option configures a Resource during registration.

func WithMimeType

func WithMimeType(mimeType string) Option

WithMimeType returns an Option that sets the resource's MIME type.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds registered resources sorted alphabetically by URI. Not safe for concurrent use — register all resources before starting the server.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty resource registry.

func (*Registry) Lookup

func (r *Registry) Lookup(uri string) (Resource, bool)

Lookup finds a resource by URI in O(1) via the index map.

func (*Registry) LookupTemplate added in v0.6.3

func (r *Registry) LookupTemplate(uri string) (ResourceTemplate, bool)

LookupTemplate finds the first template whose URI pattern matches the given URI. Returns the template and true if a match is found. Templates use RFC 6570 Level 1 syntax: literal segments plus {variable} placeholders that each match one or more characters.

func (*Registry) Resources

func (r *Registry) Resources() []Resource

Resources returns a copy of all registered static resources in alphabetical order.

func (*Registry) Templates

func (r *Registry) Templates() []ResourceTemplate

Templates returns a copy of all registered resource templates in alphabetical order.

type Resource

type Resource struct {
	Description string          `json:"description,omitempty"`
	Handler     resourceHandler `json:"-"`
	MimeType    string          `json:"mimeType,omitempty"`
	Name        string          `json:"name"`
	URI         string          `json:"uri"`
}

Resource represents a registered MCP resource.

type ResourceTemplate

type ResourceTemplate struct {
	Description string          `json:"description,omitempty"`
	Handler     templateHandler `json:"-"`
	MimeType    string          `json:"mimeType,omitempty"`
	Name        string          `json:"name"`
	URITemplate string          `json:"uriTemplate"`
}

ResourceTemplate represents a URI template for dynamic resources.

type Result

type Result struct {
	Contents []ContentBlock `json:"contents"`
}

Result is the outcome of reading a resource.

func BlobResult

func BlobResult(uri, blob, mimeType string) Result

BlobResult creates a Result with a single base64-encoded content block.

func TextResult

func TextResult(uri, text string) Result

TextResult creates a Result with a single text content block.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL