-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathtool.ts
More file actions
57 lines (52 loc) · 1.72 KB
/
tool.ts
File metadata and controls
57 lines (52 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { VapiClient, Vapi } from '@vapi-ai/server-sdk';
import { GetToolInputSchema, CreateToolInputSchema, UpdateToolInputSchema } from '../schemas/index.js';
import { transformToolInput, transformUpdateToolInput, transformToolOutput } from '../transformers/index.js';
import { createToolHandler } from './utils.js';
export const registerToolTools = (
server: McpServer,
getClient: () => VapiClient
) => {
server.tool(
'list_tools',
'Lists all Vapi tools',
{},
createToolHandler(async () => {
const vapiClient = getClient();
const tools = await vapiClient.tools.list({ limit: 10 });
return tools.map(transformToolOutput);
})
);
server.tool(
'get_tool',
'Gets details of a specific tool',
GetToolInputSchema.shape,
createToolHandler(async (data) => {
const vapiClient = getClient();
const tool = await vapiClient.tools.get(data.toolId);
return transformToolOutput(tool);
})
);
server.tool(
'create_tool',
'Creates a new Vapi tool',
CreateToolInputSchema.shape,
createToolHandler(async (data) => {
const vapiClient = getClient();
const createToolDto = transformToolInput(data);
const tool = await vapiClient.tools.create(createToolDto);
return transformToolOutput(tool);
})
);
server.tool(
'update_tool',
'Updates an existing Vapi tool',
UpdateToolInputSchema.shape,
createToolHandler(async (data) => {
const vapiClient = getClient();
const updateToolDto = transformUpdateToolInput(data);
const tool = await vapiClient.tools.update(data.toolId, updateToolDto);
return transformToolOutput(tool);
})
);
};