scorpiox-bot-plugin-memory
←README.mdmarkdown
239 lines · 12 KBHEAD
BlameDownload

SCORPIOX BOT — memory

A persistent knowledge graph your agents can write to and read back, living on

your own node.

This is the standard MCP memory server, rebuilt as one static C99 binary. Entities

carry observations, typed relations link them, and the same nine tools an agent

sees over stdio back a browser UI for searching, inspecting and editing the graph.

The whole graph is a single JSONL file in this connector's own data directory.

No account, no database, no CDN, no network request of any kind — the binary

opens no socket and runs no other program.

make            # native build            -> ./plugin_memory
make musl       # static musl x86_64      -> ./plugin_memory.musl
make arm64      # static aarch64          -> ./plugin_memory.arm64
make win64      # MinGW-w64 static PE     -> ./plugin_memory.exe
make macos      # Apple clang (on macOS)  -> ./plugin_memory
make ui         # regenerate src/ui_html.h from src/ui.html
make test       # offline suite (180+ assertions)
make e2e        # Playwright viewport suite (1440 / 1024 / 390, dark + light)

Install

Drop the binary where the node looks for plugins, then open

Settings → Plugins, or use the market installer:

# node plugin directory (created by scorpiox-bot on startup)
cp plugin_memory ~/.scorpiox/plugins/plugin_memory
chmod +x ~/.scorpiox/plugins/plugin_memory

# or from the market
curl -s -H "X-Bot-Password: $BOT_PASSWORD" \
  "http://127.0.0.1:8150/plugin_manage?action=install&slug=memory&mode=prebuilt"

Windows: %LOCALAPPDATA%\scorpiox\plugins\plugin_memory.exe.

BotCloud container: /workspace/.scorpiox/plugins/plugin_memory.

Five modes, one binary

Mode Trigger Response
Discovery --meta or SX_PLUGIN_META=1 {"name":"memory","desc":"Knowledge graph","kind":"mcp","mcp":true,"daemon":false,"menus":false,"verified":"live","category":"devtools","version":"1.0.0"} (unauthenticated)
MCP tool provider --mcp newline-delimited JSON-RPC 2.0 over stdio — initialize, tools/list, tools/call, resources/list, resources/read, ping
API ?action=..., ?format=json, or any POST application/json; charset=utf-8
UI plain GET (?embed=1 aware) the graph browser, text/html
Info --version, --help, --schema id + version, usage, the nine tool schemas

Modes 3 and 4 sit behind require_node_auth(): X-Bot-Password,

Authorization: Bearer <pwd>, or ?pwd=. With BOT_PASSWORD unset the check

is a no-op, which is the intended behaviour on a single-user box. --meta and

--mcp stay open — the node spawns the stdio server itself, so a CGI password

must not stop it, or the router could never reach an installed connector.

Why --mcp and not an MCP server entry

plugin_memory is a connector plugin, not a new MCP server. scorpiox-bot-api

ships one lightweight stdio router, sx-connector-mcp, registered as a single

MCP server; it reads mcp_plugins.json and dispatches into every installed

mcp:true plugin. That keeps clang's MAX_SERVERS 16 untouched and adds zero

prompt bloat no matter how many connectors are installed:

# what the router sees
sx-connector-mcp --list                     # memory   kind mcp   9 tools
sx-connector-mcp --tools memory
sx-connector-mcp --call memory create_entities \
  '{"entities":[{"name":"Earl Grey","entityType":"tea","observations":["bergamot"]}]}'
sx-connector-mcp --call memory read_graph '{}'

The nine tools

Names, schemas and error texts match the upstream reference server, so a prompt or

tool-allowlist written for it works unchanged.

