Class InMemorySyncResourceRepository
java.lang.Object
org.springframework.ai.mcp.modern.InMemorySyncResourceRepository
- All Implemented Interfaces:
io.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository
public final class InMemorySyncResourceRepository
extends Object
implements io.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository
A
McpSyncResourceRepository that keeps SyncResourceRegistrations and
SyncResourceTemplateRegistrations 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
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(SyncResourceRegistration registration) Adds a resource and notifies listening clients.voidadd(SyncResourceTemplateRegistration registration) Adds a resource template and notifies listening clients.builder()@Nullable io.modelcontextprotocol.modern.server.feature.McpSyncResource@Nullable io.modelcontextprotocol.modern.server.feature.McpSyncResourceTemplatefindTemplate(io.modelcontextprotocol.modern.server.McpRequestContext ctx, String uriTemplate) The template registered under exactly this URI template, which carries the handler that completes its variables.io.modelcontextprotocol.modern.server.feature.ResourcesPageio.modelcontextprotocol.modern.server.feature.ResourceTemplatesPagelistTemplates(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 io.modelcontextprotocol.modern.server.feature.ResourcesPage list(io.modelcontextprotocol.modern.server.McpRequestContext ctx, @Nullable String cursor) - Specified by:
listin interfaceio.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository
-
listTemplates
public io.modelcontextprotocol.modern.server.feature.ResourceTemplatesPage listTemplates(io.modelcontextprotocol.modern.server.McpRequestContext ctx, @Nullable String cursor) - Specified by:
listTemplatesin interfaceio.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository
-
find
public @Nullable io.modelcontextprotocol.modern.server.feature.McpSyncResource find(io.modelcontextprotocol.modern.server.McpRequestContext ctx, String uri) - Specified by:
findin interfaceio.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository
-
findTemplate
public @Nullable io.modelcontextprotocol.modern.server.feature.McpSyncResourceTemplate 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.McpSyncResourceRepository
-
supportsSubscribe
public boolean supportsSubscribe()- Specified by:
supportsSubscribein interfaceio.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository
-
supportsCompletion
public boolean supportsCompletion()- Specified by:
supportsCompletionin interfaceio.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository
-