Installation

Add the library to your dependencies and you will be good to go.

def deps do
  [
    {:gen_mcp, "~> 0.10"},
  ]
end

For advanced setups, the System Configuration guide contains more information to integrate the library in your system.

Quick Start

This guide covers high level usage of the library with the default MCP server implementation: GenMCP.Suite with the Streamable HTTP transport implemented by the GenMCP.Transport.StreamableHTTP plug.

Define a Test Tool

To validate your installation, you will need a valid tool, otherwise there will be nothing much to test.

You can copy the following tool as an example:

defmodule MyApp.Tools.Addition do
  use GenMCP.Suite.Tool,
    name: "Addition",
    description: "Adds two numbers",
    input_schema: %{
      type: "object",
      properties: %{
        a: %{type: "number"},
        b: %{type: "number"}
      },
      required: ["a", "b"]
    }

  @impl true
  def call(req, channel, _arg) do
    %{"a" => a, "b" => b} = req.params.arguments
    result = GenMCP.MCP.call_tool_result(text: "#{a + b}")
    {:result, result, channel}
  end
end

Mount the Server in your Router

Add the GenMCP.Transport.StreamableHTTP plug to your Phoenix or Plug router. You configure the server details and register your tools here.

defmodule MyAppWeb.Router do
  use MyAppWeb, :router

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

  scope "/mcp" do
    pipe_through :mcp

    forward "/", GenMCP.Transport.StreamableHTTP,
      server_name: "My Addition Server",
      server_version: "1.0.0",
      tools: [MyApp.Tools.Addition]
  end
end

Your MCP server is now available at /mcp!

Next Steps