Spanish Total.js
English
Documentation For AI agents
Contents

Remote access

require('total5/remote'): the client of the Code Editor, the MCP proxy and the tools App_* for AI agents.

.md GitHub
On this page

The module total5/remote with the client of the Total.js Code Editor, the client and the server of the MCP proxy, and the tools App_*. The guide Remote access explains how to connect a project and how to protect the proxy. The start options edit and editmcp are in Application structure and modes, the requests of the editor in Command line.

API

method

require('total5/remote')

The module of the remote access.

Returns Object The module.

The module exports edit(), mcp(), proxy() and tools(). Loading it registers nothing.

Require
const Remote = require('total5/remote');
method

Remote.edit(url, [directory])

Connects a folder to the Total.js Code Editor.
ParameterTypeDescription
url String The URL from the editor, for example https://code.example.com/?id=project (http is changed to ws).
directory? String The folder to edit. Default: F.directory

Opens a WebSocket to url in the current process and answers the requests of the editor (see Code Editor requests) on the files of directory. The client pings the editor every 30 seconds and connects again every 10 seconds when the connection is lost. 404 project not found and 409 project is already open are printed when the editor refuses the project. F.remote(url, [directory]) is the same function. The start option edit calls it in the watcher process.

Connect
const Remote = require('total5/remote');
Remote.edit('https://code.example.com/?id=shop');
method

F.remote(url, [directory])

Connects the folder of the application to the Total.js Code Editor.
ParameterTypeDescription
url String The URL from the editor, wss://...?id=project.
directory? String The folder to edit. Default: F.directory

Returns undefined

The same as Remote.edit(): starts the remote editing client in the current process, a WebSocket connection to url that lets the editor browse and change the files in directory. It reconnects every 10 seconds when the connection is lost. The edit start option does the same in the watcher process.

Connect
F.remote('wss://code.example.com/?id=myproject');
method

Remote.mcp(url)

Connects the application to an MCP proxy.
ParameterTypeDescription
url String The WebSocket route of the proxy with the id of the project (http is changed to ws).

Registers the tools App_* and opens a WebSocket to the proxy. The proxy sends the calls of the AI agent, and the tools run in the current process on the files of F.directory, as the user { id: 'ai', name: 'AI', sa: true }. Only the tools App_* can be called through this connection, not the other actions. The client connects again every 10 seconds when the connection is lost. The start option editmcp calls it in the watcher process.

Connect
const Remote = require('total5/remote');
Remote.mcp('https://proxy.example.com/$mcp/?id=shop');
method

Remote.proxy(socket)

Turns a WebSocket route into an MCP proxy.
ParameterTypeDescription
socket WebSocket The $ of the WebSocket route.

Call it in the action of a SOCKET route. It registers the tools App_* as MCP tools and forwards each call to the connected project whose ?id= is the same as the ?id= of the MCP endpoint. Without such a project the tools answer App is offline.; the calls that wait when a project disconnects end with Timeout. The proxy needs $mcp : true. It does not check who connects: protect the endpoint with Total.mcp.auth and check a token of the projects in the event open of the socket. Each connected and disconnected project is printed to the console.

The proxy
// config: $mcp : true
const Remote = require('total5/remote');

ROUTE('SOCKET /$mcp/ 10MB', function($) {

	$.on('open', function(client) {
		if (client.query.token !== CONF.remote_token)
			client.close(4001);
	});

	Remote.proxy($);
});

Total.mcp.auth = function($) {
	if ($.token && $.token === CONF.mcp_token)
		$.success({ id: 'agent', name: 'Agent' });
	else
		$.invalid();
};
method

Remote.tools()

Registers the actions App_* only.

Registers the actions once, without a connection. They are normal actions without mcp: true, so they are not in the list of the MCP server until you set it.

Two tools in your own MCP server
require('total5/remote').tools();

F.actions.App_read.mcp = true;
F.actions.App_search.mcp = true;
Total.mcp.refresh();
type

App_*

The tools for AI agents.
ToolWhat it does
App_infoThe name of the application, the versions and the platform
App_treeThe list of files and folders, without .git, tmp, the file storages and the start script
App_readThe content and the current revision of one or more files
App_writeCreates or replaces a file and saves its content as a new revision
App_restoreReturns the content of a saved revision; write it with App_write to use it
App_move, App_deleteMoves or deletes a file or a folder with its revisions (the root cannot be deleted)
App_mkdirCreates a folder
App_searchFinds a text in the .js, .html, .htm, .css, .md and .txt files, at most about 100 matches
App_logsThe last 4 kB of logs/debug.log (see $logger in Configuration)
App_shellRuns a shell command in the folder of the application
App_restartRestarts the application

The arguments go in input. Paths are relative to the root of the application, with or without the first slash. The tools report a problem with a file in the field error of their output.

ToolInputOutput
App_infoname, version, hostname, framework, node, platform, documentation
App_treeitems: [{ path, type, size, modified }], type is file or directory
App_readpathsitems: [{ path, error, content, revision }]
App_writepath, contentpath, revision, created
App_restorepath, revisioncontent, error
App_movefrom, tofrom, to, error, moved
App_deletepathpath, error, deleted
App_mkdirpathpath, error, created
App_searchsearchitems: [{ path, line, ch, text }], truncated
App_logsoutput, truncated
App_shellcmdresponse, error
App_restartsuccess

App_write saves each content as revisions/<hash>_<number>.rev; the numbers of the revisions are in databases/memorize_revisions.json.

A call
{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "App_read", "arguments": { "input": { "paths": ["/controllers/api.js"] } } } }
Made in Europe