getTool

View as MarkdownOpen in Claude

Look up a registered SwaigFunction on this service by name.

Parameters

name
stringRequired

The tool name to search for.

Returns

SwaigFunction | undefined — The SwaigFunction instance, or undefined if not found or not a SwaigFunction (e.g., a raw DataMap descriptor).

Example

1import { SWMLService } from '@signalwire/sdk';
2
3const service = new SWMLService({ name: 'swaig-host', route: '/' });
4service.defineTool({
5 name: 'get_weather',
6 description: 'Get the current weather',
7 parameters: { type: 'object', properties: { city: { type: 'string' } } },
8 handler: async (args) => ({ response: `Weather in ${args.city}: sunny` }),
9});
10
11const tool = service.getTool('get_weather');
12if (tool) {
13 console.log(tool.description); // "Get the current weather"
14}