SDK

The Vendored Connector SDK

The one HTTPS/TLS/WebSocket stack, MCP loop and node bridge that a connector is written on top of: vendored BearSSL and yyjson, verified TLS by default, --mcp and --daemon, and the two hundred lines you still have to own.

sdk8 min readsnapshot

A connector is a plugin that also talks to something: an HTTPS API on one side, the agent on the other, sometimes a chat network on a third. You can write all of that from the three-mode contract with hand-rolled sockets, and one repository will do that happily. What you cannot do is hand-roll it three thousand times and still trust the result. This page is the vendored Connector SDK — the one HTTP/TLS/WebSocket stack, the one JSON-RPC loop, the one node bridge — and the two-hundred lines you write on top of it.

The contract, restated for connectors

plugin_<name> is the whole extension spec. A connector is not a new subsystem; it is the same single executable with two optional extra modes and three extra --meta fields.

InvocationMust return
--meta / SX_PLUGIN_META=1one-line JSON: name, desc, kind, mcp, daemon, menus, verified
GET with neither action= nor format=jsonthe setup UI, text/html, bot-themed, ?embed=1-aware
?action= / ?format=json / POSTJSON, always with ok, behind the node-auth guard
--mcpstdio MCP JSON-RPC 2.0 — initialize, notifications/initialized, ping, tools/list, tools/call
--daemona long-lived bridge between the outside network and the node API

The three extra fields are what make the market usable once there are hundreds of them. kind is ui / mcp / channel / hybrid; menus is false for a pure connector, because a dropdown that lists fifty installed connectors is a dropdown nobody can use; verified is an honesty field — mock means the connector was proven against a local mock, live means it was proven against the real service. Never set live because it looked like the right thing to type.

Why the TLS stack is vendored rather than linked

The node that runs your binary may be a slim container with no libssl.so, an Alpine image whose OpenSSL is a different major version than the one you developed against, or a stock Windows laptop with neither. A connector that needs a runtime library is a connector that fails to load on exactly the machines where it is most useful, and fails at install time with a message about a file, not about your code.

So the SDK carries its own: BearSSL 0.6 (MIT, pure C99, no external dependencies at all) and yyjson 0.12.0 (MIT), both vendored unmodified with their digests recorded. There is no libcurl, no libssl, no OpenSSL, no WinHTTP import library. ldd on the musl binary says *not a dynamic executable*; the MinGW binary is -static and pulls in no third-party DLL. You can confirm both yourself in under a minute, which is the point: the six-target claim is checkable, not a promise.

Five minutes to a connector

git clone https://git.scorpiox.net/SCORPIOX_INC/scorpiox-bot-connector-sdk.git
cd scorpiox-bot-connector-sdk
make lib                     # build/libsxconn.a = SDK + yyjson + BearSSL
make example test            # reference connector + the whole offline suite

Your repository is then one C file and one link line:

#include "sx_connector.h"

static const sx_mcp_tool TOOLS[] = {
    { "hello", "say hello",
      "{\"type\":\"object\",\"properties\":{\"who\":{\"type\":\"string\"}}}",
      tool_hello },
};

static const sx_plugin_info INFO = {
    .id = "hello", .name = "hello", .desc = "greeting",
    .kind = SX_KIND_MCP, .mcp = 1, .daemon = 0, .menus = -1,
    .verified = "mock", .version = "1.0.0",
};

int main(int argc, char **argv)
{
    sx_stdio_binary();                                    /* Windows CR CRLF guard */
    if (sx_has_flag(argc, argv, "--mcp"))    return sx_mcp_serve(&INFO, TOOLS, 1);
    if (sx_has_flag(argc, argv, "--schema")) return sx_mcp_schema(&INFO, TOOLS, 1);
    return sx_main(argc, argv, &INFO, html_ui, json_api);
}
cc -O2 -std=c99 src/plugin_hello.c path/to/build/libsxconn.a -o plugin_hello
./plugin_hello --meta
install -m 0755 plugin_hello ~/.scorpiox/plugins/

examples/test_connector.c is the file to actually copy: an MCP tool server, a channel bridge and a themed setup UI in one binary, and it is the executable the SDK's own test suite drives. If your connector is not roughly that shape, you are fighting the SDK rather than using it.

The network layer, and the three bugs it exists to prevent

sx_url_parse, sx_conn_open, sx_http_request, sx_read_all / sx_read_line, plus sx_sse_* for record-at-a-time Server-Sent Events and sx_ws_connect / sx_ws_send / sx_ws_recv for RFC 6455 with client-side masking and automatic ping/pong. Deadlines are absolute and per-phase: DNS, connect, handshake, every header byte, and every read of a stream that may legitimately sit idle for minutes. Three things this design is specifically paying for.

A half-closed socket is an error, not a signal. A server that answers Connection: close closes its read side the moment it answers. The next write() from your process raises SIGPIPE, whose default disposition kills the process — and if something in your process has installed a handler, the signal returns into whatever frame it landed in and your socket call comes back with a nonsense value taken from errno. A bridge that "sometimes reports status 25" is a bridge with an unignored SIGPIPE. The SDK ignores it (sx_ignore_sigpipe(), called by sx_main, sx_mcp_serve and sx_daemon_run) and passes MSG_NOSIGNAL, so a vanished peer is an ordinary -1 with a readable error string.

