Toolnexus.Mcp.Protocol (toolnexus v0.9.4)

Copy Markdown View Source

Pure JSON-RPC 2.0 codec for the in-house MCP client (SPEC §2).

Framing/correlation helpers plus the MCP methods toolnexus speaks: initialize, notifications/initialized, tools/list (cursor pagination), tools/call, inbound ping, and the inbound elicitation/create bridge onto §10 Request/Answer (mirrors js/src/mcp.ts elicitationToRequest / answerToElicitResult exactly).

Summary

Functions

Map a resolved §10 Answer back onto an MCP elicit result: ok → accept (with answer.data as content); reason=="declined" → decline; everything else → cancel.

Classify a decoded inbound message: {:request, id, method, params} (server→client request, e.g. ping/elicitation), {:response, id, {:ok, result} | {:error, error}}, {:notification, method, params}, or :unknown. Unknown notifications are tolerated silently by the caller.

clientInfo version — the toolnexus app version from mix.

Map an MCP elicitation/create request onto a §10 Request: form mode → kind:"input" (with requestedSchema carried in data.schema); URL mode (mode == "url") → kind:"authorization" with url.

Encode a message as one newline-delimited JSON line (stdio framing).

initialize params. When elicitation? the client advertises the elicitation capability so servers may elicit (§2 elicitation bridge); without a waitFor the capability is not advertised and a compliant server will not elicit.

Reply to an inbound ping.

The MCP protocol version this client advertises.

Functions

answer_to_elicit_result(answer)

Map a resolved §10 Answer back onto an MCP elicit result: ok → accept (with answer.data as content); reason=="declined" → decline; everything else → cancel.

classify(msg)

Classify a decoded inbound message: {:request, id, method, params} (server→client request, e.g. ping/elicitation), {:response, id, {:ok, result} | {:error, error}}, {:notification, method, params}, or :unknown. Unknown notifications are tolerated silently by the caller.

client_version()

clientInfo version — the toolnexus app version from mix.

elicitation_to_request(params)

Map an MCP elicitation/create request onto a §10 Request: form mode → kind:"input" (with requestedSchema carried in data.schema); URL mode (mode == "url") → kind:"authorization" with url.

encode_line(msg)

Encode a message as one newline-delimited JSON line (stdio framing).

error_response(id, code, message)

initialize_params(elicitation?)

initialize params. When elicitation? the client advertises the elicitation capability so servers may elicit (§2 elicitation bridge); without a waitFor the capability is not advertised and a compliant server will not elicit.

initialized_notification()

notification(method, params \\ nil)

ping_response(id)

Reply to an inbound ping.

protocol_version()

The MCP protocol version this client advertises.

request(id, method, params \\ nil)

response(id, result)

tools_call_request(id, name, args)

tools_list_request(id, cursor)