Files
TREK/server/src/nest-mcp/helpers.ts
T
Maurice 7283b75cac feat(mcp): list_collection_places pages a long list compactly (#2647)
A read tool that answers one list a page at a time (100 by default, up to
500) as compact one-line JSON rows, filtered by status, label or "no label",
with the list's labels, the matching total and a cursor. The cursor is the
last place's position (sort_order, created_at, id), so labelling a page
while paging through unlabelled places skips none. getCollection orders by
the same keys, id last, so both tools agree on ties.
2026-11-13 10:17:11 +01:00

70 lines
2.1 KiB
TypeScript

/**
* Result-shape helpers and tool-annotation presets shared by MCP handlers.
* App-agnostic on purpose — host-specific canned errors (permission wording,
* RBAC lookups, broadcasts) belong in the host, built on `errorResult`.
*/
/** The text-content result shape MCP tool handlers return. */
export interface McpTextResult {
content: { type: 'text'; text: string }[];
isError?: boolean;
}
/** Success result: `data` pretty-printed as a single JSON text block. */
export function ok(data: unknown): McpTextResult {
return { content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }] };
}
/** Success result: `data` as one line of JSON, for an answer whose size matters more than how it reads (a page of a long list). */
export function okCompact(data: unknown): McpTextResult {
return { content: [{ type: 'text' as const, text: JSON.stringify(data) }] };
}
/** Error result with a verbatim message (no formatting, no prefix). */
export function errorResult(text: string): McpTextResult {
return { content: [{ type: 'text' as const, text }], isError: true };
}
/** Canned refusal for write tools when the acting user is a demo account. */
export function demoDenied(): McpTextResult {
return errorResult('Write operations are disabled in demo mode.');
}
export const TOOL_ANNOTATIONS_READONLY = {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
} as const;
export const TOOL_ANNOTATIONS_OPEN_WORLD_READONLY = {
...TOOL_ANNOTATIONS_READONLY,
openWorldHint: true,
} as const;
export const TOOL_ANNOTATIONS_WRITE = {
readOnlyHint: false,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
} as const;
export const TOOL_ANNOTATIONS_DELETE = {
readOnlyHint: false,
destructiveHint: true,
idempotentHint: true,
openWorldHint: false,
} as const;
export const TOOL_ANNOTATIONS_NON_IDEMPOTENT = {
readOnlyHint: false,
destructiveHint: false,
idempotentHint: false,
openWorldHint: false,
} as const;
export const TOOL_ANNOTATIONS_OPEN_WORLD_NON_IDEMPOTENT = {
...TOOL_ANNOTATIONS_NON_IDEMPOTENT,
openWorldHint: true,
} as const;