src/web.bend checks
raw source on the hub · import ezmcp@0.3.0.0/src/web.bend as Web
ezmcp/src/web: the streamable HTTP transport's decisions, with no IO (basic/transports#streamable-http). One HTTP request in, a reply out, or a tool call (or, under 2025-03-26, a batch) for src/io.bend to run before it replies. Every POST is answered with one JSON body or 202; there is no SSE stream and no session.
6 imports
import Base import ezjson@1.2.0.0/main.bend as Json import ezjson@1.2.0.0/src/value.bend as Value import ezhttp@0.23.0.0/src/http.bend as Http import ./rpc.bend as Rpc import ./server.bend as Server
Types
type Web source · line 16 · raw
Data
what the transport does with one HTTP request: reply now, run a tool
first, or run a batch's acts first; rev is the revision the request is
read by
Now@status:U32 -> @headers:List<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/http.Header> -> @body:String -> Web
Later@rev:String -> @id:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @name:String -> @args:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Web
Many@rev:String -> @acts:List<&2, 0x836cb96670527cb1735ff34e6a518b02/src/server.Act> -> Web
Definitions
def json source · line 22 · raw
List<&2, 0x7367809738fddd234b8d2bed772ad2cf/src/http.Header>
the header a JSON body carries
def json.reply source · line 26 · raw
@status:U32 -> @val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Web
a reply with a JSON body
def act source · line 32 · raw
@rev:String -> @lead:0x836cb96670527cb1735ff34e6a518b02/src/server.Act -> Web
a server's act, under revision rev, as an HTTP reply: a request's reply
is 200 with its JSON, a notification or a response is 202 with no body, a
message the server cannot accept is 400 with its error
def ran source · line 46 · raw
@rev:String -> @id:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @out:0x836cb96670527cb1735ff34e6a518b02/src/rpc.Out -> Web
the reply to a tool call, once it ran
def many source · line 51 · raw
@replies:Maybe<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json> -> Web
the reply to a batch once its acts ran: 202 with no body when none had a reply, else 200 with the array of the replies
def path.of source · line 59 · raw
@target:String -> String
a request-target's path: everything before ?
def origin.or source · line 63 · raw
@hit:Bool -> @rest:(@_:Unit -> Bool) -> Bool
true at a hit, else the rest of the search
def origin.listed source · line 71 · raw
@origins:List<&2, String> -> @+origin:String -> Bool
whether the server lists an Origin
def loopback.colon source · line 79 · raw
@tail:String -> @colon:Bool -> Bool
a port's digits after a colon
def loopback.port source · line 87 · raw
@rest:String -> Bool
after the host: nothing, or a colon and a port's digits
def loopback.at source · line 95 · raw
@+after:String -> @num:Nat -> @hit:Bool -> Bool
a host of n chars that is a loopback name, then a port
def loopback.host source · line 103 · raw
@+after:String -> Bool
whether what follows the scheme is a loopback host and an optional port
def loopback.scheme source · line 110 · raw
@+origin:String -> @num:Nat -> @hit:Bool -> Bool
a scheme of n chars, then a loopback host
def loopback source · line 119 · raw
@+origin:String -> Bool
whether an Origin is a page on this machine: http or https, host localhost, 127.0.0.1 or [::1], and an optional port
def origin.ok source · line 125 · raw
@origins:List<&2, String> -> @+origin:String -> Bool
whether an Origin is allowed: an absent one (a client that is not a browser), a page on this machine, or one the server lists
def version.ok source · line 131 · raw
@+val:String -> Bool
whether an MCP-Protocol-Version header is acceptable: absent, or a revision ezmcp speaks
def revision source · line 136 · raw
@+val:String -> String
the revision a request is read by: its MCP-Protocol-Version, or 2025-03-26 when it has none (basic/transports#protocol-version-header)
def text source · line 140 · raw
@status:U32 -> @body:String -> Web
a plain-text reply
def post.as source · line 144 · raw
@srv:0x836cb96670527cb1735ff34e6a518b02/src/server.Server -> @body:String -> @+rev:String -> Web
a POST read by revision rev: the server's step on its body
def post.ok source · line 149 · raw
@srv:0x836cb96670527cb1735ff34e6a518b02/src/server.Server -> @body:String -> @header:String -> @ok:Bool -> Web
a POST: refused for an unsupported revision, else the server's step under the revision its header names
def post source · line 157 · raw
@srv:0x836cb96670527cb1735ff34e6a518b02/src/server.Server -> @body:String -> @+header:String -> Web
a POST: the decision on its MCP-Protocol-Version header, empty when absent
def method source · line 161 · raw
@srv:0x836cb96670527cb1735ff34e6a518b02/src/server.Server -> @body:String -> @header:String -> @is_post:Bool -> Web
any method but POST is 405
def origin source · line 174 · raw
@srv:0x836cb96670527cb1735ff34e6a518b02/src/server.Server -> @body:String -> @header:String -> @is_post:Bool -> @allowed:Bool -> Web
a request whose Origin is not allowed is 403
def route source · line 190 · raw
@srv:0x836cb96670527cb1735ff34e6a518b02/src/server.Server -> @here:Bool -> @allowed:Bool -> @is_post:Bool -> @header:String -> @body:String -> Web
the decision over a request's parts: the path first, then the Origin, then the method, then the protocol version (its MCP-Protocol-Version header, empty when absent), then the body
def decide source · line 206 · raw
@srv:0x836cb96670527cb1735ff34e6a518b02/src/server.Server -> @path:String -> @origins:List<&2, String> -> @req:0x7367809738fddd234b8d2bed772ad2cf/src/http.Request -> Web
what the transport does with one HTTP request to an endpoint at path,
which allows the browser origins listed
def reply source · line 222 · raw
@wid:Web -> 0x7367809738fddd234b8d2bed772ad2cf/src/http.Reply
a Web reply as ezhttp's reply (a Later or a Many never reaches here)