MemoFSMemoFS
Self-Hosting

API Reference

Complete API reference for @memofs/server functions, options, dispatch handlers, and protocol constants.

Factories & Runtime Assembly

createHostedRuntime(options: HostedRuntimeOptions): MemoFS

Assembles a provider-neutral MemoFS instance for the hosted server runtime.

import { createHostedRuntime } from "@memofs/server";

const memofs = createHostedRuntime({
  store: memoryStore,
  projectId: "prod-project",
  embedder: customEmbedder,
});

HostedRuntimeOptions

OptionTypeRequiredDescription
storeMemoryStoreYesFoundational memory store (file replica).
projectIdstringYesProject identifier scoping the store.
embedderMemoryEmbedderNoVector embedding provider for semantic recall.
recallStoreRecallStoreNoCustom vector index storage adapter.
rerankerRerankerNoReranking provider for search candidate scoring.
extractorExtractorNoKnowledge graph entity/edge extractor.
llmClientLlmClientNoLLM transport for generative consolidation.
namestringNoRuntime client name (default: "memofs-server").
versionstringNoRuntime version (default: "0.1.0").

HTTP Request Handlers

handleRuntimeRequest(request: Request, options: RuntimeHttpOptions): Promise<Response>

Processes standard Web Request objects containing JSON-RPC payloads and returns a Web Response.

import { handleRuntimeRequest } from "@memofs/server";

const response = await handleRuntimeRequest(request, {
  runtime: memofs,
  requireAuth: true,
  bearerToken: "secret-token",
});

RuntimeHttpOptions

OptionTypeRequiredDescription
runtimeMemoFSYesThe assembled runtime instance.
concurrencyLayerConcurrencyLayerNoLock coordinator for gating mutating methods.
requireAuthbooleanNoRequire a bearer token on POST / (default: false).
bearerTokenstringNoExpected token when requireAuth is true.
allowedOriginsreadonly string[]NoAllowed origins for CORS headers.

createRuntimeFetchHandler(options: RuntimeFetchHandlerOptions)

(Exported from @memofs/server/worker)

Builds a Cloudflare Workers fetch(request, env, ctx) handler.

import { createRuntimeFetchHandler } from "@memofs/server/worker";

export default {
  fetch: createRuntimeFetchHandler({
    createRuntime: (env, request) => buildRuntime(env, request),
    requireAuth: false,
  }),
};

JSON-RPC Dispatch Utilities

dispatchRuntimeMessage(runtime: MemoFS, payload: unknown, options?: DispatchOptions): Promise<JsonRpcResponse | undefined>

Dispatches a parsed JSON-RPC request object or batch array across the runtime.

import { dispatchRuntimeMessage } from "@memofs/server";

const response = await dispatchRuntimeMessage(
  memofs,
  { jsonrpc: "2.0", id: 1, method: "recall", params: { query: "auth" } },
  { concurrencyLayer: myMutex }
);

dispatchRuntimeText(runtime: MemoFS, text: string, options?: DispatchOptions): Promise<string | undefined>

Parses and dispatches a raw JSON-RPC string payload, returning a stringified JSON-RPC response.

import { dispatchRuntimeText } from "@memofs/server";

const responseString = await dispatchRuntimeText(
  memofs,
  '{"jsonrpc":"2.0","id":1,"method":"health"}'
);

Protocol Constants

RUNTIME_METHOD

Symbolic dictionary of all registered JSON-RPC method strings:

  • Live Methods: health, recall, context, memory.readCore, memory.readNotes, memory.readConversations, memory.listRecent, memory.validate, graph.listNodes, graph.listEdges, graph.neighbors, graph.path, snapshots.list.
  • Gated Methods: memory.write, memory.recordNote, memory.updateCore, memory.appendConversation, graph.upsertNodes, graph.upsertEdges, consolidate, snapshots.create, snapshots.restore.

LIVE_METHODS: ReadonlySet<string>

Set of method names that execute concurrently without requiring a concurrency layer.

GATED_METHODS: ReadonlySet<string>

Set of mutating method names that return 503 when no concurrency layer is injected.

CONCURRENCY_GATE_ERROR_CODE

-32000 (JSON-RPC server error code for concurrency lock requirements).

CONCURRENCY_GATE_HTTP_STATUS

503 (HTTP status code carried in gate failure data).

CONCURRENCY_GATE_MESSAGE

"Concurrent writes require the concurrency layer. This method is read-only until it is injected."

On this page