ExMCP.Server.HandlerBridge (ex_mcp v1.0.0-rc.8)

Copy Markdown View Source

Normalizes ExMCP.Server.Handler callback returns into canonical GenServer.handle_call/3 replies.

use ExMCP.Server.Handler injects a thin handle_call/3 clause per MCP message that delegates here. Handler authors may answer with any of the historical shapes ({:ok, result, state}, {:ok, result}, {:ok, state}, {:error, reason, state}, {:error, reason}); this module collapses them so callers such as the HTTP message processor see exactly one shape and handler state never leaks into a reply (audit M13):

  • {:ok, result} for single-result calls
  • {:ok, entries, next_cursor} for paginated list calls
  • {:error, reason} for failures

Keeping the bodies here also keeps the generated __using__ block small and makes the bridge directly testable.

Summary

Functions

Invokes a callback whose success carries no meaningful result (subscriptions, log level), replying {:ok, result_or_empty_map}.

Invokes a callback that answers with a single result.

Invokes a paginated list callback, replying {:ok, entries, next_cursor}.

Types

reply()

@type reply() :: {:reply, term(), state()}

state()

@type state() :: term()

Functions

ack(module, fun, args, state)

@spec ack(module(), atom(), [term()], state()) :: reply()

Invokes a callback whose success carries no meaningful result (subscriptions, log level), replying {:ok, result_or_empty_map}.

call(module, fun, args, state)

@spec call(module(), atom(), [term()], state()) :: reply()

Invokes a callback that answers with a single result.

list(module, fun, args, state)

@spec list(module(), atom(), [term()], state()) :: reply()

Invokes a paginated list callback, replying {:ok, entries, next_cursor}.