Skip to main content
Import existing documentation from your filesystem into Moxn. The @moxn/kb-migrate CLI reads markdown and text files, splits them into sections, uploads images, and creates documents via the API.
If you have @moxn/context-cli installed, you can run context import-local instead of npx @moxn/kb-migrate local.

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 .md or .txt files 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:
Preview what would happen without making changes:
Import under a specific path prefix:
Replace ./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., ![alt](./images/photo.png)) are uploaded as assets
  • External images (e.g., ![alt](https://example.com/img.png)) 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-conflict option
  • 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: File extensions are stripped. The document name is derived from the filename in title case (e.g., api-guide.md becomes “Api Guide”).
Filenames with spaces are automatically sanitized — spaces are replaced with hyphens. For example, my file.md becomes path /my-file. A warning is shown when this happens.

Section Parsing

Sections are created from H2+ headers in your markdown:
This produces a document with 3 sections. Content before the first H2 header is included in the first section. Files with no H2 headers produce a single section named “Content” containing the entire file.

CLI Options

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:
Updates create new commits in the document’s history — the previous version is preserved.

Setting Permissions

Control who can access your imported documents:
See Permissions for details on how the permission model works.

Custom File Extensions

By default, only .md and .txt files are imported. To import other file types:
If two files in the same directory differ only by extension (e.g., doc.mdx and doc.markdown), they map to the same KB path. The tool will warn you and keep only the first match.

JSON Output

Use --json to get structured output for scripting or CI integration:
Returns a MigrationLog object:

Examples

Import project documentation

Preview before importing

Re-sync after updating local files

Import with restricted AI access

Troubleshooting

You need Node.js installed. Download it from nodejs.org (choose the LTS version). After installing, restart your terminal.
Either pass --api-key=YOUR_KEY or set the MOXN_API_KEY environment variable:
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
Make sure image paths in your markdown are correct relative to the markdown file’s location. The tool resolves ![alt](./images/photo.png) relative to the .md file.External image URLs (e.g., https://...) are kept as-is and require the URL to be publicly accessible.
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.

Next Steps

Concepts

Learn about documents, branches, and permissions

Connect AI Assistants

Set up MCP access so AI can use your imported docs