object

mcp_server_streamable_http_transport

Implements the Streamable HTTP transport for MCP servers. Uses Logtalk http_server::serve_until_shutdown/5 and a dedicated http_handler_protocol handler object. Supports specs 2025-06-18, 2025-11-25, and 2026-07-28 selected via the spec/1 option and delegated to the matching mcp_server_*_spec object. Supports optional OAuth protection and protected-resource metadata publication using the oauth/4 option. Long-lived subscriptions/listen streams emit periodic SSE comment keep-alives (http_sse_keepalive/1). Requires a multi-threaded backend for subscriptions/listen.

Availability:
logtalk_load(mcp_server(loader))
Author: Paulo Moura
Version: 1:0:0
Date: 2026-09-02
Compilation flags:
static, context_switching_calls, threaded
Remarks:
(none)

Public predicates

prepare/2

Initializes adapter state for Application with Options without opening a listener. Used by unit tests and by embeddings by pairing with handle_mcp_request/4 and cleanup/0.

Compilation flags:
static
Template:
prepare(Application,Options)
Mode and number of proofs:
prepare(+object_identifier,+list) - one_or_error
Exceptions:
Options is a variable:
instantiation_error
Options is neither a variable nor a list:
type_error(list,Options)
An element Option of the list Options is a variable:
instantiation_error
An element Option of the list Options is neither a variable nor a compound term:
type_error(compound,Option)
An element Option of the list Options is a compound term but not a valid option:
domain_error(option,Option)

attach_sse_stream/1

Registers a live output stream for incremental SSE writes. Headers must already have been written. Each emit_progress/5 call writes and flushes immediately.

Compilation flags:
static
Template:
attach_sse_stream(Stream)
Mode and number of proofs:
attach_sse_stream(+stream) - one

detach_sse_stream/0

Clears any live SSE output stream registration.

Compilation flags:
static
Mode and number of proofs:
detach_sse_stream - one

sse_headers/1

HTTP headers for an SSE response body.

Compilation flags:
static
Template:
sse_headers(Headers)
Mode and number of proofs:
sse_headers(-list) - one

current_options/1

Unified with the options list established by prepare/2 or start/4.

Compilation flags:
static
Template:
current_options(Options)
Mode and number of proofs:
current_options(-list) - zero_or_one

handle_mcp_request/4

Handles one MCP HTTP request. Method is an uppercase HTTP method atom. Headers is a list of Name-Value pairs. Body is the raw request body atom. HTTPResponse is http_response(Status, Headers, BodyAtom) or http_response(already_sent, Headers, BodyAtom).

Compilation flags:
static
Template:
handle_mcp_request(Method,Headers,Body,HTTPResponse)
Mode and number of proofs:
handle_mcp_request(+atom,+list,+atom,-compound) - one

emit_progress/5

Emits a notifications/progress event. In live mode the SSE record is written and flushed immediately on the attached stream. In buffered mode the event is queued until finalize_response/4.

Compilation flags:
static
Template:
emit_progress(Token,RequestId,ProgressValue,Total,Message)
Mode and number of proofs:
emit_progress(+term,+term,+number,+number,+atom) - one

Protected predicates

(no local declarations; see entity ancestors if any)

Private predicates

running_/0

True while the adapter has been prepared or is serving requests.

Compilation flags:
dynamic
Mode and number of proofs:
running_ - zero_or_one

server_options_/1

Merged server options for the active prepare/start session.

Compilation flags:
dynamic
Template:
server_options_(Options)
Mode and number of proofs:
server_options_(-list) - zero_or_one

shutdown_control_/1

Token passed to http_server::request_shutdown/1 when stopping the listener.

Compilation flags:
dynamic
Template:
shutdown_control_(Control)
Mode and number of proofs:
shutdown_control_(-nonvar) - zero_or_one

subscription_/4

Active subscriptions/listen registration. Synchronization uses threaded_wait/1 and threaded_notify/1 tagged by SubscriptionId.

Compilation flags:
dynamic
Template:
subscription_(SubscriptionId,RequestId,Filters,Stream)
Mode and number of proofs:
subscription_(-atom,-nonvar,-list,-nonvar) - zero_or_more

progress_events_/1

Buffered notifications/progress events when SSE mode is not live.

Compilation flags:
dynamic
Template:
progress_events_(Events)
Mode and number of proofs:
progress_events_(-list) - zero_or_one

progress_token_/1

progressToken from the current request, or none.

Compilation flags:
dynamic
Template:
progress_token_(Token)
Mode and number of proofs:
progress_token_(-nonvar) - zero_or_one

sse_output_/1

Live response stream for incremental SSE writes.

Compilation flags:
dynamic
Template:
sse_output_(Stream)
Mode and number of proofs:
sse_output_(-stream) - zero_or_one

sse_mode_/1

Current SSE delivery mode: live, buffered, or none.

Compilation flags:
dynamic
Template:
sse_mode_(Mode)
Mode and number of proofs:
sse_mode_(-atom) - zero_or_one

Operators

(none)