An infinite body must never be buffered whole. SSE and NDJSON streams have no length. Chunked transfer-encoding is therefore a small state machine and reads are record-at-a-time, with hard ceilings — 4 MiB body, 1 MiB line, 1 MiB frame — that turn a hostile server into an error rather than an OOM.

Time is not a budget you can spend once. A single "30 second timeout" applied to a whole request is a 30-second hang per phase, times however many phases the server decides to stall. Each phase gets its own absolute monotonic deadline.

TLS is on by default, and there is exactly one escape hatch

Verification happens against a compiled-in root bundle, plus SX_CA_BUNDLE and the usual system bundle paths for private CAs, with hostname verification. Optional SPKI pinning (SX_TLS_PIN, hex SHA-256 over the SDK's canonical public-key encoding) is an operator override: a connection passes when the chain verifies *or* the leaf key is pinned, which is what lets a self-hosted relay with a private CA still be trusted deliberately. There is no accept-anything default. The single way out is the environment variable SX_TLS_INSECURE=1, which cannot be set from a config file or an HTTP request and prints a warning on every use. If you find yourself wanting it in production, what you want is a pin.

--mcp: the tool server

sx_mcp_serve() owns stdin and stdout: unbuffered output, line-delimited JSON-RPC 2.0, one object per line, no reply to notifications, -32601 for an unknown method, and isError: true with a text part for a tool that failed rather than a transport-level error — an agent can read an error message, it cannot read a closed pipe. Your tools are a static array of {name, description, inputSchema, handler} and a handler is int (*)(const char *args_json, char *out, size_t outsz, char *err, size_t errsz). Nothing about that knows what your service is.

Registering every connector as its own MCP server does not scale — the CLI has a hard server ceiling — so all mcp:true plugins are routed behind one aggregator, sx-connector-mcp, which exposes four meta-tools (connector_list, connector_search, connector_tools, connector_call) and reads the connector directory live. That is also why tools/list must stay honest and small: your tool descriptions are prompt context for every session.

--daemon: the channel bridge, and the rule that makes it safe

A channel connector is an inbound door from a network where anyone can address you. Three rules, and the SDK enforces the first two structurally rather than by documentation.

Default-deny is not a setting. An unknown sender is refused and held in a pairing queue until the owner approves their sender ID or pairing code in the setup UI. Nothing reaches the node before that, because what sits behind /inbox is a shell-capable session. If your connector has no sender-identity primitive at all (a pub/sub relay where anyone who knows a topic can publish is the usual case), you derive an identity from whatever the payload does carry and treat it as untrusted until paired — do not promote a publisher-controlled field to an identity.

A CGI handler never forks a daemon. A short-lived request handler that leaves a long-lived child behind produces orphans and duplicate connections, one per page refresh. --daemon is supervised by the node: sx_daemon_run() takes a tick callback, manages the pidfile and the stop file, handles SIGTERM/SIGINT/SIGHUP, and returns. Your tick does the platform work and returns non-zero to stop.

State lives in the connector directory, never next to the binary. sx_connector_dir() resolves SX_CONNECTOR_DIR → /workspace/.scorpiox/connectors/<id> (persistent across container restarts) → ~/.scorpiox/connectors/<id> → %LOCALAPPDATA%\scorpiox\connectors\<id>. Tokens, refresh tokens, allowlists and pairing codes go there via sx_json_file_load/_save. Never into a sidecar that the market mirror publishes.

The node side is three loopback calls with the node credential attached: sx_node_post_inbox() → POST /inbox?id=<session>, sx_node_conversation() → GET /conversation, and sx_sse_open/sx_sse_next on GET /hashes_sse. The credential comes from BOT_PASSWORD and is sent as X-Bot-Password; CR and LF are stripped from it before it reaches a header, because a password is an operator-typed string and an injected header is a security bug with a typo as its root cause.

The setup UI

sx_html_head() and SX_THEME_CSS give you the bot's tokens (--bg-card, --surface, --text-2, --blue, --mono, …) and SX_THEME_HANDOFF_JS the sx-theme postMessage handoff, so the page decides its theme before first paint in the order ?theme= → localStorage.bot_theme → prefers-color-scheme, and hides its own toggle under ?embed=1. Do not invent a plugin-private palette; you will be the one dark card in a light frame. The embed and short-metadata rules in the UI guide still apply in full — connectors get no exemption for being headless, because they still have a settings page and it still renders at 390 pixels.

What you still have to get right yourself

The SDK cannot make your connector correct. It will not decide which of your endpoints needs authentication, whether a refresh token is stored before or after the network call that consumes it, whether a partially-written config file is your problem (it is), or what your tool does when the upstream returns 200 with an empty body. It also cannot tell whether verified is true. Write the mock harness first, name it mock, and promote it to live only when a real account has exercised it.

  • The C99 Three-Mode Plugin SDK — the base contract the connector modes extend.
  • Cross-Compiling for musl, MinGW and macOS — building the six targets from one source, and proving they are static.
  • dist Manifests and SHA-256 — publishing the six artifacts a node can verify.
  • Why Plugins Are Untrusted — the threat model a channel connector sits on top of.