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.
def deps do
[
{:phantom_mcp, "~> 0.9.0"}
]
endDefine 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
endForward 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
endAnd 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.
Start with Getting Started, which covers
Plug.Router and stdio too.
- Tools, Prompts, and Resources
- Authentication
- Elicitation
- Testing
- Deployment: load balancers, clustering, caching, and tracing
- Protocol Support
Extensions:
And A2A agents.
MIT License.