MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / buildGetCodeToolResult

Function buildGetCodeToolResult

packages/shared/src/mcp/responses.ts:31–54  ·  view source on GitHub ↗
(payload: GetCodeResult)

Source from the content-addressed store, hash-verified

29}
30
31export function utf8Bytes(value: unknown): number {
32 const serialized =
33 typeof value === 'string' ? value : (JSON.stringify(value, null, 0) ?? 'undefined')
34 return ENCODER.encode(serialized).length
35}
36
37export function measureCallToolResultBytes(result: ToolResponseLike): number {
38 return utf8Bytes(result)
39}
40
41export function buildGetCodeToolResult(payload: GetCodeResult): ToolResponseLike {
42 const summary: string[] = []
43 const codeSize = utf8Bytes(payload.code)
44 summary.push(`Generated \`${payload.lang}\` snippet (${formatBytes(codeSize)}).`)
45
46 if (payload.warnings?.length) {
47 summary.push(...payload.warnings.map((warning) => warning.message))
48 }
49
50 summary.push(
51 payload.assets?.length
52 ? `Assets attached: ${payload.assets.length}. Use asset.localPath directly when present; otherwise download asset.url.`
53 : 'No binary assets were attached to this response.'
54 )
55
56 const tokenCount = payload.tokens ? Object.keys(payload.tokens).length : 0
57 if (tokenCount) {

Callers 3

responses.test.tsFile · 0.90
createCodeToolResponseFunction · 0.90
handleGetCodeFunction · 0.90

Calls 3

utf8BytesFunction · 0.85
formatBytesFunction · 0.85
buildTextToolResultFunction · 0.85

Tested by

no test coverage detected