ExMCP.MessageProcessor.Dispatcher (ex_mcp v0.10.0)

View Source

Unified message dispatcher that eliminates duplication between different handler modes.

This module provides a single dispatch mechanism that can handle:

  • Direct handler calls (DSL servers)
  • GenServer-based handlers
  • Handler module calls

All business logic is delegated to the Handlers module, while this module handles routing and response adaptation based on the calling mode.

Summary

Functions

Dispatches a request to the appropriate handler based on the method and mode.

Extracts the request ID from a request map.

Types

conn()

@type conn() :: ExMCP.MessageProcessor.Conn.t()

mode()

@type mode() :: :direct | :genserver | :handler

Functions

dispatch(conn, handler, mode, server_info \\ %{})

@spec dispatch(conn(), module() | pid(), mode(), map()) :: conn()

Dispatches a request to the appropriate handler based on the method and mode.

Parameters

  • conn - The connection struct containing the request
  • handler - The handler module or server PID
  • mode - The dispatch mode (:direct, :genserver, or :handler)
  • server_info - Optional server information

Returns

Returns an updated connection struct with the response set.

get_request_id(request)

@spec get_request_id(map()) :: any()

Extracts the request ID from a request map.