Once a callback is bound, it will be invoked when an MCP client calls the tool, reads the resource, or sends the notification.
This section explains how to implement the callback logic itself.
Tool callbacks
A tool callback receives:
The MCP Request: Object containing all of the parameters of the request sent by the MCP Client
In the function callback, you will need to extract the value of the parameters one by one using Get Param, or a array of all of them with Get Params.
After that you can set the logic of your callback.
To finish, you need to return a Json string, the plugin has something to help you do that natively:
JsonOk: Put the message and the data using a map tranformed in Json with Make Json Object.
JsonError: Put the error code and the message.
Choose wisely the return Json of your callback, because it will give informations on the result of the tool to your MCP client.
Resources callbacks
A resource callback receives:
Uri: the full URI requested by the client.
Uri Params Json: a JSON string containing the variables extracted from the URI template.
SessionId: the MCP session identifier of the client that requested the resource.
These values allow the callback to identify the requested resource, access dynamic URI parameters, and know which client session made the request.
Notification callbacks
A notification callback receives three parameters:
Method: the notification name that was triggered, such as "game/playerJoined".
Parameters JSON: the notification payload as a JSON string.
SessionId: the MCP session ID of the client that sent the notification.
Use Method to identify the event, Parameters JSON to read the payload, and Session Id to trace or differentiate the connected client that triggered it.