Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext Store listFolders

From Leeroopedia
Knowledge Sources
Domains Knowledge_Management, API
Last Updated 2026-10-24 12:00 GMT

Overview

Concrete tool for listing knowledge base folders provided by the OpenContext native store adapter.

Description

The listFolders function is part of the native store adapter (`store-native.js`) that bridges Node.js to the Rust core library via NAPI bindings. It enumerates folders in the OpenContext knowledge base, supporting both top-level and recursive listing.

The Rust core (`crates/opencontext-core/src/lib.rs`) queries the SQLite database for folder records. Each folder has an ID, parent ID, relative path, and description. The `all` flag controls whether only top-level folders or all nested folders are returned.

Usage

  • Context Discovery: Call with `all: true` to enumerate all knowledge spaces before searching or generating manifests.
  • Folder navigation: Call with `all: false` (default) for top-level folder listing in UI sidebar trees.
  • Agent initialization: Used by `oc folder ls --all` CLI command and `oc_list_folders` MCP tool to help agents discover available spaces.

Code Reference

Source Location

  • Repository: OpenContext
  • File (JS adapter): src/core/store-native.js
  • File (Rust core): crates/opencontext-core/src/lib.rs
  • File (CLI): bin/oc.js
  • File (MCP): src/mcp/server.js

Signature

/**
 * List folders in the knowledge base
 * @param {{ all?: boolean }} options - Listing options
 * @param {boolean} options.all - If true, list all nested folders; if false, only top-level
 * @returns {Array<Folder>} Array of folder objects
 */
function listFolders(options = {}) {
  return handleResult(native.get().listFolders({ all: options.all ?? false }));
}

Import

const { listFolders } = require('./core/store-native');
// or via facade:
const store = require('./core/store');
store.listFolders({ all: true });

I/O Contract

Inputs

Name Type Required Description
options.all boolean No If true, list all nested folders; if false (default), only top-level

Outputs

Name Type Description
returns Array<Folder> Array of folder objects
Folder.id number Folder database ID
Folder.parent_id null Parent folder ID (null for top-level)
Folder.rel_path string Relative path from contexts root
Folder.description string Folder description text

Usage Examples

List All Folders (CLI)

# List all folders including nested ones
oc folder ls --all

List All Folders (JavaScript)

const store = require('./core/store-native');

// List all nested folders
const folders = store.listFolders({ all: true });
folders.forEach(folder => {
  console.log(`${folder.rel_path}: ${folder.description}`);
});

MCP Tool Usage

{
  "tool": "oc_list_folders",
  "arguments": {
    "scope": "all"
  }
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment