Handles incoming MCP requests over HTTP with SSE support.
This module is a Plug that can be mounted in your router. It handles the MCP protocol handshake, session management, and request routing.
It supports Server-Sent Events (SSE) for streaming responses, such as notifications and asynchronous tool results.
Configuration
Options for the HTTP connection
:assigns(map/0) - A map of assigns to define to the channel passed to tools, resources, etc. The default value is%{}.:copy_assigns(list ofatom/0) - A list of assigns keys that will be copied from the conn to the channel. Those will overwrite the assigns from the:assignsoption above. The default value is[].
Options for the MCP OTP session wrapper
Note that the :session_controller is managed directly by the GenMCP
behaviour implementation.
:server- TheGenMCPbehaviour server implemetation that will handle MCP messages. If a simple atom, it will receive all other options given to the session. The default value isGenMCP.Suite.:session_timeout(integer/0) - Session will automatically terminate when not receiving any request or notification for that number of milliseconds. The default value is120000.
Options for the GenMCP behaviour implmentation
All other options given to GenMCP.Transport.StreamableHTTP will be forwarded to the
server implementation.
The default server, GenMCP.Suite, will accept the following options:
:server_name(String.t/0) - Required.:server_version(String.t/0) - Required.:server_title(String.t/0):tools- The list ofGenMCP.Suite.Toolimplementations that will be available in the server. List items can be either module names,{module, arg}tuples or a descriptor map. The default value is[].:resources- The list ofGenMCP.Suite.ResourceRepoimplementations to serve resources from. List items can be either module names,{module, arg}tuples or a descriptor map. The default value is[].:prompts- A list ofGenMCP.Suite.PromptRepoimplementations to generate prompts with. List items can be either module names,{module, arg}tuples or a descriptor map. The default value is[].:extensions- A listGenMCP.Suite.Extensionimplementations to add more tools, resource repositories and prompt repositories. List items can be either module names,{module, arg}tuples or a descriptor map. The default value is[].
Example
# In your router
forward "/mcp", GenMCP.Transport.StreamableHTTP,
server_name: "My App",
server_version: "1.0.0",
tools: [MyTool]
Summary
Functions
Callback implementation for Plug.call/2.
Defines a module that delegates to GenMCP.Transport.StreamableHTTP.
Callback implementation for Plug.init/1.
Functions
Callback implementation for Plug.call/2.
Defines a module that delegates to GenMCP.Transport.StreamableHTTP.
This is useful if you want to define a named Plug for your MCP server.
Example
defmodule MyMCPPlug do
require GenMCP.Transport.StreamableHTTP
GenMCP.Transport.StreamableHTTP.defplug(MyMCPPlug)
end
Callback implementation for Plug.init/1.