Skip to content

About

MCP server implemented in Elixir

Resources

Stars

36 stars

Watchers

2 watching

Forks

Repository files navigation

Phantom MCP

Hex.pm Documentation

MCP (Model Context Protocol) framework for Elixir Plug.

Phantom implements the MCP server specification over Streamable HTTP and stdio. Declare tools, prompts, and resources in a router, the way a Phoenix router declares routes, and Phantom handles the protocol: sessions, SSE streams, clustering, elicitation, and the stateless 2026-07-28 core. The same router can serve A2A agents.

Installation

def deps do
  [
    {:phantom_mcp, "~> 0.9.0"}
  ]
end

Quick start

Define a router with a tool:

defmodule MyApp.MCP.Router do
  use Phantom.Router,
    name: "MyApp",
    vsn: "1.0",
    instructions: "Tools for greeting people"

  tool :greet, description: "Greet someone by name" do
    field :name, :string, required: true
  end

  def greet(%{"name" => name}, session) do
    {:reply, Phantom.Tool.text("Hello, #{name}!"), session}
  end
end

Forward a path to it from your Phoenix router:

pipeline :mcp do
  plug :accepts, ["json", "sse"]

  plug Plug.Parsers,
    parsers: [{:json, length: 1_000_000}],
    pass: ["application/json"],
    json_decoder: JSON
end

scope "/mcp" do
  pipe_through :mcp
  forward "/", Phantom.Plug, router: MyApp.MCP.Router
end

And accept SSE:

# config/config.exs
config :mime, :types, %{"text/event-stream" => ["sse"]}

Your server is now at http://localhost:4000/mcp. Try it with the MCP Inspector.

Guides

Start with Getting Started, which covers Plug.Router and stdio too.

Extensions:

And A2A agents.

License

MIT License.

About

MCP server implemented in Elixir

Resources

Stars

36 stars

Watchers

2 watching

Forks

Releases

Contributors

Languages