Sake.Client (Sake v0.1.0)

Copy Markdown View Source

A client for MCP servers over Streamable HTTP, on both protocol eras.

{:ok, session} = Sake.Client.connect("https://mcp.example.com/mcp", headers: [{"authorization", "Bearer ..."}])
{:ok, tools, session} = Sake.Client.list_tools(session)
{:ok, result, session} = Sake.Client.call_tool(session, "search", %{"query" => "x"})

The client is functional: every call returns the updated session. Pass on_input: to answer elicitation requests; a 401 comes back as {:error, {:unauthorized, %Sake.Client.Challenge{}}}.

Summary

Functions

call_tool(session, name, arguments)

close(session)

@spec close(Sake.Client.Session.t()) :: :ok

complete(session, ref, argument, value)

@spec complete(
  Sake.Client.Session.t(),
  {:prompt, String.t()} | {:resource, String.t()},
  String.t(),
  String.t()
) ::
  {:ok, map(), Sake.Client.Session.t()}
  | {:error, term(), Sake.Client.Session.t()}

connect(url, opts \\ [])

@spec connect(String.t(), keyword()) ::
  {:ok, Sake.Client.Session.t()} | {:error, term()}

discover(session)

@spec discover(Sake.Client.Session.t()) ::
  {:ok, map(), Sake.Client.Session.t()}
  | {:error, term(), Sake.Client.Session.t()}

get_prompt(session, name, arguments)

@spec get_prompt(Sake.Client.Session.t(), String.t(), map()) ::
  {:ok, map(), Sake.Client.Session.t()}
  | {:error, term(), Sake.Client.Session.t()}

list_prompts(session)

@spec list_prompts(Sake.Client.Session.t()) ::
  {:ok, [map()], Sake.Client.Session.t()}
  | {:error, term(), Sake.Client.Session.t()}

list_resource_templates(session)

@spec list_resource_templates(Sake.Client.Session.t()) ::
  {:ok, [map()], Sake.Client.Session.t()}
  | {:error, term(), Sake.Client.Session.t()}

list_resources(session)

@spec list_resources(Sake.Client.Session.t()) ::
  {:ok, [map()], Sake.Client.Session.t()}
  | {:error, term(), Sake.Client.Session.t()}

list_tools(session)

@spec list_tools(Sake.Client.Session.t()) ::
  {:ok, [Sake.Tool.Spec.t()], Sake.Client.Session.t()}
  | {:error, term(), Sake.Client.Session.t()}

ping(session)

@spec ping(Sake.Client.Session.t()) ::
  {:ok, Sake.Client.Session.t()} | {:error, term(), Sake.Client.Session.t()}

read_resource(session, uri)

@spec read_resource(Sake.Client.Session.t(), String.t()) ::
  {:ok, [Sake.Content.t()], Sake.Client.Session.t()}
  | {:error, term(), Sake.Client.Session.t()}