MCP server
The $mcp key, the mcp option of actions, the JSON-RPC methods of POST /$mcp/, the client of GET /$mcp/client.js and Total.mcp.
On this page
The $mcp key, the mcp option of actions, the JSON-RPC methods of POST /$mcp/, the JavaScript client of GET /$mcp/client.js (code mode) and the Total.mcp object. The guide MCP server explains how actions become tools and how to protect the endpoint.
API
config
$mcp : Boolean
Turns on the MCP server.
$mcp : BooleanReturns Boolean
true creates the routes POST /$mcp/ and GET /$mcp/client.js when the application is ready. Set it in the config file or in code before the start.
Default: false.
$mcp : true
config
mcp: Boolean
Makes an action a tool.
mcp: BooleanReturns Boolean
An action with mcp: true is listed by tools/list and runs with tools/call. The name of the tool is the name of the action with each character other than A-Z, a-z, 0-9, _ and - replaced by _ (at most 64 characters). The description is the summary option, or the name option. The input, query and params schemas become the arguments and output the output schema.
NEWACTION('Tasks|list', {
summary: 'Lists the tasks, 20 per page',
mcp: true,
query: 'page:Number // The page number',
action: function($) {
NOSQL('tasks').find().paginate($.query.page || 1, 20).callback($);
}
});
// the tool Tasks_list
type
POST /$mcp/
The endpoint of the MCP server.
POST /$mcp/A JSON-RPC 2.0 endpoint: one message in the body, one JSON answer. The body can have up to 10 MB and the request can take up to 300 seconds. A message without id is a notification and gets status 202 without a body. A message without "jsonrpc": "2.0" or method, or an array, gets the error -32600; an unknown method gets -32601. When Total.mcp.auth refuses the request, the status is 401 and the error -32001.
await fetch('http://localhost:8000/$mcp/', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: 'Bearer 6f1d2c' },
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list' })
});
type
GET /$mcp/client.js[?q=words]
The tools as a JavaScript client, for code mode.
GET /$mcp/client.js[?q=words]| Parameter | Type | Description |
|---|---|---|
q? |
String |
Words that the name or the description of a tool must contain. |
Returns String The JavaScript source.
Returns a CommonJS module (text/javascript) made from the tools that the caller may use: one function per tool, with JSDoc for its arguments (input, query, params and their fields, with the // messages as descriptions) and for its result. require('./client.js')(token, [url]) returns an object of these functions. Each function sends tools/call to POST /$mcp/ with Authorization: Bearer token, resolves with the output of the tool (structuredContent, or the parsed text) and throws an Error with the message of a tool error. The default url is the address the file was downloaded from. It needs Node.js 18 or newer (fetch) and no packages.
?q=words returns only the tools whose name or description contain all the words (not case-sensitive). The request goes through Total.mcp.auth (a refused one gets 401 and the text Unauthorized) and Total.mcp.filter, so the client has the same tools as tools/list. Nothing runs on the server: the script runs where the agent runs, and every call is a normal tool call.
// curl -H 'Authorization: Bearer TOKEN' 'https://app.example.com/$mcp/client.js?q=tasks' > client.js
const api = require('./client.js')('TOKEN');
const task = await api.Tasks_create({ input: { name: 'Call Peter' } });
console.log(task.id);
/**
* Creates a task and returns its ID
* @param {Object} args
* @param {Object} args.input Payload (request body) passed to this action.
* @param {String} args.input.name The name of the task
* @param {String} [args.input.due] When the task must be done (ISO date)
* @returns {Promise<{ id: ?String }>}
*/
api.Tasks_create = args => call("Tasks_create", args);
method
{ method: 'initialize', params: { protocolVersion } }
Starts a session of the client.
{ method: 'initialize', params: { protocolVersion } }Returns Object The result.
Returns protocolVersion (the version of the client when it is in Total.mcp.versions, otherwise the first one), capabilities: { tools: {} } and serverInfo: { name: CONF.name, version: CONF.version }. The server keeps no state between requests.
{ "jsonrpc": "2.0", "id": 1, "result": { "protocolVersion": "2025-06-18", "capabilities": { "tools": {} }, "serverInfo": { "name": "Tasks", "version": "1.0" } } }
method
{ method: 'ping' }
Checks the connection.
{ method: 'ping' }Returns Object An empty object.
Returns an empty result {}.
method
{ method: 'tools/list' }
Lists the tools.
{ method: 'tools/list' }Returns Object The result.
Returns { resultType: 'complete', tools: [...] } with the definitions of all actions that have mcp: true (Total.mcp.tools) that Total.mcp.filter allows for the caller. Each definition has name, description (when the action has summary or name), inputSchema and, with an output schema, outputSchema.
method
{ method: 'tools/call', params: { name, arguments: { input, query, params } } }
Runs a tool.
{ method: 'tools/call', params: { name, arguments: { input, query, params } } }Returns Object The result.
Runs the action of the tool with ACTION(). arguments.input (or arguments.data) is the payload, arguments.query and arguments.params are the query and the URL parameters. The action has no controller, its user is the user that Total.mcp.auth accepted the request with ({ id: 'ai', name: 'AI', sa: true } with the default function) and $.config.id is the id from the query string of the endpoint. The result has content: [{ type: 'text', text }] with the response (a string as it is, other values as JSON) and, for an object, structuredContent. Errors of the action are a result with isError: true, also when the action throws an exception (the text is Tool execution failed, or 500: Internal Server Error for an async action, and the exception goes to the error log). An unknown tool, a tool that Total.mcp.filter hides from the caller, or arguments that are not an object give the error -32602.
{ "jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": { "name": "Tasks_remove", "arguments": { "params": { "id": "JafvB11cV61f" } } } }
{ "jsonrpc": "2.0", "id": 5, "result": { "resultType": "complete", "content": [{ "type": "text", "text": "{\"success\":true}" }], "structuredContent": { "success": true } } }
method
{ method: 'server/discover' }
Describes the server.
{ method: 'server/discover' }Returns Object The result.
Returns resultType: 'complete', supportedVersions: ['2026-07-28'], capabilities: { tools: {} } and the server info (CONF.name, CONF.version) in _meta['io.modelcontextprotocol/serverInfo'].
delegate
Total.mcp.auth = function($)
Decides who may use the endpoint.
Total.mcp.auth = function($)| Parameter | Type | Description |
|---|---|---|
$ |
Options |
The request; call $.success() or $.invalid(). |
Runs for every request to POST /$mcp/ and GET /$mcp/client.js. $.token (and $.auth) is the Authorization header without Bearer , and $ has headers, query, ip, ua and url. Call $.success(user) to accept the request or $.invalid() to refuse it with 401. The tools run as user and Total.mcp.filter gets it as $.user; $.success() without a user gives an empty user {}. The default function accepts every request with the user { id: 'ai', name: 'AI', sa: true }. Set it in a file in definitions/.
Total.mcp.auth = function($) {
if ($.token && $.token === CONF.mcp_admin)
$.success({ id: 'admin', name: 'Admin', sa: true });
else if ($.token && $.token === CONF.mcp_reader)
$.success({ id: 'reader', name: 'Reader', permissions: ['tasks_read'] });
else
$.invalid();
};
delegate
Total.mcp.filter = function(tool, $)
Decides which tools a caller sees and may run.
Total.mcp.filter = function(tool, $)| Parameter | Type | Description |
|---|---|---|
tool |
Object |
The definition of the tool: name, description, inputSchema, outputSchema. |
$ |
Options |
The request; $.user is the caller. |
Returns Boolean true when the caller may use the tool.
Optional, null by default (every caller has all tools). The function gets the definition of a tool (an item of Total.mcp.tools) and $ with the user from Total.mcp.auth in $.user, and returns true to allow the tool. A tool that is not allowed is left out of tools/list and GET /$mcp/client.js, and tools/call answers it with -32602 (Unknown tool), as if it did not exist.
Total.mcp.filter = function(tool, $) {
return !tool.name.startsWith('Admin_') || $.user.sa;
};
property
Total.mcp.tools
The definitions of the tools.
Total.mcp.toolsReturns Array
An array with the definition of every action that has mcp: true, the same objects that tools/list returns. It is built again 200 ms after each NEWACTION().
console.log(Total.mcp.tools.map(tool => tool.name));
// ['Tasks_create', 'Tasks_list', 'Tasks_remove']
property
Total.mcp.versions
The supported protocol versions.
Total.mcp.versionsReturns Array
An array, newest first: ['2026-07-28', '2025-11-25', '2025-06-18', '2025-03-26']. initialize answers with the version of the client when it is in the list, otherwise with the first one.
method
F.actions[name].toAITool()
Returns the tool definition of an action.
F.actions[name].toAITool()Returns Object The tool definition.
Returns { name, description, inputSchema, [outputSchema] } in the format of tools/list. It works for any action, also without mcp: true, so you can pass actions as tools to an AI model yourself.
var tool = F.actions['Tasks|remove'].toAITool();
// { name: 'Tasks_remove', description: 'Removes a task', inputSchema: { type: 'object', properties: { params: {...} }, required: ['params'] } }