Spanish Total.js
English
Documentation For AI agents
Contents

Remote access

Work on the files of a project from the Total.js Code Editor or with an AI agent through an MCP proxy.

.md GitHub
On this page

Total.js 5 can give a remote program access to the files of a project: the Total.js Code Editor, where a person works, or an AI agent that speaks MCP. The project opens the connection itself with a WebSocket, so it works behind a firewall and without an open port.

Both ways can read and change every file of the project and run commands on its computer. Connect only to a server you trust, over https, and turn the access off when you do not need it.

The functions and tools are in the reference.

The Code Editor

The editor gives you the URL of the project. Put it into the start options:

require('total5');
F.run({ edit: 'https://code.example.com/?id=shop' });

http is changed to ws and https to wss. When the editor accepts the project, the console shows it:

> Total.js Code Editor: Welcome to "Code (1.0)"
> Project: "shop"

The client connects again every 10 seconds when the connection is lost, also after the answers 404 project not found and 409 project is already open.

The editor can browse, load, save, create, rename, remove, upload and download files, read and clear the logs and restart the application. It can also run a file on the computer of the project: a .js file with Node.js, a .sh file with sh, or with a command that the editor sends. In debug mode the watcher restarts the application after each saved file.

In debug mode the client runs in the watcher process, so you can still repair the application when it does not start. In release mode it runs only when the application is started with --watcher.

An AI agent

An agent does not connect to the project but to an MCP proxy: a Total.js application of yours on a public address. The project connects to the same proxy, and the proxy sends the calls of the agent to it.

The proxy

The proxy needs $mcp (see MCP server), one WebSocket route and two secrets, one for the agent and one for the projects:

# config
name         : Proxy
$mcp         : true
mcp_token    : a-long-secret-for-the-agent
remote_token : a-long-secret-for-the-projects
// definitions/mcp.js
Total.mcp.auth = function($) {
    if ($.token && $.token === CONF.mcp_token)
        $.success({ id: 'agent', name: 'Agent' });
    else
        $.invalid();
};
// controllers/remote.js
const Remote = require('total5/remote');

exports.install = function() {
    ROUTE('SOCKET /$mcp/ 10MB', function($) {

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

        Remote.proxy($);
    });
};

Without Total.mcp.auth anybody who knows the address can run commands in your projects, and without the check in the route anybody can connect as your project. 10MB is the limit of one message, so the agent can read big files.

The project

require('total5');
F.run({ editmcp: 'https://proxy.example.com/$mcp/?id=shop&token=a-long-secret-for-the-projects' });

id is a name that you choose for the project. The client runs in the watcher, so it works only in debug mode, and it connects again every 10 seconds when the connection is lost. When edit is set too, edit is used.

The agent

The agent connects to the MCP endpoint of the proxy with the same id, https://proxy.example.com/$mcp/?id=shop, and with the token in the Authorization header. It gets these tools:

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

Paths are relative to the root of the application, with or without the first slash. The revisions are in the folder revisions of the project. When no project with that id is connected, every tool answers App is offline..

Without starting the application

The command line connects the current folder without running the application (see Command line):

cd ~/projects/shop
total5 edit "https://code.example.com/?id=shop"
total5 mcp 'https://proxy.example.com/$mcp/?id=shop&token=a-long-secret-for-the-projects'

The tools in your own application

Remote.tools() registers the actions App_* without any connection. They are not MCP tools until you set mcp on them, so an application with its own MCP server can offer only the ones that you choose:

// definitions/mcp.js
require('total5/remote').tools();

for (const name of ['App_tree', 'App_read', 'App_search'])
    F.actions[name].mcp = true;

Total.mcp.refresh();

App_read reads every file of the application, config included, so protect the endpoint with Total.mcp.auth here too.

Made in Europe