MCPcopy
hub / github.com/subquery/subql / withStructuredResponse

Function withStructuredResponse

packages/cli/src/adapters/utils.ts:415–448  ·  view source on GitHub ↗
(
  p: (input: I, meta: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<O>
)

Source from the content-addressed store, hash-verified

413 * @returns
414 */
415export function withStructuredResponse<I, O>(
416 p: (input: I, meta: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<O>
417): (input: I, meta: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<CallToolResult> {
418 return async (i, meta) => {
419 try {
420 const result = await p(i, meta);
421
422 return {
423 structuredContent: {
424 result,
425 },
426 content: [
427 {
428 type: 'text',
429 text: JSON.stringify(result, null, 2),
430 },
431 ],
432 };
433 } catch (e: any) {
434 return {
435 isError: true,
436 structuredContent: {
437 error: formatErrorCauses(e as Error),
438 },
439 content: [
440 {
441 type: 'text',
442 text: `Error running: ${formatErrorCauses(e)}`,
443 },
444 ],
445 };
446 }
447 };
448}
449
450export type MCPToolOptions = {
451 /**

Calls 2

pFunction · 0.85
formatErrorCausesFunction · 0.85

Tested by

no test coverage detected