mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 03:26:07 +00:00
7283b75cac
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.
70 lines
2.1 KiB
TypeScript
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;
|