MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / toMcpOutputResult

Function toMcpOutputResult

packages/hosts/mcp/src/tool-server.ts:570–594  ·  view source on GitHub ↗
(
  result: FormattedExecuteInput,
  output: readonly ExecuteOutputItem[],
)

Source from the content-addressed store, hash-verified

568};
569
570const toMcpOutputResult = (
571 result: FormattedExecuteInput,
572 output: readonly ExecuteOutputItem[],
573): McpToolResult => {
574 const formatted = formatExecuteResult(result);
575 const content = output.flatMap(outputItemContent);
576 const extraText: string[] = [];
577 if (result.error) {
578 extraText.push(formatted.text);
579 } else if (result.result != null) {
580 // A script may both emit() and return: keep the returned value in the
581 // content channel too, or clients that ignore structuredContent drop it.
582 // formatted.text already renders the return value plus any logs.
583 extraText.push(formatted.text);
584 } else if (result.logs && result.logs.length > 0) {
585 extraText.push(`Logs:\n${result.logs.join("\n")}`);
586 }
587 content.push(...extraText.map((text): ContentBlock => ({ type: "text", text })));
588
589 return {
590 content,
591 structuredContent: formatted.structured,
592 isError: formatted.isError || undefined,
593 };
594};
595
596const toMcpResult = (result: FormattedExecuteInput): McpToolResult => {
597 if (result.output && result.output.length > 0) return toMcpOutputResult(result, result.output);

Callers 1

toMcpResultFunction · 0.85

Calls 2

formatExecuteResultFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected