Pure JSON-RPC 2.0 encoding/decoding for the Model Context Protocol, plus the
mapping from an MCP tool spec to an ExAgent.Tool.
Splitting the protocol out (no ports, no processes) keeps it trivially
unit-testable. ExAgent.MCP.Client owns the transport and calls into here.
Summary
Functions
Decode one complete JSON-RPC line.
Encode a JSON-RPC notification (no id, no reply expected).
Encode a JSON-RPC request (with an id) as a newline-terminated binary.
Extract the concatenated text from an MCP tools/call result.
Map an MCP tools/list entry to an ExAgent.Tool whose call forwards to the
server via call_fun. The tool's result text is extracted from the MCP
content blocks; an MCP isError: true becomes {:error, _}.
Types
Functions
Decode one complete JSON-RPC line.
- a response with a
result→{:response, id, result} - a response with an
error→{:error_response, id, error} - a notification (no
id) →{:notification, method, params} - anything unparseable / unrelated →
:ignore
Encode a JSON-RPC notification (no id, no reply expected).
Encode a JSON-RPC request (with an id) as a newline-terminated binary.
Extract the concatenated text from an MCP tools/call result.
@spec to_tool(map(), (String.t(), map() -> {:ok, String.t()} | {:error, term()})) :: ExAgent.Tool.t()
Map an MCP tools/list entry to an ExAgent.Tool whose call forwards to the
server via call_fun. The tool's result text is extracted from the MCP
content blocks; an MCP isError: true becomes {:error, _}.