FastestMCP.Lifespan (fastest_mcp v0.1.2)

Copy Markdown View Source

Small server lifespan helper for startup and shutdown state.

A lifespan can be registered as:

  • a one-arity function receiving the server and returning a map, {:ok, map}, {map, cleanup}, or {:ok, map, cleanup}
  • an explicit {enter_fun, exit_fun} pair

Startup results are merged in declaration order, with later lifespans winning on key conflicts. Cleanup runs in reverse order.

Summary

Functions

Runs the collected cleanup callbacks.

Builds a new value for this module from the supplied options.

Runs all configured lifespan enter hooks and collects cleanup callbacks.

Types

cleanup()

@type cleanup() :: (-> any()) | (map() -> any())

enter()

@type enter() :: (FastestMCP.Server.t() ->
              map()
              | {:ok, map()}
              | {map(), cleanup()}
              | {:ok, map(), cleanup()})

exit()

@type exit() ::
  nil | (-> any()) | (map() -> any()) | (FastestMCP.Server.t(), map() -> any())

t()

@type t() :: %FastestMCP.Lifespan{enter: enter(), exit: exit()}

Functions

cleanup_all(cleanups)

Runs the collected cleanup callbacks.

new(lifespan)

Builds a new value for this module from the supplied options.

new(enter, exit)

run_all(server, lifespans)

Runs all configured lifespan enter hooks and collects cleanup callbacks.