resource

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package resource provides resource management functionality.

Package resource is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var ErrResourceNotFound = errors.New("resource not found")

ErrResourceNotFound is returned when a requested resource cannot be found.

Functions

This section is empty.

Types

type DynamicResource

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

DynamicResource implements the Resource interface for resources that are fetched dynamically by executing a tool.

func NewDynamicResource

func NewDynamicResource(def *configv1.ResourceDefinition, t tool.Tool) (*DynamicResource, error)

NewDynamicResource creates a new instance of DynamicResource.

func (*DynamicResource) Read

Read executes the associated tool to fetch the resource content.

func (*DynamicResource) Resource

func (r *DynamicResource) Resource() *mcp.Resource

Resource returns the MCP representation of the resource.

func (*DynamicResource) Service

func (r *DynamicResource) Service() string

Service returns the ID of the service that provides this resource.

func (*DynamicResource) Subscribe

func (r *DynamicResource) Subscribe(_ context.Context) error

Subscribe is not yet implemented for dynamic resources.

type Manager

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

Manager is a thread-safe implementation of the ManagerInterface. It uses a map to store resources and a mutex to protect concurrent access.

func NewManager

func NewManager() *Manager

NewManager creates and returns a new, empty Manager.

func (*Manager) AddResource

func (rm *Manager) AddResource(resource Resource)

AddResource adds a new resource to the manager. If a resource with the same URI already exists, it will be overwritten. After adding the resource, it triggers the OnListChanged callback if one is registered.

resource is the resource to be added.

func (*Manager) ClearResourcesForService

func (rm *Manager) ClearResourcesForService(serviceID string)

ClearResourcesForService removes all resources associated with a given service ID.

func (*Manager) GetResource

func (rm *Manager) GetResource(uri string) (Resource, bool)

GetResource retrieves a resource from the manager by its URI.

uri is the URI of the resource to retrieve. It returns the resource and a boolean indicating whether the resource was found.

func (*Manager) ListResources

func (rm *Manager) ListResources() []Resource

ListResources returns a slice containing all the resources currently registered in the manager.

func (*Manager) OnListChanged

func (rm *Manager) OnListChanged(f func())

OnListChanged sets a callback function that will be invoked whenever the list of resources is modified by adding or removing a resource.

f is the callback function to be set.

func (*Manager) RemoveResource

func (rm *Manager) RemoveResource(uri string)

RemoveResource removes a resource from the manager by its URI. If the resource exists, it is removed, and the OnListChanged callback is triggered if one is registered.

uri is the URI of the resource to be removed.

func (*Manager) Subscribe

func (rm *Manager) Subscribe(ctx context.Context, uri string) error

Subscribe finds a resource by its URI and calls its Subscribe method.

ctx is the context for the subscription. uri is the URI of the resource to subscribe to. It returns an error if the resource is not found or if the subscription fails.

type ManagerInterface

type ManagerInterface interface {
	// GetResource retrieves a resource by its URI.
	GetResource(uri string) (Resource, bool)
	// AddResource adds a new resource to the manager.
	AddResource(resource Resource)
	// RemoveResource removes a resource from the manager by its URI.
	RemoveResource(uri string)
	// ListResources returns a slice of all resources currently in the manager.
	ListResources() []Resource
	// OnListChanged registers a callback function to be called when the list of
	// resources changes.
	OnListChanged(func())
	// ClearResourcesForService removes all resources associated with a given service ID.
	ClearResourcesForService(serviceID string)
}

ManagerInterface defines the interface for managing a collection of resources. It provides methods for adding, removing, retrieving, and listing resources, as well as for subscribing to changes.

type MockManagerInterface

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

MockManagerInterface is a mock of ManagerInterface interface.

func NewMockManagerInterface

func NewMockManagerInterface(ctrl *gomock.Controller) *MockManagerInterface

NewMockManagerInterface creates a new mock instance.

func (*MockManagerInterface) AddResource

