Over HTTP, the server runs on its own and clients connect to its URL:
# in a dedicated R process: 127.0.0.1:8000, 4 workers, 60-second calls,
# 8 calls waiting at most
runlog::run_mcp_server(
transport = "http"
)It follows the Streamable HTTP transport of MCP 2025-11-25: a POST
gets a JSON response, or an SSE stream when the server sends messages
before its answer, a notification 202, a GET on the MCP endpoint an SSE
stream (below), another method 405, a path other than /mcp,
/health and /elicitation/complete (see Asking the user) 404; an
Origin other than localhost gets 403 (against
DNS rebinding); a POST on /mcp whose
Content-Type is not application/json gets 415,
so that a web page cannot send one without the browser asking the server
first; an MCP-Protocol-Version other than 2025-11-25 and
2026-07-28 400 with -32022, and a body over 1 MiB 400, refused by the
HTTP server of nanonext before the request reaches
mordew. It listens on 127.0.0.1 only by
default, as the specification recommends for a local server. A client
that runs in a web page of another origin is not served: the server
sends no CORS header, and refuses an Origin that is not
local.
Requests of 2026-07-28
2026-07-28 requests need no session. Their
MCP-Protocol-Version header must be the version in their
_meta, or they get 400 and -32020; a request sent with
MCP-Protocol-Version: 2026-07-28 and no version in its
_meta gets 400 and -32602, since it lacks a required field.
Their Mcp-Method header must be their method, and their
Mcp-Name header the name or URI of a
tools/call, prompts/get or
resources/read, or the task ID of a tasks/get,
tasks/update or tasks/cancel, decoded first
when it comes as =?base64?…?=; otherwise they get 400 and
-32020 too, so that a proxy that routes on the headers and the server
that runs the body see the same request.
@mcpHeader region Region marks the parameter
region of a tool with x-mcp-header: a
2026-07-28 client over HTTP mirrors its value into an
Mcp-Param-Region header, so that a proxy can route on it,
and a call whose header does not match the argument gets 400 and -32020;
an integer is compared as a number, so 12.0 matches 12. The
parameter must be a string, an integer or a boolean that the model
gives, and the header names of a tool must be unique whatever their
case. A header value that comes as =?base64?…?= must be
strict Base64, padded and in its alphabet. A 2026-07-28 request the
server refuses for its _meta, or that needs a capability
the client did not declare (-32021), gets 400, and one with a method the
server does not know 404. A client cancels a 2026-07-28 request by
closing its stream. The server only learns it when a write fails, so it
writes an SSE comment every 15 seconds on an open stream of a 2026-07-28
request; once a write fails, it cancels the request as
notifications/cancelled does over stdio: a subscription
ends, a call leaves the queue or its worker stops, and a call that runs
as a task goes on. A request that has not opened its stream, such as a
tool call that sends neither progress nor logs, runs to its end. A
2025-11-25 stream that closes cancels nothing, since the client can
resume it.
Sessions
The answer to initialize carries an
MCP-Session-Id header, a random 128-bit ID that the client
sends back with every request. The session keeps what the client
declared it can do, and lets the server tell whose request a message is
about, since each client numbers its own requests. A request with a
session the server does not know, or no longer knows, gets 404, so that
the client opens a new one, unless it is a 2026-07-28 request, which has
no session and is served; DELETE on /mcp ends
a session, and the server forgets a session idle for an hour. It keeps
at most 1024 sessions: the one that comes beyond ends the session seen
least recently, whose client gets that 404 and opens a new one. A
session that ends has its listening stream closed and its calls stopped,
among them those that wait for an answer of the user. A request without
a session is still served, but can be neither cancelled nor asked a
question.
Resuming a stream
In a session, the SSE stream of a POST opens with an event that
carries only an ID, and numbers the events after it: the ID names the
stream and the place of the event in it. When the connection drops, the
call goes on. The client sends a GET on /mcp with its
session and the Last-Event-ID it got last; the server sends
again the events that followed, then the rest of the stream on that
connection. The server keeps the last 1000 events of a stream, until
five minutes after its answer, and a Last-Event-ID of a
stream it does not know gets 400. Without a session, the events carry no
ID and a dropped stream is lost.
Listening
A GET on /mcp with a session and without
Last-Event-ID opens an SSE stream that stays open, for the
messages that the server sends outside the answer to a request: the
updates of the resources that the session subscribed to, the end of a
URL elicitation, and the progress, the logs and the status of its tasks.
It opens with the same empty event and numbers its events as the stream
of a POST does, and resumes the same way. The server sends each message
on one stream only, so a new GET of the session takes over from the one
before, which the server closes. A GET without a session gets 405, as
the specification asks of a server that offers no stream there. The
server keeps the last 1000 events of that stream for as long as the
session lives, and writes a comment on it every 15 seconds, so that a
proxy does not close it: while the comments go through, the session is
not idle.
Authentication
With a token, every request but GET /health must send
Authorization: Bearer <token>, or gets a 401 with
WWW-Authenticate: Bearer; the token is compared in constant
time. It comes from the MORDEW_TOKEN environment variable
by default, which the server takes out of its environment before it
starts its workers: a tool cannot read it. The server speaks plain HTTP:
beyond the machine, the token crosses the network in clear unless a
proxy in front adds TLS, and a token typed in a command shows in the
list of the processes. The token is optional: a proxy or a gateway in
front may authenticate the clients instead, or the network may be
private. Serving on another host than 127.0.0.1,
localhost or ::1 without one prints a message
at start-up, so that an open server does not go unnoticed.
The 403, 404, 401, 405 and 400 above are settled on the headers, before the request reaches the front; the HTTP server has read the body by then, at most 1 MiB.
MORDEW_TOKEN=... Rscript -e "runlog::run_mcp_server(transport = 'http', host = '0.0.0.0')"
claude mcp add --transport http runlog http://server:8000/mcp --header "Authorization: Bearer ..."A shared token suits an internal deployment. It is not the OAuth 2.1 authorization of the MCP specification: one secret for every user, no identity, no expiry, and no discovery for clients that only speak OAuth. mordew does not plan OAuth: a deployment that needs it puts a gateway that handles it in front of the server.