Skip to main content

ResourceHandler

Struct ResourceHandler 

Source
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

Source

pub fn new() -> Self

Creates a new resource handler.

Source

pub fn with_prompt_service(self, prompt_service: PromptService) -> Self

Adds a prompt service to the resource handler.

Source

pub fn with_recall_service(self, recall_service: RecallService) -> Self

Adds a recall service to the resource handler.

Source

pub fn with_topic_index(self, topic_index: TopicIndexService) -> Self

Adds a topic index to the resource handler.

Source

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.

Source

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.

Source

fn build_resource( uri: &str, name: &str, description: &str, mime_type: &str, ) -> ResourceDefinition

Source

fn help_resource_definitions(&self) -> Vec<ResourceDefinition>

Source

fn memory_resource_definitions(&self) -> Vec<ResourceDefinition>

Source

fn domain_resource_definitions() -> Vec<ResourceDefinition>

Source

fn search_topic_resource_definitions() -> Vec<ResourceDefinition>

Source

fn summary_resource_definitions() -> Vec<ResourceDefinition>

Source

fn prompt_resource_definitions() -> Vec<ResourceDefinition>

Source

pub fn get_resource(&mut self, uri: &str) -> Result<ResourceContent>

Gets a resource by URI.

Supported URI patterns:

  • subcog://help - Help index
  • subcog://help/{topic} - Help topic
  • subcog://_ - All memories across all domains
  • subcog://_/{namespace} - All memories in a namespace
  • subcog://memory/{id} - Get specific memory by ID
  • subcog://project/_ - Project-scoped memories (alias for subcog://_)
  • subcog://search/{query} - Search memories with a query
  • subcog://topics - List all indexed topics
  • subcog://topics/{topic} - Get memories for a specific topic
  • subcog://summaries - List all consolidated summaries
  • subcog://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.

Source

fn get_help_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>

Gets a help resource.

Source

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 domains
  • subcog://_/{namespace} - All memories in a namespace
  • subcog://project/_ - Alias for subcog://_ (project-scoped, future domain filter)

For advanced filtering, use subcog_recall with the filter argument.

Source

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.

Source

fn get_namespace_memories_resource( &self, uri: &str, namespace: &str, ) -> Result<ResourceContent>

Gets memories scoped to a namespace.

Source

fn get_scoped_memory_resource( &self, uri: &str, namespace: &str, memory_id: &str, ) -> Result<ResourceContent>

Gets a specific memory by ID with namespace validation.

Source

fn format_memory_response( &self, uri: &str, memory: &Memory, ) -> Result<ResourceContent>

Formats a memory as a JSON response.

Source

fn list_memories( &self, uri: &str, filter: &SearchFilter, ) -> Result<ResourceContent>

Source

fn get_search_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>

Searches memories and returns results.

URI: subcog://search/{query}

Source

fn get_topics_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>

Gets topics resource (list or specific topic).

URIs:

  • subcog://topics - List all topics
  • subcog://topics/{topic} - Get memories for a topic
Source

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.

Source

fn get_summaries_resource( &self, uri: &str, parts: &[&str], ) -> Result<ResourceContent>

Gets summaries resource (list or specific summary).

URIs:

  • subcog://summaries - List all summary nodes
  • subcog://summaries/{id} - Get a specific summary with source memories
Source

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.

Source

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.

Source

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.

Source

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 domain
  • subcog://{domain}/_prompts/{name} - Get specific prompt by name
  • subcog://{domain}/_ - List memories in domain (alias)
Source

fn get_prompts_resource( &mut self, uri: &str, domain: DomainScope, ) -> Result<ResourceContent>

Gets prompts for a specific domain scope.

Source

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.

Source

fn get_help_index(&self) -> String

Gets the help index listing all categories.

Source

pub fn list_categories(&self) -> Vec<&HelpCategory>

Gets a list of help categories.

Trait Implementations§

Source§

impl Default for ResourceHandler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more