Claudio.MCP.Client behaviour (Claudio v0.5.0)

View Source

Behaviour for MCP client adapters.

Defines a common interface that abstracts over different Elixir MCP client libraries (hermes_mcp, ex_mcp, mcp_ex, or custom implementations).

Implementing an adapter

defmodule MyApp.MCPAdapter do
  @behaviour Claudio.MCP.Client

  @impl true
  def list_tools(client, opts \\ []) do
    # Call your MCP library and normalize the response
    {:ok, [%Claudio.MCP.Client.Tool{name: "search", ...}]}
  end

  # ... implement other callbacks
end

Normalized types

All adapters return the same normalized types regardless of the underlying library. This ensures that Claudio.MCP.ToolAdapter and Claudio.MCP.ResultMapper work consistently across implementations.

Summary

Callbacks

Execute a tool on the MCP server.

Get a prompt by name with optional arguments.

List available prompts from the MCP server.

List available resources from the MCP server.

List available tools from the MCP server.

Ping the MCP server to check connectivity.

Read a resource by URI from the MCP server.

Types

prompt()

@type prompt() :: Claudio.MCP.Client.Prompt.t()

resource()

@type resource() :: Claudio.MCP.Client.Resource.t()

tool()

@type tool() :: Claudio.MCP.Client.Tool.t()

Callbacks

call_tool(client, name, args, opts)

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

Execute a tool on the MCP server.

get_prompt(client, name, args, opts)

@callback get_prompt(
  client :: term(),
  name :: String.t(),
  args :: map(),
  opts :: keyword()
) ::
  {:ok, term()} | {:error, term()}

Get a prompt by name with optional arguments.

list_prompts(client, opts)

@callback list_prompts(client :: term(), opts :: keyword()) ::
  {:ok, [prompt()]} | {:error, term()}

List available prompts from the MCP server.

list_resources(client, opts)

@callback list_resources(client :: term(), opts :: keyword()) ::
  {:ok, [resource()]} | {:error, term()}

List available resources from the MCP server.

list_tools(client, opts)

@callback list_tools(client :: term(), opts :: keyword()) ::
  {:ok, [tool()]} | {:error, term()}

List available tools from the MCP server.

ping(client, opts)

@callback ping(client :: term(), opts :: keyword()) :: :ok | {:error, term()}

Ping the MCP server to check connectivity.

read_resource(client, uri, opts)

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

Read a resource by URI from the MCP server.