Interface Resources
- All Known Subinterfaces:
ResourceRegistry
- All Known Implementing Classes:
DefaultResourceRegistry
public interface Resources
Façade interface for MCP resources
-
Method Summary
Modifier and TypeMethodDescriptionLists the descriptors for all registered resources.Finds a registered resource descriptor by name.Finds a registered resource descriptor by URI.findTemplate(String name) Finds a registered resource template descriptor by name.voidNotifies every session subscribed to the given resource URI that the resource has changed, emitting anotifications/resources/updatednotification to each.register(ResourceDescriptor descriptor, ResourceFn fn) Registers a resource descriptor with its synchronous function.default Resourcesregister(Consumer<ResourceDescriptor.Builder> configurer, ResourceFn fn) Registers a resource configured through a descriptor builder.registerAsync(ResourceDescriptor descriptor, AsyncResourceFn fn) Registers a resource descriptor with an asynchronous function.default ResourcesregisterAsync(Consumer<ResourceDescriptor.Builder> descriptor, AsyncResourceFn fn) Registers an asynchronous resource function using a descriptor configured through a builder.registerTemplate(ResourceTemplateDescriptor descriptor, ResourceFn fn) Registers a resource template descriptor with its synchronous function.default ResourcesregisterTemplate(Consumer<ResourceTemplateDescriptor.Builder> configurer, ResourceFn fn) Registers a resource template configured through its builder.registerTemplateAsync(ResourceTemplateDescriptor descriptor, AsyncResourceFn fn) Registers a resource template with an asynchronous function.default ResourcesregisterTemplateAsync(Consumer<ResourceTemplateDescriptor.Builder> descriptor, AsyncResourceFn fn) Registers a resource template configured through its builder.Lists all registered resource template descriptors.booleanunregister(String name) Removes the registered resource with the specified name.booleanunregisterByUri(String uri) Removes the registered resource with the specified uri.booleanunregisterTemplate(String name) Removes the registered resource template with the specified name.
-
Method Details
-
register
Registers a resource descriptor with its synchronous function.Registering a resource whose name already exists replaces it. A URI is unique across resources: registering a URI already owned by a different name is rejected.
- Parameters:
descriptor- the resource descriptor to registerfn- the resource function- Returns:
- this registry
- Throws:
IllegalArgumentException- if the URI is already registered under a different name
-
register
Registers a resource configured through a descriptor builder.- Parameters:
configurer- configures the resource descriptorfn- the resource function- Returns:
- this resource registry
-
registerAsync
Registers a resource descriptor with an asynchronous function.- Parameters:
descriptor- the resource descriptorfn- the asynchronous resource function- Returns:
- this resource registry for method chaining
-
registerAsync
default Resources registerAsync(Consumer<ResourceDescriptor.Builder> descriptor, AsyncResourceFn fn) Registers an asynchronous resource function using a descriptor configured through a builder.- Parameters:
descriptor- a consumer that configures the resource descriptor builderfn- the asynchronous function for the resource- Returns:
- this resource registry
-
unregister
Removes the registered resource with the specified name.- Parameters:
name- the name of the resource to remove- Returns:
trueif a resource was removed,falseotherwise
-
unregisterByUri
Removes the registered resource with the specified uri.- Parameters:
uri- resource URI- Returns:
- true if resource was unregistered
-
find
Finds a registered resource descriptor by name.- Parameters:
name- the resource name- Returns:
- the matching descriptor, or an empty
Optionalif no resource is registered with that name
-
findByUri
Finds a registered resource descriptor by URI.- Parameters:
uri- the resource URI- Returns:
- the matching descriptor, or an empty
Optionalif no resource is registered with that uri
-
descriptors
List<ResourceDescriptor> descriptors()Lists the descriptors for all registered resources.- Returns:
- the registered resource descriptors
-
notifyResourceUpdated
Notifies every session subscribed to the given resource URI that the resource has changed, emitting anotifications/resources/updatednotification to each.Has no effect when no session is subscribed to the URI.
- Parameters:
uri- the URI of the resource that changed
-
registerTemplate
Registers a resource template descriptor with its synchronous function.- Parameters:
descriptor- the resource template descriptor to registerfn- the resource function- Returns:
- this registry
-
registerTemplate
default Resources registerTemplate(Consumer<ResourceTemplateDescriptor.Builder> configurer, ResourceFn fn) Registers a resource template configured through its builder.- Parameters:
configurer- configures the resource template descriptorfn- the resource function- Returns:
- this resource registry
-
registerTemplateAsync
Registers a resource template with an asynchronous function.- Parameters:
descriptor- the resource template descriptor to registerfn- the asynchronous function for the resource template- Returns:
- this resource registry
-
registerTemplateAsync
default Resources registerTemplateAsync(Consumer<ResourceTemplateDescriptor.Builder> descriptor, AsyncResourceFn fn) Registers a resource template configured through its builder.- Parameters:
descriptor- a consumer that configures the resource template builderfn- the asynchronous function for the registered resource template- Returns:
- this resource registry
-
unregisterTemplate
Removes the registered resource template with the specified name.- Parameters:
name- the name of the resource template to remove- Returns:
trueif the resource template was removed,falseotherwise
-
findTemplate
Finds a registered resource template descriptor by name.- Parameters:
name- the name of the resource template- Returns:
- the matching descriptor, if registered
-
templateDescriptors
List<ResourceTemplateDescriptor> templateDescriptors()Lists all registered resource template descriptors.- Returns:
- the registered resource template descriptors
-