pub struct ResourceHandler {
help_content: HashMap<String, HelpCategory>,
recall_service: Option<RecallService>,
topic_index: Option<TopicIndexService>,
prompt_service: Option<PromptService>,
}Expand description
Handler for MCP resources (URN scheme).
Fields§
§help_content: HashMap<String, HelpCategory>Help content by category.
recall_service: Option<RecallService>Optional recall service for memory browsing.
topic_index: Option<TopicIndexService>Topic index for topic-based resource access.
prompt_service: Option<PromptService>Optional prompt service for prompt resources.
Implementations§
Source§impl ResourceHandler
impl ResourceHandler
Sourcepub fn with_prompt_service(self, prompt_service: PromptService) -> Self
pub fn with_prompt_service(self, prompt_service: PromptService) -> Self
Adds a prompt service to the resource handler.
Sourcepub fn with_recall_service(self, recall_service: RecallService) -> Self
pub fn with_recall_service(self, recall_service: RecallService) -> Self
Adds a recall service to the resource handler.
Sourcepub fn with_topic_index(self, topic_index: TopicIndexService) -> Self
pub fn with_topic_index(self, topic_index: TopicIndexService) -> Self
Adds a topic index to the resource handler.
Sourcepub fn refresh_topic_index(&mut self) -> Result<()>
pub fn refresh_topic_index(&mut self) -> Result<()>
Builds and refreshes the topic index from the recall service.
§Errors
Returns an error if the topic index cannot be built.
Sourcepub fn list_resources(&self) -> Vec<ResourceDefinition>
pub fn list_resources(&self) -> Vec<ResourceDefinition>
Lists all available resources.
Returns resources organized by type:
- Help topics
- Memory browsing patterns
For advanced filtering, use subcog_recall with the filter argument.
fn build_resource( uri: &str, name: &str, description: &str, mime_type: &str, ) -> ResourceDefinition
fn help_resource_definitions(&self) -> Vec<ResourceDefinition>
fn memory_resource_definitions(&self) -> Vec<ResourceDefinition>
fn domain_resource_definitions() -> Vec<ResourceDefinition>
fn search_topic_resource_definitions() -> Vec<ResourceDefinition>
fn summary_resource_definitions() -> Vec<ResourceDefinition>
fn prompt_resource_definitions() -> Vec<ResourceDefinition>
Sourcepub fn get_resource(&mut self, uri: &str) -> Result<ResourceContent>
pub fn get_resource(&mut self, uri: &str) -> Result<ResourceContent>
Gets a resource by URI.
Supported URI patterns:
subcog://help- Help indexsubcog://help/{topic}- Help topicsubcog://_- All memories across all domainssubcog://_/{namespace}- All memories in a namespacesubcog://memory/{id}- Get specific memory by IDsubcog://project/_- Project-scoped memories (alias forsubcog://_)subcog://search/{query}- Search memories with a querysubcog://topics- List all indexed topicssubcog://topics/{topic}- Get memories for a specific topicsubcog://summaries- List all consolidated summariessubcog://summaries/{id}- Get a specific summary with source memories
For advanced filtering, use subcog_recall with the filter argument.
§Errors
Returns an error if the resource is not found.
Sourcefn get_help_resource(
&self,
uri: &str,
parts: &[&str],
) -> Result<ResourceContent>
fn get_help_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>
Gets a help resource.
Sourcefn get_all_memories_resource(
&self,
uri: &str,
parts: &[&str],
) -> Result<ResourceContent>
fn get_all_memories_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>
Gets all memories resource with optional namespace filter.
URI patterns:
subcog://_- All memories across all domainssubcog://_/{namespace}- All memories in a namespacesubcog://project/_- Alias forsubcog://_(project-scoped, future domain filter)
For advanced filtering, use subcog_recall with the filter argument.
Sourcefn get_memory_resource(
&self,
uri: &str,
parts: &[&str],
) -> Result<ResourceContent>
fn get_memory_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>
Gets a specific memory by ID with full content (cross-domain lookup).
This is the targeted fetch endpoint - returns complete memory data.
Use subcog://memory/{id} for cross-domain lookups when ID is known.
Sourcefn get_namespace_memories_resource(
&self,
uri: &str,
namespace: &str,
) -> Result<ResourceContent>
fn get_namespace_memories_resource( &self, uri: &str, namespace: &str, ) -> Result<ResourceContent>
Gets memories scoped to a namespace.
Sourcefn get_scoped_memory_resource(
&self,
uri: &str,
namespace: &str,
memory_id: &str,
) -> Result<ResourceContent>
fn get_scoped_memory_resource( &self, uri: &str, namespace: &str, memory_id: &str, ) -> Result<ResourceContent>
Gets a specific memory by ID with namespace validation.
Sourcefn format_memory_response(
&self,
uri: &str,
memory: &Memory,
) -> Result<ResourceContent>
fn format_memory_response( &self, uri: &str, memory: &Memory, ) -> Result<ResourceContent>
Formats a memory as a JSON response.
fn list_memories( &self, uri: &str, filter: &SearchFilter, ) -> Result<ResourceContent>
Sourcefn get_search_resource(
&self,
uri: &str,
parts: &[&str],
) -> Result<ResourceContent>
fn get_search_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>
Searches memories and returns results.
URI: subcog://search/{query}
Sourcefn get_topics_resource(
&self,
uri: &str,
parts: &[&str],
) -> Result<ResourceContent>
fn get_topics_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>
Gets topics resource (list or specific topic).
URIs:
subcog://topics- List all topicssubcog://topics/{topic}- Get memories for a topic
Sourcefn get_namespaces_resource(&self, uri: &str) -> Result<ResourceContent>
fn get_namespaces_resource(&self, uri: &str) -> Result<ResourceContent>
Gets namespaces resource listing all available namespaces.
URI: subcog://namespaces
Returns namespace definitions with descriptions and signal words.
Sourcefn get_summaries_resource(
&self,
uri: &str,
parts: &[&str],
) -> Result<ResourceContent>
fn get_summaries_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>
Gets summaries resource (list or specific summary).
URIs:
subcog://summaries- List all summary nodessubcog://summaries/{id}- Get a specific summary with source memories
Sourcefn get_specific_summary_resource(
&self,
uri: &str,
recall: &RecallService,
summary_id: &str,
) -> Result<ResourceContent>
fn get_specific_summary_resource( &self, uri: &str, recall: &RecallService, summary_id: &str, ) -> Result<ResourceContent>
Gets a specific summary node with its source memories.
Returns the summary content and linked source memories.
Sourcefn get_aggregate_prompts_resource(
&mut self,
uri: &str,
) -> Result<ResourceContent>
fn get_aggregate_prompts_resource( &mut self, uri: &str, ) -> Result<ResourceContent>
Gets aggregate prompts resource listing prompts from all domains.
URI: subcog://_prompts
Returns prompts aggregated from project, user, and org domains. Prompts are deduplicated by name, with project scope taking priority.
Sourcefn collect_unique_prompts(
seen: &mut HashSet<String>,
output: &mut Vec<Value>,
prompts: Vec<PromptTemplate>,
domain_name: &str,
)
fn collect_unique_prompts( seen: &mut HashSet<String>, output: &mut Vec<Value>, prompts: Vec<PromptTemplate>, domain_name: &str, )
Collects unique prompts, skipping those already seen.
Sourcefn get_domain_scoped_resource(
&mut self,
uri: &str,
parts: &[&str],
domain: DomainScope,
) -> Result<ResourceContent>
fn get_domain_scoped_resource( &mut self, uri: &str, parts: &[&str], domain: DomainScope, ) -> Result<ResourceContent>
Gets domain-scoped resources (prompts or memories).
URIs:
subcog://{domain}/_prompts- List prompts in domainsubcog://{domain}/_prompts/{name}- Get specific prompt by namesubcog://{domain}/_- List memories in domain (alias)
Sourcefn get_prompts_resource(
&mut self,
uri: &str,
domain: DomainScope,
) -> Result<ResourceContent>
fn get_prompts_resource( &mut self, uri: &str, domain: DomainScope, ) -> Result<ResourceContent>
Gets prompts for a specific domain scope.
Sourcefn get_single_prompt_resource(
&mut self,
uri: &str,
domain: DomainScope,
name: &str,
) -> Result<ResourceContent>
fn get_single_prompt_resource( &mut self, uri: &str, domain: DomainScope, name: &str, ) -> Result<ResourceContent>
Gets a specific prompt by name from a domain scope.
Sourcefn get_help_index(&self) -> String
fn get_help_index(&self) -> String
Gets the help index listing all categories.
Sourcepub fn list_categories(&self) -> Vec<&HelpCategory>
pub fn list_categories(&self) -> Vec<&HelpCategory>
Gets a list of help categories.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ResourceHandler
impl !RefUnwindSafe for ResourceHandler
impl Send for ResourceHandler
impl Sync for ResourceHandler
impl Unpin for ResourceHandler
impl !UnwindSafe for ResourceHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].