Protocols

Status: implemented

The messages the repository exchanges with a peer are schemas, so one declaration is both the decoder and the static type:

  • the JSON-RPC 2.0 envelopes, in protocol/json_rpc;
  • the MCP messages, in protocol/mcp;
  • the arguments of the MCP tools the repository serves, in mcp/cas and mcp/evo. A tool's argument schema is both the inputSchema the server advertises, through toJsonSchema, and the check its arguments pass.

A message read from a peer is read with parse: what comes in is rebuilt to the schema. The envelopes say open, so a peer on a later protocol revision can add members (open containers); a tool's arguments are closed, because the server defines that vocabulary.

Examples

The demo on this page offers four schemas: a JSON-RPC request, an MCP tool, and the arguments of cas_add and evo_add, each shown as the import that brings it in and with a value it accepts. They are defined in sample.f.mjs, and the module page's demo lists them among all the others.

Where it is implemented

The modules linked above.

Demo

A JSON-RPC 2.0 request; without an id it is a notification. open(), so a peer on a later protocol revision can add members. Read with parse.

import { request } from 'functionalscript/fjs/protocol/json_rpc/module.f.mjs'
open [] → {}{} [params] → or{} [id] → oror [] → unknown oror [] → orunknown or [] → orunknown or [] → recordunknown or [] → arrayrecord [] → unknown or (recursive)array [] → unknown or (recursive)open{}jsonrpcmethodparamsid"2.0"stringorororoptionunknown ororoptionorunknown ororstringnumbernullornullbooleannumberstringrecordarray

TypeScript:

type T0 = null|boolean|number|string|readonly(T0)[]|{readonly[k in string]?:T0}
{readonly"id"?:null|number|string,readonly"jsonrpc":"2.0",readonly"method":string,readonly"params"?:null|boolean|number|string|readonly(T0)[]|{readonly[k in string]?:T0}}

JSON Schema:

{"type":"object","properties":{"id":{"anyOf":[{"const":null},{"type":"number"},{"type":"string"}]},"jsonrpc":{"const":"2.0"},"method":{"type":"string"},"params":{"anyOf":[{"const":null},{"type":"boolean"},{"type":"number"},{"type":"string"},{"type":"array","items":{"$ref":"#/$defs/unknown"}},{"type":"object","additionalProperties":{"$ref":"#/$defs/unknown"}}]}},"required":["jsonrpc","method"],"$defs":{"unknown":{"anyOf":[{"const":null},{"type":"boolean"},{"type":"number"},{"type":"string"},{"type":"array","items":{"$ref":"#/$defs/unknown"}},{"type":"object","additionalProperties":{"$ref":"#/$defs/unknown"}}]}}}
Canonical form (toData)
export default [{"unknown":{"unit":13,"number":true,"string":true,"array":[{"prefix":[],"rest":"unknown"}],"object":[{"props":{},"rest":"unknown"}]}},{"object":[{"props":{"id":{"unit":17,"number":true,"string":true},"jsonrpc":{"string":["2.0"]},"method":{"string":true},"params":{"unit":29,"number":true,"string":true,"array":[{"prefix":[],"rest":"unknown"}],"object":[{"props":{},"rest":"unknown"}]}}}]}];

parse · ok

export default {"jsonrpc":"2.0","method":"tools/list","id":1};

validate · ok

export default {"jsonrpc":"2.0","method":"tools/list","id":1};

Emergent Testing

Idle. Press Run to start the suite.

  • ./proof.f.mjs