UNPKG

touchdesigner-mcp-server

Version:
67 lines (66 loc) 1.92 kB
/** * Response Formatter Utilities * * Provides token-optimized formatting for MCP tool responses. * Based on the design document: docs/context-optimization-design.md */ /** * Common formatting options */ import { presentStructuredData } from "./presenter.js"; /** * Default formatter options */ export const DEFAULT_FORMATTER_OPTIONS = { detailLevel: "summary", includeHints: true, limit: undefined, responseFormat: undefined, }; /** * Merge user options with defaults */ export function mergeFormatterOptions(options) { const merged = { ...DEFAULT_FORMATTER_OPTIONS, ...options }; const detailLevel = options?.detailLevel ?? options?.mode ?? DEFAULT_FORMATTER_OPTIONS.detailLevel; return { detailLevel, includeHints: merged.includeHints ?? true, limit: merged.limit, responseFormat: merged.responseFormat, }; } export function finalizeFormattedText(text, opts, metadata) { const chosenFormat = opts.responseFormat ?? (opts.detailLevel === "detailed" ? "yaml" : "markdown"); return presentStructuredData({ context: metadata?.context, detailLevel: opts.detailLevel, structured: metadata?.structured, template: metadata?.template, text, }, chosenFormat); } /** * Format a hint message for omitted content */ export function formatOmissionHint(totalCount, shownCount, itemType) { const omitted = totalCount - shownCount; if (omitted <= 0) return ""; return `\n💡 ${omitted} more ${itemType}(s) omitted. Use detailLevel='detailed' or increase limit to see all.`; } /** * Truncate array based on limit option */ export function limitArray(items, limit) { if (limit === undefined || limit >= items.length) { return { items, truncated: false }; } return { items: items.slice(0, limit), truncated: true, }; }