Wymcp. ServerInfo
(Wymcp v0.2.2)
View Source
Owns the server identity map (serverInfo) both eras emit — the legacy
lane in the initialize result, the modern lane in every result's
_meta (Wymcp.Modern) — split across two moments. At the mount
module's compile, encode!/1 validates the :server_info router
option and returns the serverInfo partial that Wymcp.Router.init/1
stores in the option's place; per request, build/1 merges name
and version into that partial. Those two stay application config
reads (:wymcp, :name / :version) because mix compile runs
before config/runtime.exs.
Validation is key-deep only: an unknown key — or an :icons value
that is not a list of maps, which is the shape the key check has to
walk — aborts the consumer's mix compile with a named
ArgumentError, while every field value passes to the wire verbatim,
so a value typo stays visible client-side instead of aborting the
build. Wymcp.Router documents the accepted keys.
Summary
Functions
Merges name and version — application config, read per call — into
the stored serverInfo partial, which must already be encode!/1's
output: this is the request half of the split, and it re-encodes
nothing. Tolerates a :server_info key that is absent or nil (an
empty partial), so callers that never ran Wymcp.Router.init/1 still
get the two-field map.
Validates the authored :server_info map and returns the serverInfo
partial — the wire-shaped serverInfo fragment precomputed at the
mount module's compile: the optional identity fields under their
camelCase wire names; name and version join per request
(build/1).
Functions
Merges name and version — application config, read per call — into
the stored serverInfo partial, which must already be encode!/1's
output: this is the request half of the split, and it re-encodes
nothing. Tolerates a :server_info key that is absent or nil (an
empty partial), so callers that never ran Wymcp.Router.init/1 still
get the two-field map.
Validates the authored :server_info map and returns the serverInfo
partial — the wire-shaped serverInfo fragment precomputed at the
mount module's compile: the optional identity fields under their
camelCase wire names; name and version join per request
(build/1).
Raises ArgumentError — aborting the consumer's mix compile when
called from Wymcp.Router.init/1 — on a non-map value, an unknown
key, a :name/:version key, a non-list :icons, a non-map icon,
or an unknown icon key. A nil field value reads as absent and
icons: [] is omitted, so authored options can stay permissive.
Examples
iex> Wymcp.ServerInfo.encode!(%{})
%{}
iex> Wymcp.ServerInfo.encode!(%{title: "My App", website_url: "https://my.app"})
%{"title" => "My App", "websiteUrl" => "https://my.app"}