Skip to content

Multiple client instances #7

@hubertpompecki

Description

@hubertpompecki

It seems it's not possible to start more than one instance of a given client, trying to follow the docs results in an error, here's a minimum example:

Mix.install([{:anubis_mcp, "~> 0.13.1"}])

defmodule Test.MCPClient do
  use Anubis.Client,
    name: "Test",
    version: "1.0.0",
    protocol_version: "2025-03-26",
    capabilities: [:roots, :sampling]
end

defmodule Test.Application do
  def start() do
    children = [
      Supervisor.child_spec(
        {Test.MCPClient, name: :some_id_1, transport: {:stdio, command: "command", args: ["1"]}},
        id: :some_id_1
      ),
      Supervisor.child_spec(
        {Test.MCPClient, name: :some_id_2, transport: {:stdio, command: "command", args: ["2"]}},
        id: :some_id_2
      )
    ]

    opts = [strategy: :one_for_all, name: Astro.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

Test.Application.start()

Gives:

** (EXIT from #PID<0.94.0>) shutdown: failed to start child: :some_id_2
    ** (EXIT) shutdown: failed to start child: Anubis.Client.Base
        ** (EXIT) already started: #PID<0.205.0>

In my use case I'm trying to use a dynamic supervisor and start connections to an MCP server on behalf of many different end users (therefore passing different credentials) but here I'm using stdio for a minimal example as per docs.

Thank you for your great work on this lib.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions