Implementation:0xranx OpenContext Store createFolder
| Knowledge Sources | |
|---|---|
| Domains | Knowledge_Management, API |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for creating folders in the OpenContext knowledge base provided by the native store adapter.
Description
The createFolder function creates a new folder in the knowledge base. It registers the folder in the SQLite database and creates the directory on disk. The folder path is relative to the contexts root (e.g., `projects/architecture` creates a nested folder).
The Rust core validates the path, checks for duplicates, inserts a record into the `folders` table, and creates the filesystem directory. The returned object includes both the relative and absolute paths.
Usage
- Document Lifecycle: Create new knowledge spaces before adding documents.
- Agent workflows: The `oc folder create` CLI command and `oc_folder_create` MCP tool use this function.
- Idempotent creation: Safe to call even if the folder partially exists (database handles uniqueness).
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
/**
* Create a folder
* @param {{ path: string, description?: string }} options
* @returns {{ rel_path: string, abs_path: string, description: string }}
*/
function createFolder(options) {
return handleResult(native.get().createFolder({
path: options.path,
description: options.description,
}));
}
Import
const { createFolder } = require('./core/store-native');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| options.path | string | Yes | Folder path relative to contexts/ (e.g., "projects/architecture") |
| options.description | string | No | Optional folder description |
Outputs
| Name | Type | Description |
|---|---|---|
| returns.rel_path | string | Relative path from contexts root |
| returns.abs_path | string | Absolute filesystem path |
| returns.description | string | Folder description (may be empty string) |
Usage Examples
Create a Folder (CLI)
oc folder create projects/architecture -d "Architecture decisions and designs"
Create a Folder (JavaScript)
const { createFolder } = require('./core/store-native');
const result = createFolder({
path: 'projects/architecture',
description: 'Architecture decisions and designs'
});
console.log(`Created: ${result.abs_path}`);
MCP Tool Usage
{
"tool": "oc_folder_create",
"arguments": {
"path": "projects/architecture",
"description": "Architecture decisions and designs"
}
}