Installation
Add the library to your dependencies and you will be good to go.
def deps do
[
{:gen_mcp, "~> 0.9"},
]
endFor 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
endMount 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
endYour MCP server is now available at /mcp!
Next Steps
- Explore
GenMCP.Suiteto get a better understanding of its capabilities. - Explore
GenMCP.Suite.Toolto learn more about building tools, including asynchronous ones. - Check out
GenMCP.Suite.ResourceRepoto expose data as resources. - Use
GenMCP.Suite.PromptRepoto provide reusable prompts. - Learn about
GenMCP.Suite.Extensionto compose functionality from multiple modules.