MCPcopy Index your code
hub / github.com/codeaashu/claude-code / transformMCPResult

Function transformMCPResult

src/services/mcp/client.ts:2662–2706  ·  view source on GitHub ↗
(
  result: unknown,
  tool: string, // Tool name for validation (e.g., "search")
  name: string, // Server name for transformation (e.g., "slack")
)

Source from the content-addressed store, hash-verified

2660}
2661
2662export async function transformMCPResult(
2663 result: unknown,
2664 tool: string, // Tool name for validation (e.g., "search")
2665 name: string, // Server name for transformation (e.g., "slack")
2666): Promise<TransformedMCPResult> {
2667 if (result && typeof result === 'object') {
2668 if ('toolResult' in result) {
2669 return {
2670 content: String(result.toolResult),
2671 type: 'toolResult',
2672 }
2673 }
2674
2675 if (
2676 'structuredContent' in result &&
2677 result.structuredContent !== undefined
2678 ) {
2679 return {
2680 content: jsonStringify(result.structuredContent),
2681 type: 'structuredContent',
2682 schema: inferCompactSchema(result.structuredContent),
2683 }
2684 }
2685
2686 if ('content' in result && Array.isArray(result.content)) {
2687 const transformedContent = (
2688 await Promise.all(
2689 result.content.map(item => transformResultContent(item, name)),
2690 )
2691 ).flat()
2692 return {
2693 content: transformedContent,
2694 type: 'contentArray',
2695 schema: inferCompactSchema(transformedContent),
2696 }
2697 }
2698 }
2699
2700 const errorMessage = `MCP server "${name}" tool "${tool}": unexpected response format`
2701 logMCPError(name, errorMessage)
2702 throw new TelemetrySafeError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS(
2703 errorMessage,
2704 'MCP tool unexpected response format',
2705 )
2706}
2707
2708/**
2709 * Check if MCP content contains any image blocks.

Callers 1

processMCPResultFunction · 0.85

Calls 4

jsonStringifyFunction · 0.85
inferCompactSchemaFunction · 0.85
transformResultContentFunction · 0.85
logMCPErrorFunction · 0.85

Tested by

no test coverage detected