MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / withErrorHandling

Function withErrorHandling

packages/mcp/src/tools/shared.ts:88–102  ·  view source on GitHub ↗
(
  fn: () => Promise<T>
)

Source from the content-addressed store, hash-verified

86 * Wrap a tool handler to catch errors and return them as MCP error content.
87 */
88export async function withErrorHandling<T>(
89 fn: () => Promise<T>
90): Promise<{ content: [{ type: 'text'; text: string }]; isError?: boolean }> {
91 try {
92 const result = await fn();
93 return toText(result);
94 } catch (err) {
95 const message = err instanceof Error ? err.message : String(err);
96 logger.error({ err }, `MCP tool error: ${message}`);
97 return {
98 content: [{ type: 'text' as const, text: `Error: ${message}` }],
99 isError: true,
100 };
101 }
102}

Callers 15

registerProjectToolsFunction · 0.90
registerGscOverviewToolsFunction · 0.90
registerGscPageToolsFunction · 0.90
registerGscQueryToolsFunction · 0.90
registerGroupToolsFunction · 0.90
registerUserFlowToolsFunction · 0.90
registerActiveUserToolsFunction · 0.90
registerEventToolsFunction · 0.90

Calls 3

fnFunction · 0.85
toTextFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected