Interface Resources

All Known Subinterfaces:
ResourceRegistry
All Known Implementing Classes:
DefaultResourceRegistry

public interface Resources
Façade interface for MCP resources
  • Method Details

    • register

      Resources register(ResourceDescriptor descriptor, ResourceFn fn)
      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 register
      fn - the resource function
      Returns:
      this registry
      Throws:
      IllegalArgumentException - if the URI is already registered under a different name
    • register

      default Resources register(Consumer<ResourceDescriptor.Builder> configurer, ResourceFn fn)
      Registers a resource configured through a descriptor builder.
      Parameters:
      configurer - configures the resource descriptor
      fn - the resource function
      Returns:
      this resource registry
    • registerAsync

      Resources registerAsync(ResourceDescriptor descriptor, AsyncResourceFn fn)
      Registers a resource descriptor with an asynchronous function.
      Parameters:
      descriptor - the resource descriptor
      fn - 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 builder
      fn - the asynchronous function for the resource
      Returns:
      this resource registry
    • unregister

      boolean unregister(String name)
      Removes the registered resource with the specified name.
      Parameters:
      name - the name of the resource to remove
      Returns:
      true if a resource was removed, false otherwise
    • unregisterByUri

      @ExperimentalApi boolean unregisterByUri(String uri)
      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 Optional if 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 Optional if no resource is registered with that uri
    • descriptors

      List<ResourceDescriptor> descriptors()
      Lists the descriptors for all registered resources.
      Returns:
      the registered resource descriptors
    • notifyResourceUpdated

      void notifyResourceUpdated(String uri)
      Notifies every session subscribed to the given resource URI that the resource has changed, emitting a notifications/resources/updated notification to each.

      Has no effect when no session is subscribed to the URI.

      Parameters:
      uri - the URI of the resource that changed
    • registerTemplate

      Resources registerTemplate(ResourceTemplateDescriptor descriptor, ResourceFn fn)
      Registers a resource template descriptor with its synchronous function.
      Parameters:
      descriptor - the resource template descriptor to register
      fn - 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 descriptor
      fn - the resource function
      Returns:
      this resource registry
    • registerTemplateAsync

      Resources registerTemplateAsync(ResourceTemplateDescriptor descriptor, AsyncResourceFn fn)
      Registers a resource template with an asynchronous function.
      Parameters:
      descriptor - the resource template descriptor to register
      fn - 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 builder
      fn - the asynchronous function for the registered resource template
      Returns:
      this resource registry
    • unregisterTemplate

      boolean unregisterTemplate(String name)
      Removes the registered resource template with the specified name.
      Parameters:
      name - the name of the resource template to remove
      Returns:
      true if the resource template was removed, false otherwise
    • 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