src/server.bend checks
raw source on the hub · import ezmcp@0.2.0.0/src/server.bend as Server
ezmcp/src/server: an MCP server's decisions, with no IO. One message's
text in, under the protocol revision the transport reads it by, an act
out: a reply to send, nothing to send, a tool call for the transport to
run (src/io.bend) before it replies with ran, or, under 2025-03-26, a
batch of those.
4 imports
import Base import 0xa81e161008ecc2f297c0a3065cb9b188/main.bend as Json import 0xa81e161008ecc2f297c0a3065cb9b188/src/value.bend as Value import ./rpc.bend as Rpc
Types
type ToolSpec source · line 12 · raw
Data
one tool: its name, what it does, and the JSON Schema of its arguments
ToolSpec@name:String -> @description:String -> @input:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> ToolSpec
type Server source · line 17 · raw
Data
a server: its name and version, instructions for the client (empty for none), and its tools
Server@name:String -> @version:String -> @instructions:String -> @tools:List<&2, ToolSpec> -> Server
type Act source · line 23 · raw
Data
what a server does with one message; a Batch's acts are its elements', in order, and none of them is a Batch
QuietAct
Send@reply:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Act
Fault@reply:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Act
Run@id:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @name:String -> @args:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Act
Batch@acts:List<&2, Act> -> Act
type Turn source · line 32 · raw
Data
what a server does with one message, and the revision the messages after it are read by on the same stream
Turn@act:Act -> @rev:String -> Turn
type Step source · line 36 · raw
Data
how a method ends: an outcome now, or a tool to run
Now@out:0x6b75cc24ae78878f45f867de73d7929d/src/rpc.Out -> Step
Call@name:String -> @args:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Step
type Method source · line 41 · raw
Data
the methods a server answers
InitializeMethod
PingMethod
ListToolsMethod
CallToolMethod
OtherMethod
Definitions
def latest source · line 51 · raw
String
the latest revision ezmcp speaks
def oldest source · line 56 · raw
String
the oldest: the one JSON-RPC batches belong to, and the one a server assumes for an HTTP request that names none
def revisions source · line 60 · raw
List<&2, String>
the revisions ezmcp speaks, oldest first
def supported source · line 64 · raw
@+val:String -> Bool
whether ezmcp speaks a revision
def batches source · line 70 · raw
@rev:String -> Bool
whether a revision receives JSON-RPC batches: 2025-03-26 does, and 2025-06-18 removed them
def negotiate.of source · line 75 · raw
@val:String -> @ok:Bool -> String
the revision a server answers to the one a client asks for: the same when it is supported, else the latest (basic/lifecycle#version-negotiation)
def negotiate source · line 83 · raw
@asked:Maybe<&2, String> -> String
the revision answered to an initialize request's, if it names one
def session.ask source · line 92 · raw
@rev:String -> @params:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @init:Bool -> String
def session source · line 101 · raw
@rev:String -> @msg:0x6b75cc24ae78878f45f867de73d7929d/src/rpc.Msg -> String
the revision the messages after this one are read by: the one the server answers an initialize request with, else the one they were read by
def capabilities source · line 116 · raw
@tools:List<&2, ToolSpec> -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
the capabilities a tool table declares: tools when there is one, with listChanged false, since the table never changes
def init.info source · line 123 · raw
@name:String -> @version:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
def init.extra source · line 127 · raw
@instructions:String -> @empty:Bool -> List<&1, Pair(String, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json)>
the instructions member, when there are any
def init.with source · line 138 · raw
@version:String -> @caps:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @info:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @+instructions:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
the members of an initialize result
def init source · line 150 · raw
@srv:Server -> @params:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
the result of initialize (basic/lifecycle#initialization)
def tool.json source · line 159 · raw
@tail:ToolSpec -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
one tool as tools/list shows it (server/tools#tool)
def tool.all source · line 165 · raw
@tools:List<&2, ToolSpec> -> List<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json>
def list source · line 173 · raw
@srv:Server -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
the result of tools/list: every tool, in order, on one page
def known.or source · line 179 · raw
@hit:Bool -> @rest:(@_:Unit -> Bool) -> Bool
true at a hit, else the rest of the search
def known source · line 187 · raw
@tools:List<&2, ToolSpec> -> @+name:String -> Bool
whether a tool table has a tool by this name
def invalid source · line 195 · raw
@message:String -> Step
an invalid-params outcome
def call.args source · line 200 · raw
@+name:String -> @has:Bool -> @+args:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Step
the arguments of a call: absent is no arguments, an object is passed on, anything else is invalid
def call.known source · line 208 · raw
@+name:String -> @+params:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @hit:Bool -> Step
def call.named source · line 216 · raw
@tools:List<&2, ToolSpec> -> @+params:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @name:Maybe<&2, String> -> Step
def call source · line 229 · raw
@srv:Server -> @+params:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Step
tools/call: a known tool with object arguments is a call to run; anything else is an invalid-params error (server/tools#error-handling)
def method.of source · line 236 · raw
@+meth:String -> Method
def dispatch.of source · line 242 · raw
@srv:Server -> @meth:String -> @params:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @which:Method -> Step
def dispatch source · line 261 · raw
@srv:Server -> @+meth:String -> @params:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> Step
how a request for a method ends
def answer source · line 265 · raw
@id:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @text:Step -> Act
a request's step as an act
def handle source · line 274 · raw
@srv:Server -> @msg:0x6b75cc24ae78878f45f867de73d7929d/src/rpc.Msg -> Act
what a server does with one classified message: a request is answered, a notification or a response is not, an invalid request is a fault
def unparsed source · line 286 · raw
Act
the fault for text that is not JSON (JSON-RPC 2.0 §5.1)
def batch.init source · line 292 · raw
@id:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @msg:0x6b75cc24ae78878f45f867de73d7929d/src/rpc.Msg -> @init:Bool -> @srv:Server -> Act
def batch.one source · line 303 · raw
@srv:Server -> @+msg:0x6b75cc24ae78878f45f867de73d7929d/src/rpc.Msg -> Act
what a server does with one element of a batch: what it does with the message alone, except that initialize is an invalid request (2025-03-26/basic/lifecycle#initialization)
def batch.all source · line 311 · raw
@+srv:Server -> @items:List<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json> -> List<&2, Act>
every element's act, in order
def batch source · line 320 · raw
@srv:Server -> @items:List<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json> -> Act
what a server does with a batch: an empty one is one invalid request (JSON-RPC §6); any other is a batch of its elements' acts
def batch.some source · line 329 · raw
@replies:List<&2, Maybe<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json>> -> List<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json>
the replies of a batch's elements that have one, in order
def batch.gather source · line 338 · raw
@replies:List<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json> -> Maybe<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json>
def batch.reply source · line 347 · raw
@replies:List<&2, Maybe<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json>> -> Maybe<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json>
what a batch sends back: nothing when no element has a reply, else the array of the replies (JSON-RPC §6)
def turn.msg source · line 353 · raw
@srv:Server -> @rev:String -> @+msg:0x6b75cc24ae78878f45f867de73d7929d/src/rpc.Msg -> Turn
a message's act, and the revision after it
def turn.value source · line 358 · raw
@srv:Server -> @rev:String -> @+val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @many:Bool -> Turn
a decoded value: a batch when it is an array and the revision receives batches, else one message
def turn.parsed source · line 366 · raw
@srv:Server -> @+rev:String -> @meth:Maybe<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json> -> Turn
a decoded message, or text that was not JSON
def turn source · line 375 · raw
@srv:Server -> @rev:String -> @text:String -> Turn
what a server does with one message's text, read by revision rev, and
the revision the stream's next message is read by
def turn.act source · line 379 · raw
@tn:Turn -> Act
a turn's act
def step source · line 385 · raw
@srv:Server -> @rev:String -> @text:String -> Act
what a server does with one message's text, read by revision rev
def without.pair source · line 390 · raw
@hit:Bool -> @key:String -> @val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @rest:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
def without.bind source · line 397 · raw
@hit:Bool -> @src:String -> @num:U32 -> @val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @rest:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
def without.go source · line 411 · raw
@cells:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @+key:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
an object's members, less every one named key
def without source · line 422 · raw
@val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @key:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
an object less every member named key; any other value as it is
def shape.of source · line 429 · raw
@result:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @old:Bool -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
def shape source · line 439 · raw
@rev:String -> @result:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
a tool's result as revision rev reads it: 2025-03-26 has no
structuredContent (2025-06-18/server/tools#structured-content), so it is
left out; any later revision gets the result as the runner answered it
def ran source · line 445 · raw
@rev:String -> @id:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @out:0x6b75cc24ae78878f45f867de73d7929d/src/rpc.Out -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
the reply to a tool call under revision rev, once the runner answered:
its tool result, shaped for the revision, or the protocol error it chose
(server/tools#error-handling)
def text source · line 455 · raw
@text2:String -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
a text content block
def result source · line 459 · raw
@blocks:List<&2, 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json> -> @bad:Bool -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
a tool result from content blocks, flagged when the tool failed
def structured source · line 463 · raw
@+val:0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json -> @bad:Bool -> 0xa81e161008ecc2f297c0a3065cb9b188/src/value.Json
a tool result with structured content, and its JSON text as a text block