# Expose your actions as MCP tools

> Mark a NEWACTION with mcp: true, enable CONF.$mcp and an AI client such as Claude can list and call it through the built-in POST /$mcp/ endpoint, with the schema generated from input, query, params and output.

Framework: total5
Product: Total.js 5 (total5@0.0.20)
Language: en
Content-SHA256: d05029ddeef3ec2b7e17d95e9a3d063f005afae4195f511befef6395382f6a25
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

Since Total.js 5 `0.0.20` the framework carries an **MCP server** (Model Context Protocol), so an AI client can use your application as a set of tools without a separate service. There is nothing to write apart from the actions you already have: add `mcp: true` to a `NEWACTION()` and set `CONF.$mcp = true`. The framework then answers `POST /$mcp/` (JSON-RPC 2.0) and keeps the list of tools up to date as actions are declared.

The tool schema is generated from the action. `input`, `query` and `params` become the sections of the arguments (`{ input: {}, query: {}, params: {} }`), `output` becomes the output schema, and the text after `//` in a field of the schema is the description the model reads and the message of a validation error. The name of the action is the name of the tool; characters that MCP does not allow become `_`, so `Notes/create` is the tool `Notes_create`. The description is `summary` or, when there is none, `name`.

```js definitions/notes.js
CONF.$mcp = true;

// The default allows every caller. Replace it with your own check before you publish the endpoint
Total.mcp.auth = function($) {
	if ($.token === 'secret')
		$.success({ id: 'ai', name: 'AI' });
	else
		$.invalid(401);
};

MAIN.notes = [];

NEWACTION('Notes/create', {
	name: 'Create a note',
	summary: 'Creates a note and returns it with its id',
	mcp: true,
	input: '*text:String // The text of the note',
	output: 'id:Number, text:String',
	action: function($, model) {
		const note = { id: MAIN.notes.length + 1, text: model.text };
		MAIN.notes.push(note);
		$.callback(note);
	}
});

NEWACTION('Notes/list', {
	name: 'List the notes',
	mcp: true,
	query: 'limit:Number // How many notes to return',
	action: function($) {
		$.callback(MAIN.notes.slice(0, $.query.limit || 10));
	}
});

// Without mcp: true an action is never offered to the AI
NEWACTION('Notes/clear', {
	name: 'Remove every note',
	action: function($) {
		MAIN.notes = [];
		$.success();
	}
});
```

`Total.mcp.auth` receives the options of an action: the bearer token of the request is in `$.token`, `$.success(user)` accepts the caller and `$.invalid()` answers `401`. The user of a tool call is always the same service user (`{ sa: true, name: 'AI' }`), so check the token here and not in the action. Tool errors, such as a failed validation, are returned inside the result with `isError: true` so that the model can read them and correct the call.
