ExMCP.MessageProcessor.Migration (ex_mcp v0.10.0)

View Source

Migration module to transition MessageProcessor to use the unified dispatcher.

This module provides a facade that maintains backward compatibility while internally using the new Dispatcher and Handlers modules. This allows for a gradual migration without breaking existing code.

Summary

Functions

Replaces the three dispatch maps with a single unified dispatcher call.

Helper to create backward-compatible error response format.

Converts old dispatch map calls to use the unified dispatcher.

Helper to create backward-compatible response format.

Functions

dispatch_request(conn, handler, mode, method, params, id, server_info \\ %{})

Replaces the three dispatch maps with a single unified dispatcher call.

This function can be used as a drop-in replacement for the existing dispatch map lookups in MessageProcessor.

error_response(message, data, id)

Helper to create backward-compatible error response format.

migrate_dispatch_calls()

Converts old dispatch map calls to use the unified dispatcher.

Old pattern:

case Map.get(handler_method_dispatch(), method) do
  nil -> handle_handler_custom_method(conn, server_pid, method, params, id)
  handler_fun -> handler_fun.(conn, server_pid, params, id)
end

New pattern:

Migration.dispatch_request(conn, server_pid, :handler, method, params, id)

success_response(result, id)

Helper to create backward-compatible response format.