table of contents
- Tumbleweed 0.100.0-1.1
- Leap-16.0
| MCP::Server::Transport::HTTP(3) | User Contributed Perl Documentation | MCP::Server::Transport::HTTP(3) |
NAME¶
MCP::Server::Transport::HTTP - HTTP transport for MCP servers
SYNOPSIS¶
use MCP::Server::Transport::HTTP; my $http = MCP::Server::Transport::HTTP->new;
DESCRIPTION¶
MCP::Server::Transport::HTTP is a transport for MCP (Model Context Protocol) server that uses HTTP as the underlying transport mechanism.
By default only "POST" requests are handled. When "streaming" is enabled, the transport additionally supports the server-to-client SSE stream ("GET") and explicit session termination ("DELETE") defined by the Streamable HTTP transport. Note that this requires per-process state and is therefore not compatible with pre-forking web servers.
ATTRIBUTES¶
MCP::Server::Transport::HTTP inherits all attributes from MCP::Server::Transport and implements the following new ones.
heartbeat¶
my $seconds = $http->heartbeat; $http = $http->heartbeat(30);
Interval in seconds at which a keep-alive comment is sent on each open server-to-client stream. Defaults to 30; set to 0 to disable. Useful when running behind reverse proxies that close idle connections. Only used when "streaming" is enabled.
session_timeout¶
my $seconds = $http->session_timeout; $http = $http->session_timeout(3600);
Idle timeout in seconds for sessions without an open server-to-client stream. Defaults to 3600; set to 0 to disable. A periodic sweep removes sessions whose last activity is older than this value, so the effective lifetime of an idle session is up to twice the configured timeout. Only used when "streaming" is enabled.
sessions¶
my $sessions = $http->sessions;
$http = $http->sessions({});
Per-process registry of active MCP::Server::Session objects, keyed by session ID. Only used when "streaming" is enabled.
streaming¶
my $bool = $http->streaming; $http = $http->streaming(1);
Enable server-to-client streaming and session lifecycle management. Defaults to false. When enabled, the transport tracks all sessions in "sessions", accepts "GET" requests to open a long-lived SSE stream the server can push notifications to, and accepts "DELETE" requests to terminate a session. Requests for unknown sessions are rejected with status 404.
METHODS¶
MCP::Server::Transport::HTTP inherits all methods from MCP::Server::Transport and implements the following new ones.
handle_request¶
$http->handle_request(Mojolicious::Controller->new);
Handles an incoming HTTP request.
notifications¶
my $bool = $http->notifications;
True when "streaming" is enabled, false otherwise.
notify¶
my $bool = $http->notify($session_id, $method);
my $bool = $http->notify($session_id, $method, {foo => 'bar'});
Send a JSON-RPC notification to the open SSE stream of a session. Returns true on success, or "undef" if the session does not exist or has no open stream. Only available when "streaming" is enabled.
notify_all¶
my $bool = $http->notify_all($method);
my $bool = $http->notify_all($method, {foo => 'bar'});
Send a JSON-RPC notification to the open SSE stream of every active session. Returns true on success, or "undef" when "streaming" is disabled.
SEE ALSO¶
MCP, <https://mojolicious.org>, <https://modelcontextprotocol.io>.
| 2026-05-07 | perl v5.42.1 |