Packages

MCP server exposing live Elixir runtime introspection tools to AI agents.

Current section

Files

Jump to
extools lib extools.ex
Raw

lib/extools.ex

if Code.ensure_loaded?(Plug.Conn) do
defmodule Extools do
@moduledoc """
MCP server exposing live Elixir runtime introspection tools to AI agents.
## Dual mode
**Phoenix** — add one line to your endpoint (dev only):
# lib/my_app_web/endpoint.ex
if Mix.env() == :dev do
plug Extools
end
The MCP endpoint is served at `http://localhost:4000/extools/mcp`.
Requests to any other path pass through untouched.
**Non-Phoenix** — configure a port and the application starts a
standalone Bandit server (requires `{:bandit, "~> 1.0"}` in deps):
# config/dev.exs
config :extools, port: 4040
The MCP endpoint is served at `http://localhost:4040/extools/mcp`.
"""
@behaviour Plug
alias Hermes.Server.Transport.StreamableHTTP.Plug, as: MCPPlug
@mcp_path "/extools/mcp"
@impl Plug
def init(opts) do
MCPPlug.init(Keyword.merge([server: Extools.MCPServer], opts))
end
@impl Plug
def call(%Plug.Conn{request_path: path} = conn, mcp_opts) do
if path == @mcp_path or String.starts_with?(path, @mcp_path <> "/") do
MCPPlug.call(conn, mcp_opts)
else
conn
end
end
end
else
defmodule Extools do
@moduledoc """
Stub module — `Plug` is not available in this project.
To use the Extools HTTP endpoint, add a Plug-providing dependency:
* Phoenix apps already have one (via `phoenix`).
* Non-Phoenix apps: add `{:bandit, "~> 1.0", only: :dev}` and set
`config :extools, port: 4040`.
"""
end
end