Class InMemoryAsyncResourceRepository
java.lang.Object
org.springframework.ai.mcp.modern.InMemoryAsyncResourceRepository
- All Implemented Interfaces:
io.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository
public final class InMemoryAsyncResourceRepository
extends Object
implements io.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository
The asynchronous twin of
InMemorySyncResourceRepository: a
McpAsyncResourceRepository that keeps AsyncResourceRegistrations and
AsyncResourceTemplateRegistrations in sorted, concurrent maps. A
resources/read URI is served by the resource registered under it, or else by
the first template matching it in URI-template order. Resources and templates can be
added and removed at runtime; each change is broadcast as
notifications/resources/list_changed when a change broadcaster is configured,
and resourceUpdated(String) notifies subscribers of a changed resource.
Listings are paged with an opaque key cursor when a page size is set. Completion is
served from the completionHandler of each template, and is advertised unless
the repository is built with completionSupported(false).- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(AsyncResourceRegistration registration) Adds a resource and notifies listening clients.voidadd(AsyncResourceTemplateRegistration registration) Adds a resource template and notifies listening clients.builder()reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.feature.McpAsyncResource>reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.feature.McpAsyncResourceTemplate>findTemplate(io.modelcontextprotocol.modern.server.McpRequestContext ctx, String uriTemplate) The template registered under exactly this URI template, which carries the handler that completes its variables.reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.feature.ResourcesPage>reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.feature.ResourceTemplatesPage>listTemplates(io.modelcontextprotocol.modern.server.McpRequestContext ctx, @Nullable String cursor) booleanRemoves the resource or resource template with this URI and notifies listening clients.voidresourceUpdated(String uri) Notifies subscribers that the content ofurichanged.booleanboolean
-
Method Details
-
builder
-
add
Adds a resource and notifies listening clients.- Throws:
IllegalArgumentException- if a resource with the same URI exists
-
add
Adds a resource template and notifies listening clients.- Throws:
IllegalArgumentException- if a template with the same URI template exists, or the URI template is invalid
-
remove
Removes the resource or resource template with this URI and notifies listening clients.- Returns:
- whether anything was removed
-
resourceUpdated
Notifies subscribers that the content ofurichanged. Reaches clients only when the repository was built withsubscribeSupported. -
list
public reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.feature.ResourcesPage> list(io.modelcontextprotocol.modern.server.McpRequestContext ctx, @Nullable String cursor) - Specified by:
listin interfaceio.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository
-
listTemplates
public reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.feature.ResourceTemplatesPage> listTemplates(io.modelcontextprotocol.modern.server.McpRequestContext ctx, @Nullable String cursor) - Specified by:
listTemplatesin interfaceio.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository
-
find
public reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.feature.McpAsyncResource> find(io.modelcontextprotocol.modern.server.McpRequestContext ctx, String uri) - Specified by:
findin interfaceio.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository
-
findTemplate
public reactor.core.publisher.Mono<io.modelcontextprotocol.modern.server.feature.McpAsyncResourceTemplate> findTemplate(io.modelcontextprotocol.modern.server.McpRequestContext ctx, String uriTemplate) The template registered under exactly this URI template, which carries the handler that completes its variables.- Specified by:
findTemplatein interfaceio.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository
-
supportsSubscribe
public boolean supportsSubscribe()- Specified by:
supportsSubscribein interfaceio.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository
-
supportsCompletion
public boolean supportsCompletion()- Specified by:
supportsCompletionin interfaceio.modelcontextprotocol.modern.server.feature.McpAsyncResourceRepository
-