# Describe a function for an AI model with a JSON schema

> Turn a compact Total.js schema into the tool or the object definition that an AI model expects, with toAITool() and toAIObject(), and let an action produce its own MCP tool.

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

The compact schema that you already write for `input` (`'*name:String // The name, age:Number'`) is enough to describe a function to an AI model. `0.0.20` adds three conversions:

| Call | Result |
|---|---|
| `'<schema>'.toJSONSchema().toAITool(name)` | A function definition in the shape of the chat APIs: `{ type: 'function', function: { name, description, parameters } }` |
| `'<schema>'.toJSONSchema().toAIObject(name, description)` | A JSON Schema object with `name`, `description`, `properties` and `required`, to ask the model for structured output |
| `Total.actions['Name'].toAITool()` | The MCP tool of an action (name, description, `inputSchema` and `outputSchema`) |

The text after `//` in a field becomes its `description`, which is what the model reads to decide what to put there. A field marked `*` goes into `required`. Do not send user input to a model as an instruction: the schema only describes the shape of the arguments.

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