mcp_client/manager

MCP Manager — manages multiple MCP server connections.

Provides unified tool, resource, and prompt discovery and execution across multiple MCP servers. Each server is configured with a command and args; the manager handles lifecycle, discovery, and routing via JSON-RPC 2.0 over STDIO.

Usage

let assert Ok(mgr) = manager.start()
let config = manager.ServerConfig(name: "fs", command: "npx", args: [...], env: [], retry: manager.NoRetry)
manager.register(mgr, config)

Types

Messages for the manager actor.

pub type ManagerMessage {
  RegisterServer(
    reply_to: process.Subject(Result(Nil, String)),
    config: ServerConfig,
  )
  UnregisterServer(
    reply_to: process.Subject(Result(Nil, String)),
    name: String,
  )
  ListServers(reply_to: process.Subject(List(String)))
  GetServerConfig(
    reply_to: process.Subject(Result(ServerConfig, String)),
    name: String,
  )
  ListTools(reply_to: process.Subject(List(Tool)))
  ExecuteTool(
    reply_to: process.Subject(Result(String, String)),
    tool_name: String,
    args: String,
  )
  ListResources(reply_to: process.Subject(List(Resource)))
  ReadResource(
    reply_to: process.Subject(Result(String, String)),
    server_name: String,
    uri: String,
  )
  ListPrompts(reply_to: process.Subject(List(Prompt)))
  GetPrompt(
    reply_to: process.Subject(Result(String, String)),
    server_name: String,
    name: String,
    args: dict.Dict(String, String),
  )
  Stop(reply_to: process.Subject(Nil))
}

Constructors

The manager handle.

pub type McpManager =
  process.Subject(ManagerMessage)

A discovered prompt template from an MCP server.

pub type Prompt {
  Prompt(
    name: String,
    description: String,
    server_name: String,
    arguments: List(PromptArg),
  )
}

Constructors

  • Prompt(
      name: String,
      description: String,
      server_name: String,
      arguments: List(PromptArg),
    )

    Arguments

    name

    Prompt name.

    description

    Human-readable description.

    server_name

    Which server provides this prompt.

    arguments

    Argument definitions.

An argument definition for an MCP prompt.

pub type PromptArg {
  PromptArg(name: String, description: String, required: Bool)
}

Constructors

  • PromptArg(name: String, description: String, required: Bool)

A discovered resource from an MCP server.

pub type Resource {
  Resource(
    uri: String,
    name: String,
    description: String,
    server_name: String,
  )
}

Constructors

  • Resource(
      uri: String,
      name: String,
      description: String,
      server_name: String,
    )

    Arguments

    uri

    Resource URI (e.g. “file:///path/to/file”).

    name

    Human-readable name.

    description

    Human-readable description.

    server_name

    Which server provides this resource.

Retry policy applied when a server process crashes.

pub type RetryPolicy {
  NoRetry
  Retry(max_attempts: Int, base_delay_ms: Int)
}

Constructors

  • NoRetry

    Remove the server from state immediately on crash.

  • Retry(max_attempts: Int, base_delay_ms: Int)

    Retry up to max_attempts times with exponential backoff starting at base_delay_ms milliseconds.

Configuration for an MCP server connection.

pub type ServerConfig {
  ServerConfig(
    name: String,
    command: String,
    args: List(String),
    env: List(#(String, String)),
    retry: RetryPolicy,
  )
}

Constructors

  • ServerConfig(
      name: String,
      command: String,
      args: List(String),
      env: List(#(String, String)),
      retry: RetryPolicy,
    )

    Arguments

    name

    Unique name for this server.

    command

    Command to execute (e.g. “npx”, “node”, “python3”).

    args

    Command arguments.

    env

    Environment variables.

    retry

    What to do if the server process crashes.

A discovered tool from an MCP server.

pub type Tool {
  Tool(
    spec: ToolSpec,
    server_name: String,
    original_name: String,
  )
}

Constructors

  • Tool(spec: ToolSpec, server_name: String, original_name: String)

    Arguments

    spec

    Qualified name: “server_name/tool_name”.

    server_name

    Which server provides this tool.

    original_name

    Original tool name as declared by the MCP server.

Minimal tool specification (name + description).

pub type ToolSpec {
  ToolSpec(name: String, description: String)
}

Constructors

  • ToolSpec(name: String, description: String)

Values

pub fn execute_tool(
  manager: process.Subject(ManagerMessage),
  tool_name: String,
  args: String,
) -> Result(String, String)

Execute a tool by qualified name ("server/tool") with JSON arguments.

pub fn get_prompt(
  manager: process.Subject(ManagerMessage),
  server_name: String,
  name: String,
  args: dict.Dict(String, String),
) -> Result(String, String)

Get a rendered prompt by name from a named server. Returns the raw JSON result.

pub fn get_server(
  manager: process.Subject(ManagerMessage),
  name: String,
) -> Result(ServerConfig, String)

Get a server’s configuration by name.

pub fn list_prompts(
  manager: process.Subject(ManagerMessage),
) -> List(Prompt)

List all prompts discovered across all servers.

pub fn list_resources(
  manager: process.Subject(ManagerMessage),
) -> List(Resource)

List all resources discovered across all servers.

pub fn list_servers(
  manager: process.Subject(ManagerMessage),
) -> List(String)

List all registered server names.

pub fn list_tools(
  manager: process.Subject(ManagerMessage),
) -> List(Tool)

List all discovered tools across all servers.

pub fn read_resource(
  manager: process.Subject(ManagerMessage),
  server_name: String,
  uri: String,
) -> Result(String, String)

Read a resource by URI from a named server. Returns the raw JSON result.

pub fn register(
  manager: process.Subject(ManagerMessage),
  config: ServerConfig,
) -> Result(Nil, String)

Register an MCP server. Starts the process, performs the MCP initialize handshake, and discovers all tools, resources, and prompts.

pub fn start() -> Result(
  process.Subject(ManagerMessage),
  actor.StartError,
)

Start a new MCP manager.

pub fn stop(manager: process.Subject(ManagerMessage)) -> Nil

Stop the manager and all server connections.

pub fn unregister(
  manager: process.Subject(ManagerMessage),
  name: String,
) -> Result(Nil, String)

Unregister an MCP server and stop its process.

Search Document