Matrix logo

RPC Server

The JSON-RPC dispatcher routes tachyon_ methods to the engine. It is used by both the HTTP API (POST /rpc) and the MCP server (tools/call).

Source file: pkg/rpc/server.go

The JSON-RPC dispatcher routes tachyon_* methods to the engine. It is used by both the HTTP API (POST /rpc) and the MCP server (tools/call).


Design decisions

Method-per-verb mapping

Each JSON-RPC method maps 1:1 to an engine verb:

MethodEngine callRequest type
tachyon_compileeng.Compiletypes.CompileRequest
tachyon_testeng.Testtypes.TestRequest
tachyon_simulateeng.Simulatetypes.SimulateRequest
tachyon_deployeng.Deploytypes.DeployRequest
tachyon_calleng.Calltypes.CallRequest
tachyon_chain_listeng.ChainList(none)
tachyon_chain_registereng.ChainRegistertypes.ChainRegisterRequest
tachyon_chain_useeng.ChainUsetypes.ChainUseRequest
tachyon_artifact_geteng.ArtifactGettypes.ArtifactGetRequest
tachyon_registry_lookupeng.RegistryLookuptypes.RegistryLookupRequest
tachyon_healtheng.Health(none)

Envelope passthrough

The engine returns types.Envelope[T]. The JSON-RPC layer passes this through as the result field. This means JSON-RPC responses have the same shape as REST responses:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "ok": true,
    "data": { ... }
  }
}

Standard JSON-RPC error codes

  • -32700 — Parse error (malformed JSON)
  • -32602 — Invalid params (type mismatch, missing field)
  • -32601 — Method not found

Engine errors are not JSON-RPC errors. They are returned in the envelope's error field with ok: false. This preserves the engine's structured error taxonomy across all transports.

Context propagation

The JSON-RPC dispatcher accepts a context.Context and passes it to engine methods. This enables request cancellation and timeout propagation from the HTTP server or MCP caller.


Modifying the RPC server

What to changeWhere
Add JSON-RPC methodpkg/rpc/server.go — add case in Dispatch
Change error codespkg/rpc/server.gorpcError struct
Add batch supportpkg/rpc/server.go — parse array requests