Tool Arguments Notes
create_entities {entities:[{name,entityType,observations[]}]} a name already present, or repeating earlier in the same call, is skipped and listed in skipped; its observations are not added — use add_observations
add_observations {observations:[{entityName,contents[]}]} one unknown entity fails the whole call; repeats inside the call and against the graph are dropped
delete_entities {entityNames[]} cascades every relation touching them; reports Deleted N of M entities. Not found: …
create_relations {relations:[{from,to,relationType}]} both ends must exist (Entity with name X not found); the exact triple is never stored twice
delete_relations {relations:[{from,to,relationType}]} exact-triple match; entities are kept
delete_observations {deletions:[{entityName,observations[]}]} exact-text match
read_graph {entityTypes?, observationLimit?} observationLimit: 0 returns counts only (observationCount) — absent returns full text
search_nodes {query, limit?, observationLimit?} case-insensitive substring over name, type and observations, first-N in stored order
open_nodes {names[], observationLimit?} exact names; relations kept when either endpoint is in the set

A tool failure is a tools/call result with isError:true and the human

sentence in content[0].text — never a JSON-RPC error — so an agent reading the

text can correct itself. Mutations also carry structuredContent, and

create_entities adds a second plain-text block naming what was skipped.

HTTP actions

Every action maps onto one of the nine tools, so the page can never drift away

from what an agent sees.

Action Call Returns
graph GET ?action=graph {"ok":true,"entities":[…],"relations":[…]}
search GET ?action=search&q=<text>&limit= same shape, name / type / observation matched
entity GET ?action=entity&name=<name> {"ok":true,"entities":[e],"relations":[…]} — both directions
stats GET ?action=stats {"ok":true,"entities":N,"relations":N,"observations":N,"unreadable_lines":N,"types":[…]}
add_entity POST ?action=add_entity {"name","entityType","observations?":[]} {"ok":true,…}
add_relation POST ?action=add_relation {"from","to","relationType"} {"ok":true,…}
add_obs POST ?action=add_obs {"name","contents":[]} {"ok":true,"results":[…]}
delete_entity POST ?action=delete_entity&name= {"ok":true,"message":"…"}
delete_obs POST ?action=delete_obs {"name","observations":[]} {"ok":true,"message":"…"}
delete_relation POST ?action=delete_relation {"from","to","relationType"} {"ok":true,"message":"…"}
tools GET ?action=tools the nine MCP tool schemas + kind:"mcp"
export GET ?action=export the raw JSONL as text/plain download

?action= and a JSON body are both accepted, so the page can POST an array

(contents, observations) without stuffing it into a query string.

P="pwd=$BOT_PASSWORD"
curl -s "http://127.0.0.1:8150/plugin_memory?action=stats&$P"

curl -s -X POST -H "Content-Type: application/json" \
  "http://127.0.0.1:8150/plugin_memory?action=add_entity&$P" \
  -d '{"name":"Earl Grey","entityType":"tea","observations":["black tea","bergamot"]}'

curl -s -X POST -H "Content-Type: application/json" \
  "http://127.0.0.1:8150/plugin_memory?action=add_relation&$P" \
  -d '{"from":"Earl Grey","to":"Cup","relationType":"is served in"}'

curl -s "http://127.0.0.1:8150/plugin_memory?action=search&q=bergamot&$P"

Storage

Platform Location
Linux / macOS ~/.scorpiox/connectors/plugin_memory/memory.jsonl
BotCloud container /workspace/.scorpiox/connectors/plugin_memory/memory.jsonl (preferred when /workspace exists — the rootfs does not survive stop → start)
Windows %LOCALAPPDATA%\scorpiox\connectors\plugin_memory\memory.jsonl
Override $MEMORY_FILE_PATH (absolute, or relative to the connector directory)

One JSON object per line, exactly the upstream record shape:

{"type":"entity","name":"Earl Grey","entityType":"tea","observations":["black tea","bergamot"]}
{"type":"relation","from":"Earl Grey","to":"Cup","relationType":"is served in"}
  • Entities are written first, then relations, then anything the loader could not

parse — verbatim. A malformed line is never silently deleted by an unrelated

write; it is carried through and written back byte for byte, and counted in

