AshAi.Mcp.Client.Server (ash_ai v1.5.6)

Copy Markdown View Source

Configuration for an MCP server reached over Streamable HTTP.

Build one with new/1 (or AshAi.Mcp.Client.server/1) and pass it to AshAi.Mcp.Client.connect/1. The struct holds no connection state, so it is safe to build from stored configuration in each job or request.

Summary

Functions

Builds a server configuration.

Types

t()

@type t() :: %AshAi.Mcp.Client.Server{
  allowed_private_hosts: [String.t()] | :all,
  auth: {module(), keyword()} | nil,
  capabilities: map(),
  client_info: map() | nil,
  headers: [{String.t(), String.t()}] | (-> [{String.t(), String.t()}]),
  max_response_size: pos_integer(),
  name: String.t(),
  protocol_version: String.t() | nil,
  req_options: keyword(),
  request_timeout: pos_integer(),
  url: String.t()
}

Functions

new(opts)

@spec new(keyword()) :: t()

Builds a server configuration.

Options

  • :name - Required. A name for the server, unique among the servers a conversation uses: up to 32 letters and digits in runs joined by single - or _. It prefixes the server's tool names (mcp__<name>__<tool>), so changing it changes every tool name. The format keeps one server's tool names from colliding with another's.

  • :url (String.t/0) - Required. The server's MCP endpoint, e.g. https://example.com/mcp.

  • :allowed_private_hosts - Hosts that may resolve to loopback, private, or other non-public addresses, such as ["localhost"] in development or an internal MCP server's hostname. The client connects to any other host only at public addresses, so a URL a user supplies can't reach services on your network. :all turns the check off. A proxy, a named finch: pool, or a custom adapter: in req_options takes the connection out of the check's reach, so they require :all, for example with an egress proxy that enforces it. The default value is [].

  • :request_timeout (pos_integer/0) - Milliseconds a request may take in all, including a streamed response. The default value is 60000.

  • :max_response_size (pos_integer/0) - The most bytes a response may carry, including a streamed one. The default value is 8388608.

  • :auth - {module, opts}, where module implements AshAi.Mcp.Client.Auth, such as {AshAi.Mcp.OAuth, store: MyApp.McpTokens, owner: user.id}. The default value is nil.

  • :headers - Static headers sent with every request, such as an API key. A zero-arity function is called before each request. The default value is [].

  • :req_options (keyword/0) - Options merged into Req.new/1, e.g. plug: in tests or receive_timeout:. The default value is [].

  • :client_info (map of String.t/0 keys and term/0 values) - The Implementation sent as clientInfo. Defaults to %{"name" => "ash_ai", "version" => <AshAi's version>}.

  • :capabilities (map of String.t/0 keys and term/0 values) - The client capabilities to declare. The client implements none beyond the core. The default value is %{}.

  • :protocol_version - Skip version detection and use this protocol version. Set it from a previously negotiated AshAi.Mcp.Client.Connection.protocol_version to save the probe request. The default value is nil.