MCP::Se...t::HTTP(3)
π MCP::Server::Transport::HTTP β HTTP transport for MCP servers β¨
okay so this is the MCP::Se...t::HTTP(3) page, straight out of the User Contributed Perl Documentation folder, and it's literally the glow-up your MCP server needs to talk HTTP. stay with me bestie, it's giving very slay. π
πΈ SYNOPSIS πΈ
use MCP::Server::Transport::HTTP;
my $http = MCP::Server::Transport::HTTP->new;
that's it. two lines. iconic. π
π¦ DESCRIPTION π¦
MCP::Server::Transport::HTTP is a transport for MCP (Model Context Protocol) servers that uses HTTP as the underlying transport mechanism. it's the whole vibe. π«Ά
so here's the tea: only POST requests are handled. GET and DELETE? rejected, status 405, no notes. π The protocol is stateless, meaning nothing is remembered between requests, which is lowkey the best part because the transport can be deployed behind a load balancer and a pre-forking web server. Notifications that belong to a request β like progress reports β are delivered on the response stream of that very request, which gets upgraded from application/json to text/event-stream whenever there's actually something to deliver. it's giving β¨custom deliveryβ¨.
the one exception is streaming, which opts in to subscriptions/listen. Long-lived notification streams require per-process state, and are therefore not compatible with pre-forking web servers. read that again bestie, no cap. π
Routing headers are validated against the JSON-RPC body before a request is dispatched, so a gateway that routes on Mcp-Method, Mcp-Name, or Mcp-Param-* alone can never disagree with the server about what was called. consistency queen. π
β¨ ATTRIBUTES β¨
MCP::Server::Transport::HTTP inherits all attributes from MCP::Server::Transport and implements the following new ones. π
π auth
my $cb = $http->auth;
$http = $http->auth(sub ($c) {...});
Optional callback to authenticate each request before it's dispatched. It receives the Mojolicious::Controller and returns a hash reference of authentication info on success, or a false value to reject the request with a 401 WWW-Authenticate challenge. The scopes and principal keys of the returned hash reference are made available to handlers as scopes in MCP::Server::Context and principal in MCP::Server::Context. Token validation is left to the application, so this is literally where you verify an OAuth 2.0 access token. when not set, requests are not authenticated. π§
π heartbeat
my $seconds = $http->heartbeat;
$http = $http->heartbeat(30);
Interval in seconds at which a keep-alive comment is sent on each open subscription stream. Defaults to 30; set it to 0 to disable. Useful when you're running behind reverse proxies that close idle connections (ugh, they always do). Only used when streaming is enabled. π
π metadata_url
my $url = $http->metadata_url;
$http = $http->metadata_url('https://example.com/.well-known/oauth-protected-resource');
URL of the OAuth 2.0 Protected Resource Metadata document. When set, it's included as the resource_metadata parameter of the WWW-Authenticate challenge sent with 401 and 403 responses, so clients can discover the authorization server. Use an absolute URL so remote clients can actually fetch it, bestie. See "oauth_metadata" in MCP::Server. π
π origins
my $origins = $http->origins;
$http = $http->origins(['https://example.com']);
$http = $http->origins(sub ($c, $origin) {...});
Origins allowed to make browser requests β either an array reference of exact matches, or a callback returning true for an acceptable origin. Requests carrying an Origin header that isn't allowed are rejected with status 403, which protects against DNS rebinding attacks on servers bound to localhost. Defaults to undef, which accepts every origin. (yes, every single one. protect her.) π‘οΈ
π‘ streaming
my $bool = $http->streaming;
$http = $http->streaming(1);
Enable subscriptions/listen, so clients can open a long-lived stream for the list_changed notifications they ask for. Defaults to false. When enabled, the transport tracks every open stream in subscriptions and advertises the listChanged capabilities in server/discover. Progress and log notifications do not depend on this, since they're delivered on the response stream of the request they belong to. β
π subscriptions
my $subscriptions = $http->subscriptions;
$http = $http->subscriptions({});
Per-process registry of active MCP::Server::Subscription objects. Only used when streaming is enabled. π₯
π§ 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. that's the whole job description and she ate. π
π notifications
my $bool = $http->notifications;
True when streaming is enabled, false otherwise. simple as. β¨
π’ notify_all
my $bool = $http->notify_all($method);
my $bool = $http->notify_all($method, {foo => 'bar'});
Send a JSON-RPC notification to every subscription that asked for it. Returns true on success, or undef when streaming is disabled. so if you get undef back, check that streaming flag first, iykyk. π
π SEE ALSO π
all three are mandatory reading, bestie, no skipping. π
π vibe check reminder: stateless = load-balancer friendly, but streaming needs per-process state, so it's not compatible with pre-forking web servers. don't say i didn't warn you.
and that's the page! πΈ this cutie is perl v5.42.0, dated 2026-07-31 β go forth and transport, bestie, you're gonna slay. ππ¦π
π¦ where this page comes from
- opensuse-leap 16.0: perl-MCP 0.150.0-bp160.1.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms