ExMCP.Client.StateMachine (ex_mcp v0.9.2)

View Source

GenStateMachine implementation for ExMCP.Client.

This module formalizes the client's state transitions and reduces complexity by using state-specific data structures instead of a single monolithic state.

States

  • :disconnected - No active connection
  • :connecting - Transport connection being established
  • :handshaking - MCP protocol handshake in progress
  • :ready - Connected and ready to handle requests
  • :reconnecting - Connection lost, attempting to reconnect

State Transitions

disconnected -> connecting -> handshaking -> ready
      ^                                        |
      |                                        |
      +---------- reconnecting <---------------+

Summary

Functions

Returns a specification to start this module under a supervisor.

Initiates connection to the MCP server.

Disconnects from the MCP server.

Gets the internal state of the client (for adapter use).

Gets the current state of the client.

Sends a request to the MCP server.

Starts a new client state machine.

Types

state_name()

@type state_name() ::
  :disconnected | :connecting | :handshaking | :ready | :reconnecting

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

connect(client)

Initiates connection to the MCP server.

disconnect(client)

Disconnects from the MCP server.

get_internal_state(client)

Gets the internal state of the client (for adapter use).

get_state(client)

Gets the current state of the client.

request(client, method, params, opts \\ [])

Sends a request to the MCP server.

start_link(config, opts \\ [])

Starts a new client state machine.