unreadable_lines.

  • Every save goes to <path>.tmp.<pid>, fflush + fsync, chmod to the

existing mode, then rename(). A process killed mid-write leaves the previous

graph intact rather than a half file, and the temp file is unlinked on failure.

  • Parent directories are created 0700 — the graph holds the operator's notes

about their own projects, so it is never world-readable.

Security model

  • Authentication — every HTTP action requires the node password (three forms

above); --meta alone stays open so discovery works.

  • Write scope — exactly one file, inside the connector directory above.

MEMORY_FILE_PATH may not contain ...

  • No process spawn, no network — no popen, system, exec*, socket() or

curl anywhere in src/; tests/run.sh asserts it against the source.

plugin.json declares capabilities: ["fs_read_connector_dir","fs_write_connector_dir"]

and nothing else.

  • Input limits — a request body is capped at 8 MiB and a single --mcp line

at 8 MiB; entity names and relation ends at 1024 characters, a relation type at

1024, an observation at 8000. The graph itself is bounded (MEMORY_MAX_ENTITIES

20000, MEMORY_MAX_RELATIONS 40000, MEMORY_MAX_OBS 2000 per entity,

MEMORY_MAX_BAD 5000 preserved lines) and a file over 24 MiB is refused rather

than loaded. Every limit is an error naming the limit, never a crash.

  • XSS — every byte of graph content is HTML-escaped before any tag is emitted,

so a node named <script>alert(1)</script> renders as inert text.

  • CSP — `default-src 'none'; script-src 'unsafe-inline'; style-src

'unsafe-inline'; connect-src 'self'; form-action 'none'; base-uri 'none'`, so a

future regression still cannot fetch a remote script.

  • Robustness — the whole suite also runs under ASan + UBSan +

_FORTIFY_SOURCE=2, including a garbage-stdin pass and the CGI path.

UI

One page, two panes: the entity list with search and type chips on the left,

the inspector on the right. Under 700 px it collapses to a single pane with a

back button, so the same page is usable at 390 px and inside the Chat floating

window.

  • live search over name, type and observations; type chips filter in one click
  • entity inspector: observations with per-row remove, relations in and out,

a "new relation from here" picker (both ends must already exist, exact

duplicates are skipped)

  • add observation, add relation, delete entity / observation / relation, all

round-tripping into the JSONL immediately

  • stats tally in the header, status line for every action, export as a file
  • dark and light from the SCORPIOX BOT theme tokens — ?theme=,

localStorage.bot_theme, prefers-color-scheme, and the sx-theme

postMessage handoff; the plugin's own toggle hides under ?embed=1

  • no <script src=>, no CDN, no framework, zero emoji — inline SVG only

1440 dark

390 dark

API routes the page uses

The single most common plugin bug is calling the wrong route. This page branches

exactly once:

  • served through the hub (/plugins?plugin=plugin_memory&node=...) → call the hub

proxy back: /plugins?plugin=plugin_memory&action=...

  • opened directly on the node (/plugin_memory) → the plugin is the route:

/plugin_memory?action=...

Calling /plugins?plugin= on the node itself returns the discovery list, not the

plugin.

Test

make test        # 180+ offline assertions, 0 fail, no network, no Playwright
make e2e         # Playwright: 6 viewports × theme, console/overflow/CRUD round trip

The offline suite proves the contract: --meta field for field, --mcp as a real

JSON-RPC session (all nine tools, notifications, bad JSON, unknown method,

ping, resources), the skip / dedupe / not-found semantics, observationLimit 0

versus absent, the either-endpoint relation rule, cross-process persistence,

verbatim survival of a malformed line, no .tmp left behind, every HTTP action's

JSON shape, the auth matrix, the source guards, and the ASan/UBSan run. It also

cross-builds musl, aarch64 and MinGW where the toolchain is installed, and audits

git history for LAN IPs and tokens.

License

MIT — see LICENSE. Vendored: yyjson

0.12.0 (MIT, vendor/, compiled in — no runtime dependency on any target).