v2026.11.3
All Bundles
Bundle

MCP server support (-lib net_server)

McpRequestHandler

MCP request handler. Each POST body is one JSON-RPC 2.0 message from the client and nothing in it is trusted: a body that is not JSON, is not a request object, or carries "jsonrpc", "method", "id" or "params" of the wrong type is answered with the JSON-RPC error the MCP specification mandates (see ErrorCode) instead of being dereferenced, a body over MAX_BODY_SIZE bytes is refused with HTTP 413, a notification (no "id") is accepted with a bodyless HTTP 202, and a handler callback (ListTools, CallTool, ...) that raises, dereferences Nil or returns Nil is answered with an internal error rather than ending the server.

Operations

CallPrompt # virtual

Calls a prompt

method : private : virtual : CallPrompt(name:String, arguments:JsonElement) ~ Vector<PromptMessage>

Parameters

NameTypeDescription
nameStringprompt name
argumentsJsonElementprompt arguments

Return

TypeDescription
Vector<PromptMessage>vector of prompt messages

CallTool # virtual

Calls a tool

method : private : virtual : CallTool(name:String, arguments:JsonElement) ~ Vector<ToolContent>

Parameters

NameTypeDescription
nameStringtool name
argumentsJsonElementtool arguments

Return

TypeDescription
Vector<ToolContent>vector of tool content

CheckCache # function

Checks and clears expired sessions from cache

function : CheckCache() ~ Nil

GetResource # virtual

Gets a resource by URI

method : private : virtual : GetResource(uri:Url) ~ Vector<ResourceContent>

Parameters

NameTypeDescription
uriUrlresource URI

Return

TypeDescription
Vector<ResourceContent>vector of resource content

Initialize # function

Initializes the MCP request handler

function : Initialize(config:JsonElement) ~ Bool

Parameters

NameTypeDescription
configJsonElementJSON configuration, with an "http_session_timeout" greater than 0

Return

TypeDescription
Booltrue if successful, false if the configuration is Nil or its "http_session_timeout" is missing or not greater than 0

ListPrompts # virtual

Lists available prompts

method : private : virtual : ListPrompts() ~ Vector<PromptItem>

Return

TypeDescription
Vector<PromptItem>vector of prompt items

ListResources # virtual

Lists resources

method : private : virtual : ListResources() ~ Vector<ResourceItem>

Return

TypeDescription
Vector<ResourceItem>vector of resource items

ListTemplates # virtual

Lists resource templates

method : private : virtual : ListTemplates() ~ Vector<ResourceTemplate>

Return

TypeDescription
Vector<ResourceTemplate>vector of resource templates

ListTools # virtual

Lists available tools

method : private : virtual : ListTools() ~ Vector<ToolItem>

Return

TypeDescription
Vector<ToolItem>vector of tool items

New # constructor

Constructor

New()

ProcessGet #

Processes GET requests

method : private : ProcessGet(request:Web.HTTP.Server.Request, response:Web.HTTP.Server.Response) ~ Bool

Parameters

NameTypeDescription
requestRequestHTTP request
responseResponseHTTP response

Return

TypeDescription
Booltrue to continue processing, false otherwise

ProcessPost #

Processes POST requests. The body is one JSON-RPC 2.0 message. A body that is empty, not JSON, over MAX_BODY_SIZE bytes or nested deeper than the parser allows is answered with PARSE_ERROR (INVALID_REQUEST and HTTP 413 for the size); JSON that is not an object, or whose "jsonrpc" is not "2.0", "method" is not a non-empty string, "id" is present but neither a string nor a number, or "params" is not an object, with INVALID_REQUEST (HTTP 400); a message without an "id", or whose method starts with "notifications/", is a notification and gets a bodyless HTTP 202. A request for a method the server lacks, with params it cannot use, or whose handler callback raised, dereferenced Nil or returned Nil is answered with METHOD_NOT_FOUND, INVALID_PARAMS or INTERNAL_ERROR in a JSON-RPC error reply (HTTP 200). The request id is echoed in every reply, null when it was unusable.

method : private : ProcessPost(request:Web.HTTP.Server.Request, response:Web.HTTP.Server.Response) ~ Bool

Parameters

NameTypeDescription
requestRequestHTTP request
responseResponseHTTP response

Return

TypeDescription
Booltrue to continue processing, false otherwise

ShowPayload # function

Displays payload for debugging

function : ShowPayload(payload:String) ~ Nil

Parameters

NameTypeDescription
payloadStringpayload string

StopCacheTimer # function

Stops the session cache timer

function : StopCacheTimer() ~ Nil

WriteError #

Writes a JSON-RPC error response

method : private : WriteError(code:Int, message:String, id:JsonElement, response:Web.HTTP.Server.Response, http_code:Int) ~ Nil

Parameters

NameTypeDescription
codeIntJSON-RPC error code (see ErrorCode)
messageStringwhat was wrong
idJsonElementrequest ID element, Nil for null when the request's id was unusable
responseResponseHTTP response
http_codeIntHTTP status code: 200 for an error in a well-formed request, 400 or 413 for a body that is not one

WriteResponse #

Writes a JSON-RPC response

method : private : WriteResponse(message:JsonElement, id:Int, response:Web.HTTP.Server.Response, code:Int) ~ Nil

Parameters

NameTypeDescription
messageJsonElementresponse message
idIntrequest ID
responseResponseHTTP response
codeIntHTTP status code

WriteResponse #

Writes a JSON-RPC response whose id is echoed as the request sent it (a string or a number; Nil writes null)

method : private : WriteResponse(message:JsonElement, id:JsonElement, response:Web.HTTP.Server.Response, code:Int) ~ Nil

Parameters

NameTypeDescription
messageJsonElementresponse message, Nil for an empty result object
idJsonElementrequest ID element
responseResponseHTTP response
codeIntHTTP status code