MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / toVercelAITool

Function toVercelAITool

packages/web/src/features/tools/adapters.ts:7–35  ·  view source on GitHub ↗
(
    def: ToolDefinition<TName, TShape, TMetadata>,
    context: ToolContext,
)

Source from the content-addressed store, hash-verified

5import { ToolContext, ToolDefinition } from "./types";
6
7export function toVercelAITool<TName extends string, TShape extends z.ZodRawShape, TMetadata>(
8 def: ToolDefinition<TName, TShape, TMetadata>,
9 context: ToolContext,
10) {
11 return tool({
12 description: def.description,
13 inputSchema: def.inputSchema,
14 title: def.title,
15 execute: async (input) => {
16 let success = true;
17 try {
18 return await def.execute(input, context);
19 } catch (error) {
20 success = false;
21 throw error;
22 } finally {
23 captureEvent('tool_used', {
24 toolName: def.name,
25 source: context.source ?? 'unknown',
26 success,
27 });
28 }
29 },
30 toModelOutput: ({ output }) => ({
31 type: "content",
32 value: [{ type: "text", text: output.output }],
33 }),
34 });
35}
36
37export function registerMcpTool<TName extends string, TShape extends z.ZodRawShape, TMetadata>(
38 server: McpServer,

Callers 1

createToolsFunction · 0.90

Calls 1

captureEventFunction · 0.90

Tested by

no test coverage detected