> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # Mastra.getToolById() `.getToolById()` メソッドは、最初に Mastra レベルのレジストリから固有の `id` が一致する Tool を検索します。一致する固有 ID がない場合は、指定された値を登録キーとして扱います。 ## 使用例 この例では、`weather` を登録キー、`weather-tool` を Tool 固有の ID として使用します。 ```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') ``` ## パラメーター **id** (`TTools[TToolName]['id']`): 検索する Tool 固有の ID。その ID を持つ Tool がない場合、Mastra はこの値を登録キーとして使用します。 ## 関連項目 - [Agent 間で Tool を共有](https://mastra.zisheng.pro/ja/docs/agents/using-tools) - [Mastra クラス](https://mastra.zisheng.pro/ja/reference/core/mastra-class) - [Mastra.getTool()](https://mastra.zisheng.pro/ja/reference/core/getTool) - [Mastra.listTools()](https://mastra.zisheng.pro/ja/reference/core/listTools)