API referencegRPC / ConnectRPC

gRPC / ConnectRPC

Alpha, on the 3.6.x line. 17 RPCs are served with ConnectRPC on the same HTTP port as REST, under the path prefix /mnemosyne.v1.MnemosyneService/. Messages can still change within 3.x.

Service definition

The proto file is packages/server/proto/mnemosyne.proto in the repository. No client package is published: generate your own client from it with Buf.

syntax = "proto3";
 
package mnemosyne.v1;
 
service MnemosyneService {
  // Unary
  rpc Recall(RecallRequest)                   returns (RecallResponse);
  rpc Remember(RememberRequest)               returns (RememberResponse);
  rpc ResolveReasoning(ResolveReasoningRequest) returns (ResolveReasoningResponse);
  rpc CreateTask(CreateTaskRequest)           returns (Task);
  rpc UpdateTask(UpdateTaskRequest)           returns (Task);
  rpc RecordEvent(RecordEventRequest)         returns (Event);
  rpc Forget(ForgetRequest)                   returns (ForgetResponse);
  rpc RecordReasoning(RecordReasoningRequest) returns (RecordReasoningResponse);
  rpc GetHealth(GetHealthRequest)             returns (HealthSnapshot);
  rpc SelfEdit(SelfEditRequest)               returns (SelfEditResponse);
 
  // Server-streaming
  rpc WatchMemory(WatchMemoryRequest)   returns (stream MemoryEvent);
  rpc WatchTasks(WatchTasksRequest)     returns (stream TaskEvent);
  rpc StreamHealth(StreamHealthRequest) returns (stream HealthSnapshot);
 
  // Client-streaming
  rpc IngestBatch(stream MemoryItem)    returns (IngestSummary);
  rpc ImportMemory(stream Chunk)        returns (ImportResult);
 
  // Bidi
  rpc Session(stream SessionRequest)         returns (stream SessionResponse);
  rpc FederationSync(stream SyncMessage)     returns (stream SyncMessage);
}

Transport

The server listens with Node’s HTTP/1.1 server and dispatches requests whose path starts with /mnemosyne.v1.MnemosyneService/ to the Connect handler. The repository’s tests call it with the Connect and gRPC-Web protocols over HTTP/1.1. HTTP/1.1 carries unary and one-way streaming calls, but not a bidirectional one: Session and FederationSync fail there with HTTP 505.

Set MNEMO_GRPC_PORT to open a second listener, cleartext HTTP/2 (h2c), that serves only this service, with the same authentication. It takes every RPC, the two bidirectional ones included, in the gRPC, gRPC-Web and Connect protocols. It has no TLS of its own: put a proxy that terminates TLS and forwards HTTP/2 in front of it. On that port the client-IP headers count only from MNEMO_TRUSTED_PROXY_IP. The port must differ from PORT.

A single message can be up to 1 MiB, the same limit as a REST body.

Authentication

Send the API key as a request header:

Authorization: Bearer mns_live_xxx

A missing or invalid key returns Unauthenticated. A key without the required scope returns PermissionDenied.

Scopes

The API-key scope each method requires:

MethodsScope
Recall, ResolveReasoning, GetHealthmemory:read
Remember, RecordReasoning, CreateTask, UpdateTask, RecordEvent, IngestBatch, ImportMemory, Sessionmemory:write
Forgetmemory:delete
SelfEditmemory:self_edit
WatchMemory, WatchTasks, StreamHealthmemory:subscribe
FederationSyncmemory:federation

Forget is a soft delete. There is no hard delete over gRPC.

FederationSync answers Unimplemented to every key: a peer never pushes into this server. A pull is started with POST /memory/federation/sync.

An operation that needs a human approval returns FailedPrecondition over gRPC: use the REST API for it.

See also