A behaviour describing extensions to the GenMCP.Suite server.
Extensions allow modular addition of tools, resources, and prompts to the
suite. They are configured via the :extensions option when plugging
GenMCP.Transport.StreamableHTTP.
Lifecycle
Extensions are invoked during server initialization to gather the initial list of capabilities.
The order of invocation follows the order in the :extensions list. However,
tools, resources, and prompts defined directly on the configuration (via
:tools, :resources, :prompts options) are always treated as the first
extension, taking precedence in the listing order.
Channel Access
Extension callbacks receive the GenMCP.Mux.Channel from the initialization
HTTP request.
This allows extensions to filter or dynamically generate capabilities based on request context (e.g., user authorization).
Future implementations to support listChanged notifications will pass the
channel from the current GET HTTP request streaming server notifications.
Example
defmodule MyExtension do
@behaviour GenMCP.Suite.Extension
@impl true
def tools(channel, _arg) do
if channel.assigns.admin do
[AdminTool]
else
[]
end
end
@impl true
def resources(_channel, _arg), do: [MyResourceRepo]
@impl true
def prompts(_channel, _arg), do: []
end
# In Router
plug GenMCP.Transport.StreamableHTTP,
extensions: [{MyExtension, []}]
Summary
Callbacks
Returns a list of prompt repositories to be added to the suite.
Returns a list of resource repositories to be added to the suite.
Returns a list of tools to be added to the suite.
Functions
Returns a descriptor for the given module or {module, arg} tuple.
Types
Callbacks
@callback prompts(GenMCP.Mux.Channel.t(), arg()) :: [ GenMCP.Suite.PromptRepo.prompt_repo() ]
Returns a list of prompt repositories to be added to the suite.
Examples
def prompts(_channel, _arg), do: [MyPromptRepo]
@callback resources(GenMCP.Mux.Channel.t(), arg()) :: [ GenMCP.Suite.ResourceRepo.resource_repo() ]
Returns a list of resource repositories to be added to the suite.
Examples
def resources(_channel, _arg), do: [MyResourceRepo]
@callback tools(GenMCP.Mux.Channel.t(), arg()) :: [GenMCP.Suite.Tool.tool()]
Returns a list of tools to be added to the suite.
Examples
def tools(_channel, _arg), do: [MyTool, {AnotherTool, [opt: :val]}]
Functions
@spec expand(extension()) :: extension_descriptor()
Returns a descriptor for the given module or {module, arg} tuple.