SDK

The C99 Three-Mode Plugin SDK

One file, three modes, no dependencies: --meta for discovery, ?action= for JSON, plain GET for a responsive HTML page. The whole contract in one page of C.

sdk5 min readsnapshot

Every plugin in this market is the same shape. One C file, no dependencies, one binary, three modes. This page is the whole contract. If you can read it, you can write a plugin; if your plugin does not implement exactly this, no amount of UI polish will make the node load it.

The contract in one table

InvocationMust returnContent-Type
plugin_x --meta, or SX_PLUGIN_META=1 in the environment{"name":"Display Name","desc":"One line"}anything JSON-parseable
GET /plugin_x?action=..., or ?format=jsona JSON object, always with okapplication/json; charset=utf-8
GET /plugin_x with neithera complete HTML pagetext/html; charset=utf-8

That is it. There is no manifest format to learn, no registration call, no schema to upload. The filename is the route; the three behaviours are the entire interface.

Mode 1 — metadata

$ ./plugin_starter --meta
{"name":"Starter Plugin","desc":"A copy-paste single-binary SCORPIOX BOT plugin"}

Both --meta as argv[1] and SX_PLUGIN_META=1 must work, because the discovery scanner uses the environment form when it probes every plugin in a directory at once, and quick verification from a shell uses the argument form. The output must be a JSON object; the installer's smoke test parses it, and a plugin whose metadata does not parse is rejected before installation.

Two fields are read: name for the display title and desc for the one-line summary in Settings. A plugin that returns an empty object still loads, with a humanised filename as its title — which is why every plugin in this catalogue implements this mode properly rather than relying on the fallback.

Mode 2 — the JSON action API

$ QUERY_STRING='action=info' ./plugin_starter
Content-Type: application/json; charset=utf-8
Cache-Control: no-store
X-Content-Type-Options: nosniff

{"ok":true,"plugin":"plugin_starter","version":"1.0.0","node":{"os":"linux",...}}

The dispatch is a strcmp chain on one query parameter. There is no router and no framework, because there does not need to be. Four rules govern it.

Always emit ok. true on success, false with an error string on failure. The UI keys off it and so does the installer's smoke test. A response without ok is a broken plugin even if the rest of the JSON is correct.

Never emit Content-Length. scorpiox-server frames the response itself; a duplicate header is a 502 from the reverse proxy and will look like the plugin is down. This is the single most common mistake in a first plugin.

Missing action means info. A caller that sends ?format=json with no action is asking the same question as a caller that sends ?action=info. Handling both identically keeps "give me the state" a single code path.

Unknown actions fail loudly. {"ok":false,"error":"unknown action","action":"foo","supported":["info"]} — the supported array is what lets an agent discover the plugin's surface without reading its source.

Authentication

The node API listens on a LAN-reachable port. A plugin that answered any caller would be an unauthenticated read of whatever it exposes. Every plugin therefore calls the same guard at the top of its JSON path:

  • accept X-Bot-Password: <pwd> when it equals BOT_PASSWORD,
  • accept Authorization: Bearer <pwd>,
  • accept ?pwd=<pwd>,
  • when BOT_PASSWORD is unset, the node is explicitly open and the guard is a no-op.

Return 401 with a JSON body and exit. Do not fall through.

Reading query parameters

scorpiox-server exports query parameters as environment variables and also provides QUERY_STRING. Do not split it naively at the first & you find in a value — %26 inside a value is data. Decode each key and each value once, after splitting. The starter file contains the twenty-line implementation; copy it rather than inventing one.

Mode 3 — the HTML UI

$ QUERY_STRING='' ./plugin_starter | head -2
Content-Type: text/html; charset=utf-8
Cache-Control: no-store

The page is returned by the plugin and rendered inside the SCORPIOX BOT chat surface. It must be self-contained: no external stylesheet, no CDN script, no font download. A container with no outbound network must still render it.

The page should respect ?embed=1, which means "you are inside an iframe, do not draw your own chrome". Practically that is a class on <body> and a few CSS rules, not a second page.

Its script should call only its own ?action= endpoints. Because the page can be served either directly at /plugin_x or proxied at /plugins?plugin=plugin_x&node=..., the URL the script builds depends on how it was reached:

var hub = q.get('plugin');           // set when served through the bot web proxy
var u = hub ? '/plugins?plugin=' + encodeURIComponent(hub)
            : '/plugin_x?action=' + encodeURIComponent(action);

Then append &node=, &id= and &pwd= if the page was opened with them. The proxy inherits those from the referer for in-iframe requests, but a page opened in a new tab has no referer and must pass them itself.

The build

cc      -O2 -std=c99 -o plugin_starter plugin_starter.c
musl-gcc -O2 -std=c99 -static -o plugin_starter plugin_starter.c
x86_64-w64-mingw32-gcc -O2 -std=c99 -static -o plugin_starter.exe plugin_starter.c

Three flags matter and the rest are taste. -std=c99 keeps you honest about portability across the four compilers. -static is what makes a musl or MinGW binary run on a machine that has neither glibc's version nor the VC++ runtime. -O2 is the convention used by every published artifact, so a locally built binary behaves like the one from dist.

-pedantic -Wall -Wextra is worth keeping for your own code: it catches the two things that bite most often, a missing #include that happens to compile on your platform, and a format string that does not match its argument.

What the starter gives you

The file in the SDK tab is complete and working. It compiles with no warnings, answers all three modes, carries the auth guard, emits no Content-Length, and its UI has a dark/light toggle and a live JSON view of the same facts the API returns.

Changing it into a real plugin is three edits:

  1. the PLUGIN_SLUG, PLUGIN_NAME and PLUGIN_DESC defines,
  2. emit_info() — replace the node facts with whatever your plugin actually reports,
  3. the CSS variable block and the card markup, if you want a different look.

Rename the binary to plugin_<your_slug> and the route follows. There is nothing else to register.

Portability notes

getpid() does not exist on Windows; the starter uses GetCurrentProcessId() behind #if defined(_WIN32). gmtime_r is POSIX; Windows has gmtime_s with a different signature. Those two are the only platform differences in the whole template, which is why the file compiles with a MinGW cross-compiler unmodified.

If your plugin reads /proc, runs a command through popen, or opens a socket, those are POSIX-only and you will need a #if branch or a #error on Windows. Deciding that early is better than discovering it in the release script.

  • The Vendored Connector SDK — the same contract plus --mcp and --daemon, on a vendored HTTPS/TLS/WebSocket stack.
  • Embedding, Short Metadata and UI Rules — the response-size, escaping and layout rules the UI enforces.
  • Cross-Compiling for musl, MinGW and macOS — producing all six published targets from one source file.
  • dist Manifests and SHA-256 — how to publish your build so the one-click installer accepts it.