Skip to content

@slop-ai/server

The server package lets you expose application state and actions to AI consumers over SLOP. It handles tree assembly, diffing, patch broadcasting, and action dispatch. Pair it with a transport adapter to serve over WebSocket, Unix socket, or stdio.

Terminal window
bun add @slop-ai/server
import { createSlopServer } from "@slop-ai/server";
const slop = createSlopServer({
id: "my-app",
name: "My App",
});
  • register(path, descriptorOrFn)
  • unregister(path)
  • scope(prefix)
  • refresh()
  • onChange(listener)
  • getVersion()
  • getTree()
  • stop()

Server registrations can be static objects or functions. Use descriptor functions when the provider needs to re-read changing application state.

slop.register("todos", () => ({
type: "collection",
props: { count: getTodos().length },
items: getTodos().map((todo) => ({
id: todo.id,
props: { title: todo.title, done: todo.done },
})),
}));

Call slop.refresh() after mutations that happen outside SLOP action handlers.

The server instance is transport-agnostic. Pick the runtime-specific export that matches your app:

  • @slop-ai/server/node
  • @slop-ai/server/bun
  • @slop-ai/server/unix
  • @slop-ai/server/stdio
  • @slop-ai/server/nitro
  • @slop-ai/server/vite
import { createServer } from "node:http";
import { attachSlop } from "@slop-ai/server/node";
const server = createServer(app);
attachSlop(slop, server, { path: "/slop" });
server.listen(3000);
import { listenUnix } from "@slop-ai/server/unix";
listenUnix(slop, "/tmp/slop/my-app.sock", { register: true });