Remote access
require('total5/remote'): the client of the Code Editor, the MCP proxy and the tools App_* for AI agents.
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.
require('total5/remote')Returns Object The module.
The module exports edit(), mcp(), proxy() and tools(). Loading it registers nothing.
const Remote = require('total5/remote');
method
Remote.edit(url, [directory])
Connects a folder to the Total.js Code Editor.
Remote.edit(url, [directory])| Parameter | Type | Description |
|---|---|---|
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.
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.
F.remote(url, [directory])| Parameter | Type | Description |
|---|---|---|
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.
F.remote('wss://code.example.com/?id=myproject');
method
Remote.mcp(url)
Connects the application to an MCP proxy.
Remote.mcp(url)| Parameter | Type | Description |
|---|---|---|
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.
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.
Remote.proxy(socket)| Parameter | Type | Description |
|---|---|---|
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.
// 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.
Remote.tools()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.
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.
App_*| Tool | What it does |
|---|---|
App_info | The name of the application, the versions and the platform |
App_tree | The list of files and folders, without .git, tmp, the file storages and the start script |
App_read | The content and the current revision of one or more files |
App_write | Creates or replaces a file and saves its content as a new revision |
App_restore | Returns the content of a saved revision; write it with App_write to use it |
App_move, App_delete | Moves or deletes a file or a folder with its revisions (the root cannot be deleted) |
App_mkdir | Creates a folder |
App_search | Finds a text in the .js, .html, .htm, .css, .md and .txt files, at most about 100 matches |
App_logs | The last 4 kB of logs/debug.log (see $logger in Configuration) |
App_shell | Runs a shell command in the folder of the application |
App_restart | Restarts 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.
| Tool | Input | Output |
|---|---|---|
App_info | name, version, hostname, framework, node, platform, documentation | |
App_tree | items: [{ path, type, size, modified }], type is file or directory | |
App_read | paths | items: [{ path, error, content, revision }] |
App_write | path, content | path, revision, created |
App_restore | path, revision | content, error |
App_move | from, to | from, to, error, moved |
App_delete | path | path, error, deleted |
App_mkdir | path | path, error, created |
App_search | search | items: [{ path, line, ch, text }], truncated |
App_logs | output, truncated | |
App_shell | cmd | response, error |
App_restart | success |
App_write saves each content as revisions/<hash>_<number>.rev; the numbers of the revisions are in databases/memorize_revisions.json.
{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "App_read", "arguments": { "input": { "paths": ["/controllers/api.js"] } } } }