# Descrivi una funzione a un modello IA con uno schema JSON

> Trasforma uno schema compatto di Total.js nello strumento o nella definizione di oggetto che un modello IA si aspetta, con toAITool() e toAIObject(), e lascia che un'azione produca il proprio strumento MCP.

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

Lo schema compatto che scrivi già per `input` (`'*name:String // The name, age:Number'`) basta per descrivere una funzione a un modello IA. `0.0.20` aggiunge tre conversioni:

| Chiamata | Risultato |
|---|---|
| `'<schema>'.toJSONSchema().toAITool(name)` | Una definizione di funzione nel formato delle API di chat: `{ type: 'function', function: { name, description, parameters } }` |
| `'<schema>'.toJSONSchema().toAIObject(name, description)` | Un oggetto JSON Schema con `name`, `description`, `properties` e `required`, per chiedere al modello un output strutturato |
| `Total.actions['Name'].toAITool()` | Lo strumento MCP di un'azione (nome, descrizione, `inputSchema` e `outputSchema`) |

Il testo dopo `//` in un campo diventa la sua `description`, che è ciò che il modello legge per decidere cosa inserirvi. Un campo contrassegnato con `*` va in `required`. Non inviare a un modello l'input di un utente come se fosse un'istruzione: lo schema descrive soltanto la forma degli argomenti.

```js controllers/tools.js
exports.install = function() {
	ROUTE('GET /tool/', tool);
	ROUTE('GET /object/', object);
	ROUTE('GET /action/', action);
};

const SCHEMA = '*city:String // The name of the city, unit:String // celsius or fahrenheit';

function tool($) {
	$.json(SCHEMA.toJSONSchema().toAITool('weather'));
}

function object($) {
	$.json(SCHEMA.toJSONSchema().toAIObject('weather', 'The weather of a city'));
}

function action($) {
	$.json(Total.actions['Weather/get'].toAITool());
}
```

```js definitions/weather.js
NEWACTION('Weather/get', {
	name: 'Get the weather',
	summary: 'Returns the weather of a city',
	input: '*city:String // The name of the city',
	action: function($, model) {
		$.callback({ city: model.city, temperature: 21 });
	}
});
```
