> Discover all available pages from the documentation index: https://mastra.zisheng.pro/fr/llms.txt # Mastra.getToolById() La méthode `.getToolById()` recherche d’abord dans le registre au niveau de Mastra un Tool dont l’`id` intrinsèque correspond. Si aucun ID intrinsèque ne correspond, elle traite la valeur comme une clé d’enregistrement. ## Exemple d’utilisation Cet exemple utilise `weather` comme clé d’enregistrement et `weather-tool` comme ID intrinsèque du Tool. ```typescript import { Mastra } from '@mastra/core/mastra' import { createTool } from '@mastra/core/tools' import { z } from 'zod' const weatherTool = createTool({ id: 'weather-tool', description: 'Fetches weather for a location', inputSchema: z.object({ location: z.string(), }), outputSchema: z.object({ weather: z.string(), }), execute: async ({ location }) => ({ weather: `Weather for ${location}`, }), }) export const mastra = new Mastra({ tools: { weather: weatherTool, }, }) const toolById = mastra.getToolById('weather-tool') ``` ## Paramètres **id** (`TTools[TToolName]['id']`): ID intrinsèque du Tool à rechercher. Lorsqu’aucun Tool n’a cet ID, Mastra utilise la valeur comme clé d’enregistrement. ## Voir aussi - [Partager des Tools entre les agents](https://mastra.zisheng.pro/fr/docs/agents/using-tools) - [Classe Mastra](https://mastra.zisheng.pro/fr/reference/core/mastra-class) - [Mastra.getTool()](https://mastra.zisheng.pro/fr/reference/core/getTool) - [Mastra.listTools()](https://mastra.zisheng.pro/fr/reference/core/listTools)