Documentation
¶
Overview ¶
Package resource provides resource management functionality.
Package resource is a generated GoMock package.
Index ¶
- Variables
- type DynamicResource
- type Manager
- func (rm *Manager) AddResource(resource Resource)
- func (rm *Manager) ClearResourcesForService(serviceID string)
- func (rm *Manager) GetResource(uri string) (Resource, bool)
- func (rm *Manager) ListResources() []Resource
- func (rm *Manager) OnListChanged(f func())
- func (rm *Manager) RemoveResource(uri string)
- func (rm *Manager) Subscribe(ctx context.Context, uri string) error
- type ManagerInterface
- type MockManagerInterface
- func (m *MockManagerInterface) AddResource(resource Resource)
- func (m *MockManagerInterface) Clear()
- func (m *MockManagerInterface) ClearResourcesForService(serviceID string)
- func (m *MockManagerInterface) EXPECT() *MockManagerInterfaceMockRecorder
- func (m *MockManagerInterface) GetResource(uri string) (Resource, bool)
- func (m *MockManagerInterface) ListResources() []Resource
- func (m *MockManagerInterface) OnListChanged(arg0 func())
- func (m *MockManagerInterface) RemoveResource(uri string)
- type MockManagerInterfaceMockRecorder
- func (mr *MockManagerInterfaceMockRecorder) AddResource(resource any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) Clear() *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) ClearResourcesForService(serviceID any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) GetResource(uri any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) ListResources() *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) OnListChanged(arg0 any) *gomock.Call
- func (mr *MockManagerInterfaceMockRecorder) RemoveResource(uri any) *gomock.Call
- type Resource
- type StaticResource
Constants ¶
This section is empty.
Variables ¶
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 ¶
func (r *DynamicResource) Read(ctx context.Context) (*mcp.ReadResourceResult, error)
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.
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 (*Manager) AddResource ¶
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 ¶
ClearResourcesForService removes all resources associated with a given service ID.
func (*Manager) GetResource ¶
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 ¶
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 ¶
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.
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 ¶
func (m *MockManagerInterface) EXPECT() *MockManagerInterfaceMockRecorder
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 ¶
func (mr *MockManagerInterfaceMockRecorder) Clear() *gomock.Call
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 ¶
func (r *StaticResource) Read(ctx context.Context) (*mcp.ReadResourceResult, error)
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.