# Beschrijf een functie voor een AI-model met een JSON-schema

> Zet een compact Total.js-schema om in de tool- of objectdefinitie die een AI-model verwacht, met toAITool() en toAIObject(), en laat een actie haar eigen MCP-tool maken.

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

Het compacte schema dat je al voor `input` schrijft (`'*name:String // The name, age:Number'`) is genoeg om een functie aan een AI-model te beschrijven. `0.0.20` voegt drie omzettingen toe:

| Aanroep | Resultaat |
|---|---|
| `'<schema>'.toJSONSchema().toAITool(name)` | Een functiedefinitie in de vorm van de chat-API's: `{ type: 'function', function: { name, description, parameters } }` |
| `'<schema>'.toJSONSchema().toAIObject(name, description)` | Een JSON Schema-object met `name`, `description`, `properties` en `required`, om het model om gestructureerde uitvoer te vragen |
| `Total.actions['Name'].toAITool()` | De MCP-tool van een actie (naam, beschrijving, `inputSchema` en `outputSchema`) |

De tekst na `//` in een veld wordt zijn `description`, en dat leest het model om te beslissen wat het invult. Een veld met `*` komt in `required`. Stuur de invoer van een gebruiker niet als instructie naar een model: het schema beschrijft alleen de vorm van de argumenten.

```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 });
	}
});
```
