ExMCP.MessageProcessor behaviour (ex_mcp v0.9.2)

View Source

Core message processing abstraction for ExMCP.

The MessageProcessor provides a simple, composable interface for processing MCP messages. It follows the Plug specification pattern used throughout the Elixir ecosystem.

Summary

Callbacks

Callback for processing the connection.

Callback for initializing the plug with options.

Functions

Assigns a value to the connection.

Completes progress tracking for a connection.

Halts the plug pipeline.

Creates a new connection.

Process an MCP request using a handler module.

Sets the response on the connection.

Runs a list of plugs on the connection.

Starts progress tracking for a connection if it has a progress token.

Updates progress for a connection.

Types

conn()

@type conn() :: %ExMCP.MessageProcessor.Conn{
  assigns: term(),
  halted: term(),
  progress_token: term(),
  request: term(),
  response: term(),
  session_id: term(),
  state: term(),
  transport: term()
}

opts()

@type opts() :: term()

t()

@type t() :: module()

Callbacks

call(conn, opts)

@callback call(conn(), opts()) :: conn()

Callback for processing the connection.

init(opts)

@callback init(opts()) :: opts()

Callback for initializing the plug with options.

Functions

assign(conn, key, value)

Assigns a value to the connection.

complete_progress(conn)

Completes progress tracking for a connection.

This should be called when a long-running operation finishes, either successfully or with an error.

halt(conn)

Halts the plug pipeline.

new(request, opts \\ [])

@spec new(
  map(),
  keyword()
) :: ExMCP.MessageProcessor.Conn.t()

Creates a new connection.

process(conn, opts)

Process an MCP request using a handler module.

This is a convenience function that creates a connection, processes it through a handler, and returns the response.

put_response(conn, response)

Sets the response on the connection.

run(plugs, conn)

Runs a list of plugs on the connection.

start_progress_tracking(conn)

@spec start_progress_tracking(ExMCP.MessageProcessor.Conn.t()) ::
  ExMCP.MessageProcessor.Conn.t()

Starts progress tracking for a connection if it has a progress token.

This should be called at the beginning of long-running operations.

update_progress(conn, progress, total, message)

@spec update_progress(
  ExMCP.MessageProcessor.Conn.t(),
  number(),
  number() | nil,
  String.t() | nil
) ::
  ExMCP.MessageProcessor.Conn.t()

Updates progress for a connection.

This is a helper function to send progress notifications during long-running operations.