in packages/mcp-client/src/ResultFormatter.ts [20:73]
static format(result: CompatibilityCallToolResult): string {
if (!result.content || !Array.isArray(result.content) || result.content.length === 0) {
return "[No content]";
}
const formattedParts: string[] = [];
for (const item of result.content) {
switch (item.type) {
case "text":
// Extract text content directly
formattedParts.push(item.text);
break;
case "image": {
// Summarize image content
const imageSize = this.getBase64Size(item.data);
formattedParts.push(
`[Binary Content: Image ${item.mimeType}, ${imageSize} bytes]\nThe task is complete and the content accessible to the User`
);
break;
}
case "audio": {
// Summarize audio content
const audioSize = this.getBase64Size(item.data);
formattedParts.push(
`[Binary Content: Audio ${item.mimeType}, ${audioSize} bytes]\nThe task is complete and the content accessible to the User`
);
break;
}
case "resource":
// Handle embedded resources - explicitly type the resource
if ("text" in item.resource) {
// It's a text resource with a text property
const textResource = item.resource as TextResourceContents;
formattedParts.push(textResource.text);
} else if ("blob" in item.resource) {
// It's a binary resource with a blob property
const blobResource = item.resource as BlobResourceContents;
const blobSize = this.getBase64Size(blobResource.blob);
const uri = blobResource.uri ? ` (${blobResource.uri})` : "";
const mimeType = blobResource.mimeType ? blobResource.mimeType : "unknown type";
formattedParts.push(
`[Binary Content${uri}: ${mimeType}, ${blobSize} bytes]\nThe task is complete and the content accessible to the User`
);
}
break;
}
}
return formattedParts.join("\n");
}