ConduitMcp.Protocol.Legacy (ConduitMCP v0.11.0)

Copy Markdown View Source

Shapes a neutral handler result (ConduitMcp.Handler.result/0) into the JSON-RPC 2.0 response map of the legacy (initialize-negotiated) protocol era.

{:ok, result} becomes a success response; {:error, code, message, data} becomes an error response, with a "data" member only when data is not nil. Codes pass through unchanged.

Resource not found

The legacy era answers an unknown resource with -32002 (resource_not_found/0). That is also the code a handle_read_resource/2 callback returns in every authoring mode: the modern shaper, ConduitMcp.Protocol.Modern, rewrites it to -32602, which is what 2026-07-28 prescribes.

Summary

Functions

The legacy-era "resource not found" code, -32002.

Builds the JSON-RPC response for request id from a neutral result.

Functions

resource_not_found()

@spec resource_not_found() :: integer()

The legacy-era "resource not found" code, -32002.

Return it from handle_read_resource/2 for an unknown URI; the modern era sees -32602 instead (see the moduledoc).

to_response(id, arg)

@spec to_response(
  ConduitMcp.Protocol.json_rpc_id() | nil,
  ConduitMcp.Handler.result()
) :: map()

Builds the JSON-RPC response for request id from a neutral result.

Examples

iex> ConduitMcp.Protocol.Legacy.to_response(1, {:ok, %{}})
%{"jsonrpc" => "2.0", "id" => 1, "result" => %{}}

iex> ConduitMcp.Protocol.Legacy.to_response(1, {:error, -32601, "Nope", nil})
%{"jsonrpc" => "2.0", "id" => 1, "error" => %{"code" => -32601, "message" => "Nope"}}