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.
Summary: Represents a ErrResourceNotFound.
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.
Summary: Represents a DynamicResource.
func NewDynamicResource ¶
func NewDynamicResource(def *configv1.ResourceDefinition, t tool.Tool) (*DynamicResource, error)
NewDynamicResource creates a new instance of DynamicResource.
Summary: Initializes a dynamic resource backed by a tool.
Parameters:
- def: *configv1.ResourceDefinition. The resource definition.
- t: tool.Tool. The tool used to fetch the resource content.
Returns:
- *DynamicResource: The initialized dynamic resource.
- error: An error if validation fails.
func (*DynamicResource) Read ¶
func (r *DynamicResource) Read(ctx context.Context) (*mcp.ReadResourceResult, error)
Read executes the associated tool to fetch the resource content.
Summary: Fetches the resource content by executing the tool.
Parameters:
- ctx: context.Context. The context for the request.
Returns:
- *mcp.ReadResourceResult: The resource content.
- error: An error if the tool execution fails.
Side Effects:
- Executes the underlying tool, which may have its own side effects.
func (*DynamicResource) Resource ¶
func (r *DynamicResource) Resource() *mcp.Resource
Resource returns the MCP representation of the resource.
Summary: Retrieves the MCP resource metadata.
Returns:
- *mcp.Resource: The MCP resource definition.
func (*DynamicResource) Service ¶
func (r *DynamicResource) Service() string
Service returns the ID of the service that provides this resource.
Summary: Retrieves the service ID.
Returns:
- string: The service ID.
func (*DynamicResource) Subscribe ¶
func (r *DynamicResource) Subscribe(_ context.Context) error
Subscribe is not yet implemented for dynamic resources.
Summary: Subscribes to resource updates (Not Implemented).
Parameters:
- _: context.Context. Unused.
Returns:
- error: Always returns an error indicating not implemented.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is a thread-safe implementation of the ManagerInterface.
Summary: Thread-safe resource manager implementation.
It manages the lifecycle and retrieval of resources, providing thread-safe access and efficient listing via caching.
func NewManager ¶
func NewManager() *Manager
NewManager creates and returns a new, empty Manager.
Summary: Creates a new resource manager.
Returns:
- *Manager: A new Manager instance.
func (*Manager) AddResource ¶
AddResource adds a new resource to the manager.
Summary: Adds a resource to the manager.
Parameters:
- resource: Resource. The resource to add.
Returns:
None.
Side Effects:
- Updates the internal resource storage.
- Invalidates the list cache.
- Triggers the on-change callback if registered.
func (*Manager) ClearResourcesForService ¶
ClearResourcesForService removes all resources associated with a given service ID.
Summary: Clears resources for a specific service.
Parameters:
- serviceID: string. The service ID.
Returns:
None.
Side Effects:
- Removes matching resources from storage.
- Invalidates the list cache.
- Triggers the on-change callback.
func (*Manager) GetResource ¶
GetResource retrieves a resource from the manager by its URI.
Summary: Retrieves a resource by URI.
Parameters:
- uri: string. The URI of the resource.
Returns:
- Resource: The resource instance.
- bool: True if found, false otherwise.
func (*Manager) ListResources ¶
ListResources returns a slice containing all the resources currently registered in the manager.
Summary: Lists all managed resources.
It uses a read-through cache (double-checked locking) to minimize allocation overhead for frequent calls.
Returns:
- []Resource: A slice of currently registered resources.
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.
Summary: Registers a callback for list changes.
Parameters:
- f: func(). The callback function.
Returns:
None.
func (*Manager) RemoveResource ¶
RemoveResource removes a resource from the manager by its URI.
Summary: Removes a resource from the manager.
Parameters:
- uri: string. The URI of the resource.
Returns:
None.
Side Effects:
- Updates the internal resource storage.
- Invalidates the list cache.
- Triggers the on-change callback if registered.
func (*Manager) Subscribe ¶
Subscribe finds a resource by its URI and calls its Subscribe method.
Summary: Subscribes to a resource.
Parameters:
- ctx: context.Context. The context for the subscription.
- uri: string. The URI of the resource.
Returns:
- error: An error if resource not found or subscription fails.
type ManagerInterface ¶
type ManagerInterface interface {
// GetResource retrieves a resource by its URI.
//
// Parameters:
// - uri: string. The URI of the resource.
//
// Returns:
// - Resource: The resource instance.
// - bool: True if found, false otherwise.
GetResource(uri string) (Resource, bool)
// AddResource adds a new resource to the manager.
//
// Parameters:
// - resource: Resource. The resource to add.
//
// Returns:
// None.
AddResource(resource Resource)
// RemoveResource removes a resource from the manager by its URI.
//
// Parameters:
// - uri: string. The URI of the resource to remove.
//
// Returns:
// None.
RemoveResource(uri string)
// ListResources returns a slice of all resources currently in the manager.
//
// Returns:
// - []Resource: A slice of resources.
ListResources() []Resource
// OnListChanged registers a callback function to be called when the list of resources changes.
//
// Parameters:
// - f: func(). The callback function to execute on change.
//
// Returns:
// None.
OnListChanged(f func())
// ClearResourcesForService removes all resources associated with a given service ID.
//
// Parameters:
// - serviceID: string. The service ID.
//
// Returns:
// None.
ClearResourcesForService(serviceID string)
}
ManagerInterface defines the interface for managing a collection of resources.
Summary: Interface for resource management.
It provides methods for adding, removing, listing, and retrieving resources, as well as managing callbacks for list changes.
type MockManagerInterface ¶
type MockManagerInterface struct {
// contains filtered or unexported fields
}
MockManagerInterface is a mock of ManagerInterface interface.
Summary: Represents a MockManagerInterface.
func NewMockManagerInterface ¶
func NewMockManagerInterface(ctrl *gomock.Controller) *MockManagerInterface
NewMockManagerInterface creates a new mock instance. ctrl is the ctrl. Returns the result.
Parameters:
- ctrl (*gomock.Controller): The ctrl parameter.
Returns:
- *MockManagerInterface: The resulting *MockManagerInterface.
Errors:
- None
Side Effects:
- None
Summary: Initializes NewMockManagerInterface operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) AddResource ¶
func (m *MockManagerInterface) AddResource(resource Resource)
AddResource mocks base method. resource is the resource.
Parameters:
- resource (Resource): The resource parameter.
Returns:
- None
Errors:
- None
Side Effects:
- None
Summary: Executes AddResource operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) Clear ¶
func (m *MockManagerInterface) Clear()
Clear mocks base method.
Parameters:
- None
Returns:
- None
Errors:
- None
Side Effects:
- None
Summary: Executes Clear operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) ClearResourcesForService ¶
func (m *MockManagerInterface) ClearResourcesForService(serviceID string)
ClearResourcesForService mocks base method. serviceID is the serviceID.
Parameters:
- serviceID (string): The serviceID parameter.
Returns:
- None
Errors:
- None
Side Effects:
- None
Summary: Executes ClearResourcesForService operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) EXPECT ¶
func (m *MockManagerInterface) EXPECT() *MockManagerInterfaceMockRecorder
EXPECT returns an object that allows the caller to indicate expected use. Returns the result.
Parameters:
- None
Returns:
- *MockManagerInterfaceMockRecorder: The resulting *MockManagerInterfaceMockRecorder.
Errors:
- None
Side Effects:
- None
Summary: Executes EXPECT operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) GetResource ¶
func (m *MockManagerInterface) GetResource(uri string) (Resource, bool)
GetResource mocks base method. uri is the uri. Returns the result. Returns true if successful.
Parameters:
- uri (string): The uri parameter.
Returns:
- Resource: The resulting Resource.
- bool: True if successful, false otherwise.
Errors:
- None
Side Effects:
- None
Summary: Retrieves GetResource operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) ListResources ¶
func (m *MockManagerInterface) ListResources() []Resource
ListResources mocks base method. Returns the result.
Parameters:
- None
Returns:
- []Resource: The resulting []Resource.
Errors:
- None
Side Effects:
- None
Summary: Executes ListResources operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) OnListChanged ¶
func (m *MockManagerInterface) OnListChanged(arg0 func())
OnListChanged mocks base method. arg0 is the arg0.
Parameters:
- arg0 (func(): The arg0 parameter.
Returns:
- ): The resulting ).
Errors:
- None
Side Effects:
- None
Summary: Executes OnListChanged operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterface) RemoveResource ¶
func (m *MockManagerInterface) RemoveResource(uri string)
RemoveResource mocks base method. uri is the uri.
Parameters:
- uri (string): The uri parameter.
Returns:
- None
Errors:
- None
Side Effects:
- None
Summary: Executes RemoveResource operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
type MockManagerInterfaceMockRecorder ¶
type MockManagerInterfaceMockRecorder struct {
// contains filtered or unexported fields
}
MockManagerInterfaceMockRecorder is the mock recorder for MockManagerInterface.
Summary: Represents a MockManagerInterfaceMockRecorder.
func (*MockManagerInterfaceMockRecorder) AddResource ¶
func (mr *MockManagerInterfaceMockRecorder) AddResource(resource any) *gomock.Call
AddResource indicates an expected call of AddResource. resource is the resource. Returns the result.
Parameters:
- resource (any): The resource parameter.
Returns:
- *gomock.Call: The resulting *gomock.Call.
Errors:
- None
Side Effects:
- None
Summary: Executes AddResource operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterfaceMockRecorder) Clear ¶
func (mr *MockManagerInterfaceMockRecorder) Clear() *gomock.Call
Clear indicates an expected call of Clear. Returns the result.
Parameters:
- None
Returns:
- *gomock.Call: The resulting *gomock.Call.
Errors:
- None
Side Effects:
- None
Summary: Executes Clear operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterfaceMockRecorder) ClearResourcesForService ¶
func (mr *MockManagerInterfaceMockRecorder) ClearResourcesForService(serviceID any) *gomock.Call
ClearResourcesForService indicates an expected call of ClearResourcesForService. serviceID is the serviceID. Returns the result.
Parameters:
- serviceID (any): The serviceID parameter.
Returns:
- *gomock.Call: The resulting *gomock.Call.
Errors:
- None
Side Effects:
- None
Summary: Executes ClearResourcesForService operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterfaceMockRecorder) GetResource ¶
func (mr *MockManagerInterfaceMockRecorder) GetResource(uri any) *gomock.Call
GetResource indicates an expected call of GetResource. uri is the uri. Returns the result.
Parameters:
- uri (any): The uri parameter.
Returns:
- *gomock.Call: The resulting *gomock.Call.
Errors:
- None
Side Effects:
- None
Summary: Retrieves GetResource operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterfaceMockRecorder) ListResources ¶
func (mr *MockManagerInterfaceMockRecorder) ListResources() *gomock.Call
ListResources indicates an expected call of ListResources. Returns the result.
Parameters:
- None
Returns:
- *gomock.Call: The resulting *gomock.Call.
Errors:
- None
Side Effects:
- None
Summary: Executes ListResources operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterfaceMockRecorder) OnListChanged ¶
func (mr *MockManagerInterfaceMockRecorder) OnListChanged(arg0 any) *gomock.Call
OnListChanged indicates an expected call of OnListChanged. arg0 is the arg0. Returns the result.
Parameters:
- arg0 (any): The arg0 parameter.
Returns:
- *gomock.Call: The resulting *gomock.Call.
Errors:
- None
Side Effects:
- None
Summary: Executes OnListChanged operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
func (*MockManagerInterfaceMockRecorder) RemoveResource ¶
func (mr *MockManagerInterfaceMockRecorder) RemoveResource(uri any) *gomock.Call
RemoveResource indicates an expected call of RemoveResource. uri is the uri. Returns the result.
Parameters:
- uri (any): The uri parameter.
Returns:
- *gomock.Call: The resulting *gomock.Call.
Errors:
- None
Side Effects:
- None
Summary: Executes RemoveResource operation.
Parameters:
- TODO: Document parameters.
Returns:
- TODO: Document returns.
Errors:
- TODO: Document errors.
Side Effects:
- None.
type Resource ¶
type Resource interface {
// Resource returns the MCP representation of the resource, which includes its metadata.
//
// Returns:
// - *mcp.Resource: The MCP resource definition.
Resource() *mcp.Resource
// Service returns the ID of the service that provides this resource.
//
// Returns:
// - string: The service ID.
Service() string
// Read retrieves the content of the resource.
//
// Parameters:
// - ctx: context.Context. The context for the request.
//
// Returns:
// - *mcp.ReadResourceResult: The content of the resource.
// - error: An error if reading fails.
Read(ctx context.Context) (*mcp.ReadResourceResult, error)
// Subscribe establishes a subscription to the resource, allowing for receiving updates.
//
// Parameters:
// - ctx: context.Context. The context for the subscription.
//
// Returns:
// - error: An error if subscription fails.
Subscribe(ctx context.Context) error
}
Resource defines the interface for a resource that can be managed by the Manager.
Summary: Interface for a managed resource.
A resource represents a data source (e.g., a file, a database record) that can be read by an MCP client.
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).
Summary: Represents a StaticResource.
func NewStaticResource ¶
func NewStaticResource(def *configv1.ResourceDefinition, serviceID string) *StaticResource
NewStaticResource creates a new instance of StaticResource.
Summary: Initializes a static resource.
Parameters:
- def: *configv1.ResourceDefinition. The resource definition.
- serviceID: string. The ID of the service owning the resource.
Returns:
- *StaticResource: The initialized static resource.
func (*StaticResource) Read ¶
func (r *StaticResource) Read(ctx context.Context) (*mcp.ReadResourceResult, error)
Read retrieves the content of the resource by fetching the URI.
Summary: Fetches the resource content.
Parameters:
- ctx: context.Context. The context for the request.
Returns:
- *mcp.ReadResourceResult: The resource content.
- error: An error if fetching fails.
Side Effects:
- Performs an HTTP GET request to the resource URI (if not inline content).
func (*StaticResource) Resource ¶
func (r *StaticResource) Resource() *mcp.Resource
Resource returns the MCP representation of the resource.
Summary: Retrieves the MCP resource metadata.
Returns:
- *mcp.Resource: The MCP resource definition.
func (*StaticResource) Service ¶
func (r *StaticResource) Service() string
Service returns the ID of the service that provides this resource.
Summary: Retrieves the service ID.
Returns:
- string: The service ID.
func (*StaticResource) Subscribe ¶
func (r *StaticResource) Subscribe(_ context.Context) error
Subscribe is not yet implemented for static resources.
Summary: Subscribes to resource updates (Not Implemented).
Parameters:
- _: context.Context. Unused.
Returns:
- error: Always returns an error indicating not implemented.