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
- New
- CallPrompt
- CallTool
- CheckCache
- GetResource
- Initialize
- ListPrompts
- ListResources
- ListTemplates
- ListTools
- ProcessGet
- ProcessPost
- ShowPayload
- StopCacheTimer
- WriteError
- WriteResponse
CallPrompt # virtual
Calls a prompt
method : private : virtual : CallPrompt(name:String, arguments:JsonElement) ~ Vector<PromptMessage>Parameters
| Name | Type | Description |
|---|---|---|
| name | String | prompt name |
| arguments | JsonElement | prompt arguments |
Return
| Type | Description |
|---|---|
| Vector<PromptMessage> | vector of prompt messages |
CallTool # virtual
Calls a tool
method : private : virtual : CallTool(name:String, arguments:JsonElement) ~ Vector<ToolContent>Parameters
| Name | Type | Description |
|---|---|---|
| name | String | tool name |
| arguments | JsonElement | tool arguments |
Return
| Type | Description |
|---|---|
| Vector<ToolContent> | vector of tool content |
GetResource # virtual
Gets a resource by URI
method : private : virtual : GetResource(uri:Url) ~ Vector<ResourceContent>Parameters
| Name | Type | Description |
|---|---|---|
| uri | Url | resource URI |
Return
| Type | Description |
|---|---|
| Vector<ResourceContent> | vector of resource content |
Initialize # function
Initializes the MCP request handler
function : Initialize(config:JsonElement) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| config | JsonElement | JSON configuration, with an "http_session_timeout" greater than 0 |
Return
| Type | Description |
|---|---|
| Bool | true 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
| Type | Description |
|---|---|
| Vector<PromptItem> | vector of prompt items |
ListResources # virtual
Lists resources
method : private : virtual : ListResources() ~ Vector<ResourceItem>Return
| Type | Description |
|---|---|
| Vector<ResourceItem> | vector of resource items |
ListTemplates # virtual
Lists resource templates
method : private : virtual : ListTemplates() ~ Vector<ResourceTemplate>Return
| Type | Description |
|---|---|
| Vector<ResourceTemplate> | vector of resource templates |
ListTools # virtual
Lists available tools
method : private : virtual : ListTools() ~ Vector<ToolItem>Return
| Type | Description |
|---|---|
| Vector<ToolItem> | vector of tool items |
ProcessGet #
Processes GET requests
method : private : ProcessGet(request:Web.HTTP.Server.Request, response:Web.HTTP.Server.Response) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| request | Request | HTTP request |
| response | Response | HTTP response |
Return
| Type | Description |
|---|---|
| Bool | true 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) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| request | Request | HTTP request |
| response | Response | HTTP response |
Return
| Type | Description |
|---|---|
| Bool | true to continue processing, false otherwise |
ShowPayload # function
Displays payload for debugging
function : ShowPayload(payload:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| payload | String | payload string |
WriteError #
Writes a JSON-RPC error response
method : private : WriteError(code:Int, message:String, id:JsonElement, response:Web.HTTP.Server.Response, http_code:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| code | Int | JSON-RPC error code (see ErrorCode) |
| message | String | what was wrong |
| id | JsonElement | request ID element, Nil for null when the request's id was unusable |
| response | Response | HTTP response |
| http_code | Int | HTTP 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) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| message | JsonElement | response message |
| id | Int | request ID |
| response | Response | HTTP response |
| code | Int | HTTP 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) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| message | JsonElement | response message, Nil for an empty result object |
| id | JsonElement | request ID element |
| response | Response | HTTP response |
| code | Int | HTTP status code |