MCPcopy Index your code
hub / github.com/callstack/agent-device / renderToolText

Function renderToolText

src/mcp/command-tools.ts:198–223  ·  view source on GitHub ↗
(params: {
  name: CommandName;
  input: unknown;
  result: unknown;
  outputFormat: McpOutputFormat;
  responseLevel?: ResponseLevel;
})

Source from the content-addressed store, hash-verified

196}
197
198function 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
225function renderJsonText(value: unknown): string {
226 return typeof value === 'string' ? value : JSON.stringify(value, null, 2);

Callers 1

Calls 2

formatCliOutputFunction · 0.90
renderJsonTextFunction · 0.85

Tested by

no test coverage detected