(params: {
name: CommandName;
input: unknown;
result: unknown;
outputFormat: McpOutputFormat;
responseLevel?: ResponseLevel;
})
| 196 | } |
| 197 | |
| 198 | function renderToolText(params: { |
| 199 | name: CommandName; |
| 200 | input: unknown; |
| 201 | result: unknown; |
| 202 | outputFormat: McpOutputFormat; |
| 203 | responseLevel?: ResponseLevel; |
| 204 | }): string { |
| 205 | // A non-default responseLevel (digest/full) hands back a leveled payload whose |
| 206 | // shape the optimized CLI formatters do not understand (e.g. the snapshot |
| 207 | // formatter expects `nodes`, which the digest drops) — rendering it through |
| 208 | // them would print misleading text that contradicts `structuredContent`. Emit |
| 209 | // the leveled payload verbatim as JSON instead. |
| 210 | if ( |
| 211 | params.outputFormat === 'json' || |
| 212 | (params.responseLevel !== undefined && params.responseLevel !== 'default') |
| 213 | ) { |
| 214 | return renderJsonText(params.result); |
| 215 | } |
| 216 | const cliOutput = formatCliOutput({ |
| 217 | name: params.name, |
| 218 | input: params.input, |
| 219 | result: params.result, |
| 220 | }); |
| 221 | if (typeof cliOutput?.text === 'string') return cliOutput.text; |
| 222 | return renderJsonText(cliOutput?.data ?? params.result); |
| 223 | } |
| 224 | |
| 225 | function renderJsonText(value: unknown): string { |
| 226 | return typeof value === 'string' ? value : JSON.stringify(value, null, 2); |
no test coverage detected