MCP.Client behaviour (fnord v0.9.37)

View Source

Facade for the Hermes MCP client runtime: the VM-global MCP.Supervisor and the per-server Hermes client GenServers it supervises.

Every Hermes touch point in fnord routes through this module so tests can substitute a Mox double (Fnord.TestCase.mock_mcp_client/0) instead of booting real server transports. The real implementation lives in MCP.Client.Default.

Callbacks are keyed by server name (the key in Settings.MCP config), not by client pid or atom - resolving the registered process for a server is an implementation detail of the runtime.

Summary

Callbacks

Invokes a tool on a connected server, returning the unwrapped result.

True when the server's client process is registered and alive.

Fetches the capabilities map negotiated with a connected server.

Lists the tools advertised by a connected server.

Starts the MCP supervisor (idempotent) and detaches it from the caller. The Hermes stack is VM-global and must outlive the process that happened to trigger it; see MCP.Client.Default for the unlink rationale.

Callbacks

call_tool(server, tool, args, opts)

@callback call_tool(
  server :: String.t(),
  tool :: String.t(),
  args :: map(),
  opts :: keyword()
) ::
  {:ok, term()} | {:error, term()}

Invokes a tool on a connected server, returning the unwrapped result.

connected?(server)

@callback connected?(server :: String.t()) :: boolean()

True when the server's client process is registered and alive.

get_server_capabilities(server)

@callback get_server_capabilities(server :: String.t()) :: {:ok, map()} | {:error, term()}

Fetches the capabilities map negotiated with a connected server.

list_tools(server)

@callback list_tools(server :: String.t()) :: {:ok, [map()]} | {:error, term()}

Lists the tools advertised by a connected server.

start_supervisor()

@callback start_supervisor() :: :ok | {:error, term()}

Starts the MCP supervisor (idempotent) and detaches it from the caller. The Hermes stack is VM-global and must outlive the process that happened to trigger it; see MCP.Client.Default for the unlink rationale.

Functions

call_tool(server, tool, args, opts)

@spec call_tool(String.t(), String.t(), map(), keyword()) ::
  {:ok, term()} | {:error, term()}

connected?(server)

@spec connected?(String.t()) :: boolean()

get_server_capabilities(server)

@spec get_server_capabilities(String.t()) :: {:ok, map()} | {:error, term()}

impl()

list_tools(server)

@spec list_tools(String.t()) :: {:ok, [map()]} | {:error, term()}

start_supervisor()

@spec start_supervisor() :: :ok | {:error, term()}