MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / convertMCPContentBlock

Function convertMCPContentBlock

packages/agent-core/src/mcp/output.ts:71–140  ·  view source on GitHub ↗
(block: MCPContentBlock)

Source from the content-addressed store, hash-verified

69 * resource shapes) so the caller can drop them.
70 */
71export function convertMCPContentBlock(block: MCPContentBlock): ContentPart | null {
72 if (block.type === 'text' && typeof block.text === 'string') {
73 return { type: 'text', text: block.text };
74 }
75
76 if (block.type === 'image' && typeof block.data === 'string') {
77 const mimeType = block.mimeType ?? 'image/png';
78 return {
79 type: 'image_url',
80 imageUrl: { url: `data:${mimeType};base64,${block.data}` },
81 };
82 }
83
84 if (block.type === 'audio' && typeof block.data === 'string') {
85 const mimeType = block.mimeType ?? 'audio/mpeg';
86 return {
87 type: 'audio_url',
88 audioUrl: { url: `data:${mimeType};base64,${block.data}` },
89 };
90 }
91
92 // EmbeddedResource: payload is nested under `resource`, as
93 // TextResourceContents (`text`) or BlobResourceContents (`blob`).
94 if (block.type === 'resource' && typeof block.resource === 'object' && block.resource !== null) {
95 const res = block.resource;
96 if (typeof res.text === 'string') {
97 return { type: 'text', text: res.text };
98 }
99 if (typeof res.blob === 'string') {
100 const mimeType = res.mimeType ?? 'application/octet-stream';
101 if (mimeType.startsWith('image/')) {
102 return {
103 type: 'image_url',
104 imageUrl: { url: `data:${mimeType};base64,${res.blob}` },
105 };
106 }
107 if (mimeType.startsWith('audio/')) {
108 return {
109 type: 'audio_url',
110 audioUrl: { url: `data:${mimeType};base64,${res.blob}` },
111 };
112 }
113 if (mimeType.startsWith('video/')) {
114 return {
115 type: 'video_url',
116 videoUrl: { url: `data:${mimeType};base64,${res.blob}` },
117 };
118 }
119 return null;
120 }
121 return null;
122 }
123
124 // ResourceLink: URL reference, not an inline blob.
125 if (block.type === 'resource_link' && typeof block.uri === 'string') {
126 const mimeType = block.mimeType ?? 'application/octet-stream';
127 if (mimeType.startsWith('image/')) {
128 return { type: 'image_url', imageUrl: { url: block.uri } };

Callers 2

output.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected