Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import type { McpToolResult } from './types';
|
|
|
|
export class MessageFormatter {
|
|
static formatToolResult(result: unknown): McpToolResult {
|
|
if (typeof result === 'object' && result !== null) {
|
|
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
|
|
}
|
|
if (typeof result === 'string') {
|
|
return { content: [{ type: 'text', text: result }] };
|
|
}
|
|
if (result === null || result === undefined) {
|
|
return { content: [{ type: 'text', text: String(result) }] };
|
|
}
|
|
if (typeof result === 'number' || typeof result === 'boolean' || typeof result === 'bigint') {
|
|
return { content: [{ type: 'text', text: result.toString() }] };
|
|
}
|
|
// Remaining types: symbol, function - convert to string representation
|
|
return {
|
|
content: [
|
|
{ type: 'text', text: String(result as symbol | ((...args: unknown[]) => unknown)) },
|
|
],
|
|
};
|
|
}
|
|
|
|
static formatError(error: Error): McpToolResult {
|
|
const errorDetails = [`${error.name}: ${error.message}`];
|
|
if (error.stack) {
|
|
errorDetails.push(error.stack);
|
|
}
|
|
return {
|
|
isError: true,
|
|
content: [{ type: 'text', text: errorDetails.join('\n') }],
|
|
};
|
|
}
|
|
}
|