func (m *MockManagerInterface) AddResource(resource Resource)

AddResource mocks base method.

func (*MockManagerInterface) Clear

func (m *MockManagerInterface) Clear()

Clear mocks base method.

func (*MockManagerInterface) ClearResourcesForService

func (m *MockManagerInterface) ClearResourcesForService(serviceID string)

ClearResourcesForService mocks base method.

func (*MockManagerInterface) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockManagerInterface) GetResource

func (m *MockManagerInterface) GetResource(uri string) (Resource, bool)

GetResource mocks base method.

func (*MockManagerInterface) ListResources

func (m *MockManagerInterface) ListResources() []Resource

ListResources mocks base method.

func (*MockManagerInterface) OnListChanged

func (m *MockManagerInterface) OnListChanged(arg0 func())

OnListChanged mocks base method.

func (*MockManagerInterface) RemoveResource

func (m *MockManagerInterface) RemoveResource(uri string)

RemoveResource mocks base method.

type MockManagerInterfaceMockRecorder

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

MockManagerInterfaceMockRecorder is the mock recorder for MockManagerInterface.

func (*MockManagerInterfaceMockRecorder) AddResource

func (mr *MockManagerInterfaceMockRecorder) AddResource(resource any) *gomock.Call

AddResource indicates an expected call of AddResource.

func (*MockManagerInterfaceMockRecorder) Clear

Clear indicates an expected call of Clear.

func (*MockManagerInterfaceMockRecorder) ClearResourcesForService

func (mr *MockManagerInterfaceMockRecorder) ClearResourcesForService(serviceID any) *gomock.Call

ClearResourcesForService indicates an expected call of ClearResourcesForService.

func (*MockManagerInterfaceMockRecorder) GetResource

func (mr *MockManagerInterfaceMockRecorder) GetResource(uri any) *gomock.Call

GetResource indicates an expected call of GetResource.

func (*MockManagerInterfaceMockRecorder) ListResources

func (mr *MockManagerInterfaceMockRecorder) ListResources() *gomock.Call

ListResources indicates an expected call of ListResources.

func (*MockManagerInterfaceMockRecorder) OnListChanged

func (mr *MockManagerInterfaceMockRecorder) OnListChanged(arg0 any) *gomock.Call

OnListChanged indicates an expected call of OnListChanged.

func (*MockManagerInterfaceMockRecorder) RemoveResource

func (mr *MockManagerInterfaceMockRecorder) RemoveResource(uri any) *gomock.Call

RemoveResource indicates an expected call of RemoveResource.

type Resource

type Resource interface {
	// Resource returns the MCP representation of the resource, which includes its
	// metadata.
	Resource() *mcp.Resource
	// Service returns the ID of the service that provides this resource.
	Service() string
	// Read retrieves the content of the resource.
	Read(ctx context.Context) (*mcp.ReadResourceResult, error)
	// Subscribe establishes a subscription to the resource, allowing for
	// receiving updates.
	Subscribe(ctx context.Context) error
}

Resource defines the interface for a resource that can be managed by the Manager. Each implementation of a resource is responsible for providing its metadata and handling read and subscribe operations.

type StaticResource

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

StaticResource implements the Resource interface for resources that are defined statically in the configuration (e.g. pointing to a URL).

func NewStaticResource

func NewStaticResource(def *configv1.ResourceDefinition, serviceID string) *StaticResource

NewStaticResource creates a new instance of StaticResource.

func (*StaticResource) Read

Read retrieves the content of the resource by fetching the URI.

func (*StaticResource) Resource

func (r *StaticResource) Resource() *mcp.Resource

Resource returns the MCP representation of the resource.

func (*StaticResource) Service

func (r *StaticResource) Service() string

Service returns the ID of the service that provides this resource.

func (*StaticResource) Subscribe

func (r *StaticResource) Subscribe(_ context.Context) error

Subscribe is not yet implemented for static resources.

Jump to

Keyboard shortcuts

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