ExMCP.Client.Adapter behaviour (ex_mcp v0.9.2)

View Source

Behaviour for client adapters.

This behaviour defines the interface that all client implementations must satisfy. It allows for different backends (GenServer-based, StateMachine-based, etc.) while maintaining a consistent API.

Summary

Types

batch_request()

@type batch_request() :: %{method: String.t(), params: map()}

client()

@type client() :: term()

error()

@type error() :: {:error, term()}

request_opts()

@type request_opts() :: keyword()

Callbacks

batch_request(client, requests, opts)

@callback batch_request(client(), requests :: [batch_request()], opts :: request_opts()) ::
  {:ok, [term()]} | error()

call(client, method, params, opts)

@callback call(client(), method :: String.t(), params :: map(), opts :: request_opts()) ::
  {:ok, term()} | error()

call_tool(client, name, arguments, opts)

@callback call_tool(
  client(),
  name :: String.t(),
  arguments :: map(),
  opts :: request_opts()
) ::
  {:ok, term()} | error()

complete(client, request, token)

@callback complete(client(), request :: map(), token :: String.t()) ::
  {:ok, term()} | error()

connect(client)

@callback connect(client()) :: :ok | error()

disconnect(client)

@callback disconnect(client()) :: :ok | error()

find_matching_tool(client, pattern)

@callback find_matching_tool(client(), pattern :: String.t() | Regex.t()) ::
  {:ok, [map()]} | error()

find_tool(client, name)

@callback find_tool(client(), name :: String.t()) :: {:ok, map()} | {:error, :not_found}

get_pending_requests(client)

@callback get_pending_requests(client()) :: map()

get_prompt(client, name, arguments, opts)

@callback get_prompt(
  client(),
  name :: String.t(),
  arguments :: map(),
  opts :: request_opts()
) ::
  {:ok, map()} | error()

get_status(client)

@callback get_status(client()) :: map()

list_prompts(client, opts)

@callback list_prompts(client(), opts :: request_opts()) :: {:ok, map()} | error()

list_resource_templates(client, opts)

@callback list_resource_templates(client(), opts :: request_opts()) ::
  {:ok, map()} | error()

list_resources(client, opts)

@callback list_resources(client(), opts :: request_opts()) :: {:ok, map()} | error()

list_roots(client, opts)

@callback list_roots(client(), opts :: request_opts()) :: {:ok, map()} | error()

list_tools(client, opts)

@callback list_tools(client(), opts :: request_opts()) :: {:ok, map()} | error()

log_message(client, level, message, data, opts)

@callback log_message(
  client(),
  level :: String.t(),
  message :: String.t(),
  data :: map() | nil,
  opts :: request_opts()
) :: :ok | error()

make_request(client, method, params, opts)

@callback make_request(
  client(),
  method :: String.t(),
  params :: map(),
  opts :: request_opts()
) ::
  {:ok, term()} | error()

negotiated_version(client)

@callback negotiated_version(client()) :: String.t() | nil

notify(client, method, params)

@callback notify(client(), method :: String.t(), params :: map()) :: :ok | error()

ping(client, opts)

@callback ping(client(), opts :: request_opts()) :: {:ok, map()} | error()

read_resource(client, uri, opts)

@callback read_resource(client(), uri :: String.t(), opts :: request_opts()) ::
  {:ok, term()} | error()

send_batch(client, requests)

@callback send_batch(client(), requests :: [batch_request()]) :: {:ok, [term()]} | error()

send_cancelled(client, request_id)

@callback send_cancelled(client(), request_id :: term()) :: :ok

server_capabilities(client)

@callback server_capabilities(client()) :: map()

server_info(client)

@callback server_info(client()) :: map() | nil

set_log_level(client, level, opts)

@callback set_log_level(client(), level :: String.t(), opts :: request_opts()) ::
  {:ok, map()} | error()

start_link(config, opts)

@callback start_link(config :: map(), opts :: keyword()) :: {:ok, client()} | error()

stop(client)

@callback stop(client()) :: :ok

subscribe_resource(client, uri, opts)

@callback subscribe_resource(client(), uri :: String.t(), opts :: request_opts()) ::
  {:ok, map()} | error()

tools(client)

@callback tools(client()) :: {:ok, [map()]} | error()

unsubscribe_resource(client, uri, opts)

@callback unsubscribe_resource(client(), uri :: String.t(), opts :: request_opts()) ::
  {:ok, map()} | error()