MCPcopy
hub / github.com/mobile-next/mobile-mcp / tool

Function tool

src/server.ts:71–104  ·  view source on GitHub ↗
(name: string, title: string, description: string, paramsSchema: ZodSchemaShape, annotations: ToolAnnotations, cb: (args: any) => Promise<string>)

Source from the content-addressed store, hash-verified

69 }
70
71 const tool = (name: string, title: string, description: string, paramsSchema: ZodSchemaShape, annotations: ToolAnnotations, cb: (args: any) => Promise<string>) => {
72 server.registerTool(name, {
73 title,
74 description,
75 inputSchema: paramsSchema,
76 annotations,
77 }, (async (args: any, _extra: any) => {
78 try {
79 trace(`Invoking ${name} with args: ${JSON.stringify(args)}`);
80 const start = +new Date();
81 const response = await cb(args);
82 const duration = +new Date() - start;
83 trace(`=> ${response}`);
84 posthog("tool_invoked", { "ToolName": name, "Duration": duration }).then();
85 return {
86 content: [{ type: "text", text: response }],
87 };
88 } catch (error: any) {
89 posthog("tool_failed", { "ToolName": name }).then();
90 if (error instanceof ActionableError) {
91 return {
92 content: [{ type: "text", text: `${error.message}. Please fix the issue and try again.` }],
93 };
94 } else {
95 // a real exception
96 trace(`Tool '${description}' failed: ${error.message} stack: ${error.stack}`);
97 return {
98 content: [{ type: "text", text: `Error: ${error.message}` }],
99 isError: true,
100 };
101 }
102 }
103 }) as any);
104 };
105
106 const posthog = async (event: string, properties: Record<string, string | number>) => {
107 if (process.env.MOBILEMCP_DISABLE_TELEMETRY) {

Callers 1

createMcpServerFunction · 0.85

Calls 2

traceFunction · 0.90
posthogFunction · 0.85

Tested by

no test coverage detected