@moxn/kb-migrate CLI reads markdown and text files, splits them into sections, uploads images, and creates documents via the API.
Prerequisites
- Node.js 18+
- A Moxn API key with read and write permissions (create one at Settings > API Keys in the web app)
- A directory of
.mdor.txtfiles to import
Make sure your API key has read/write access, not read-only. The migration tool needs write access to create documents and upload images.
Quick Start
Point the tool at the local directory you want to import. In these examples,./docs is the folder on your filesystem containing the markdown files:
./docs with the path to your own documentation directory.
You can also set
MOXN_API_KEY as an environment variable instead of passing --api-key every time.How It Works
The migration tool processes your files in four steps:1. Discover
The tool scans your directory recursively for matching files. By default it picks up.md and .txt files. It ignores node_modules/ and .git/ directories.
2. Parse
Each file is parsed into a document with sections:- H2+ headers (
##,###, etc.) become section boundaries - Content between headers becomes the section body
- Files with no H2 headers get a single “Content” section
- Local images (e.g.,
) are uploaded as assets - External images (e.g.,
) are kept as URL references - Code blocks, formatting, and lists are preserved
3. Upload
Each document is created via the API:- 201 — document created
- 409 — document already exists at that path, handled by the
--on-conflictoption - Other errors — marked as failed, remaining files continue processing
4. Report
A summary is printed with counts and timing:Document Path Mapping
The tool constructs KB paths from the file’s relative path:| Source File | --base-path | KB Document Path |
|---|---|---|
guide.md | / (default) | /guide |
guide.md | /imported | /imported/guide |
deep/nested.md | /docs | /docs/deep/nested |
a/b/c/file.txt | / | /a/b/c/file |
api-guide.md becomes “Api Guide”).
Section Parsing
Sections are created from H2+ headers in your markdown:CLI Options
| Option | Default | Description |
|---|---|---|
--api-key <key> | $MOXN_API_KEY | API authentication key (required) |
--api-url <url> | https://moxn.dev | API base URL (for local dev, e.g. http://localhost:3000) |
--base-path <path> | / | Path prefix for all imported documents |
--extensions <exts> | .md,.txt | Comma-separated file extensions to include |
--on-conflict <action> | skip | What to do when a path already exists: skip or update |
--default-permission <perm> | Server default | Default permission level: edit, read, or none |
--ai-access <perm> | Server default | AI/MCP access level: edit, read, or none |
--dry-run | false | Preview changes without calling the API |
--json | false | Output results as JSON |
Handling Conflicts
When you import files to a path that already has a document:--on-conflict=skip (default) — Existing documents are left untouched:
--on-conflict=update — Existing documents are updated with the new content:
Setting Permissions
Control who can access your imported documents:| Permission | edit | read | none |
|---|---|---|---|
--default-permission | Team members can edit | Team members can view only | Hidden from team |
--ai-access | AI assistants can read and write | AI assistants can read only | Hidden from AI |
Custom File Extensions
By default, only.md and .txt files are imported. To import other file types:
JSON Output
Use--json to get structured output for scripting or CI integration:
MigrationLog object:
Examples
Import project documentation
Preview before importing
Re-sync after updating local files
Import with restricted AI access
Troubleshooting
'npx' is not recognized
'npx' is not recognized
You need Node.js installed. Download it from nodejs.org (choose the LTS version). After installing, restart your terminal.
Error: API key required
Error: API key required
Either pass
--api-key=YOUR_KEY or set the MOXN_API_KEY environment variable:Some files failed but others succeeded
Some files failed but others succeeded
The tool continues processing remaining files when one fails. Check the summary output for failed files and their error messages. Common causes:
- Network errors (transient — retry the import with
--on-conflict=skip) - Invalid file content
Images aren't showing up in my documents
Images aren't showing up in my documents
Make sure image paths in your markdown are correct relative to the markdown file’s location. The tool resolves
 relative to the .md file.External image URLs (e.g., https://...) are kept as-is and require the URL to be publicly accessible.Path collision warning
Path collision warning
This happens when two source files map to the same KB path (e.g.,
doc.md and doc.txt in the same directory). The tool keeps the first match and warns about duplicates. Rename one of the source files to avoid the collision.