본문으로 건너뛰기

마스트라.getToolById()

그만큼.getToolById()메서드는 먼저 Mastra 수준 레지스트리에서 일치하는 내장 항목이 있는 Tool을 검색합니다.id. 일치하는 고유 ID가 없으면 값을 등록 키로 처리합니다.

사용예
사용예에 대한 직접 링크

이 예제에서는 weather를 등록 키로 사용하고 weather-tool을 Tool 자체의 ID로 사용합니다.

src/mastra/index.ts
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는 이 값을 등록 키로 사용합니다.