fix(mcp): describe day-note title and body and allow the planner's 2000-character body

create_day_note and update_day_note described `time` as a clock label and capped
it at 250 characters, while the planner shows it as the Markdown body under the
title and allows 2000. The assistant put long text in the title and had to cut
notes it was asked to edit. Both tools now take text and time from the REST
contract with descriptions naming title and body, and an update still refuses an
empty title. The assistant's change card labels the two fields title and content
instead of text and time.

Closes #2840
This commit is contained in:
Maurice
2026-10-27 14:38:30 +01:00
parent 35fb59e64e
commit 0f0232491b
35 changed files with 169 additions and 20 deletions
@@ -440,6 +440,8 @@ export const CHANGE_LABELS: Record<AssistantChangeLabelKey, { labelKey: string }
currency: { labelKey: 'assistant.change.label.currency' },
stopType: { labelKey: 'assistant.change.label.stopType' },
text: { labelKey: 'assistant.change.label.text' },
title: { labelKey: 'assistant.change.label.title' },
content: { labelKey: 'assistant.change.label.content' },
icon: { labelKey: 'assistant.change.label.icon' },
color: { labelKey: 'assistant.change.label.color' },
position: { labelKey: 'assistant.change.label.position' },
+1 -1
View File
@@ -7,7 +7,7 @@
"src/nest/budget/budget.mcp.ts": 36,
"src/nest/collab/collab.mcp.ts": 20,
"src/nest/collections/collections.mcp.ts": 14,
"src/nest/day-notes/day-notes.mcp.ts": 10,
"src/nest/day-notes/day-notes.mcp.ts": 6,
"src/nest/days/days.mcp.ts": 2,
"src/nest/doc-sync/doc-sync.mcp.ts": 1,
"src/nest/files/files.mcp.ts": 4,
@@ -195,7 +195,7 @@ const DESCRIBERS: Readonly<Record<string, Describer>> = {
const dayId = id(args, 'dayId');
const rows = new Rows()
.add('day', dayLabel(ctx, dayId))
.add('time', text(args.time))
.add('content', text(args.time))
.add('icon', text(args.icon))
.add('color', text(args.color));
return { subject: text(args.text), rows, dayId, placeIds: [] };
@@ -203,8 +203,8 @@ const DESCRIBERS: Readonly<Record<string, Describer>> = {
update_day_note: (ctx, args) => {
const note = ctx.card.notes.get(id(args, 'noteId') ?? 0);
const rows = new Rows();
if (has(args, 'text')) rows.change('text', note?.text ?? null, text(args.text));
if (has(args, 'time')) rows.change('time', note?.time ?? null, text(args.time));
if (has(args, 'text')) rows.change('title', note?.text ?? null, text(args.text));
if (has(args, 'time')) rows.change('content', note?.time ?? null, text(args.time));
if (has(args, 'icon')) rows.change('icon', note?.icon ?? null, text(args.icon));
if (has(args, 'color')) rows.change('color', note?.color ?? null, text(args.color));
return { subject: note?.text ?? text(args.text), rows, dayId: id(args, 'dayId'), placeIds: [] };
+27 -13
View File
@@ -11,7 +11,13 @@ import {
} from '../../nest-mcp';
import { McpToolGuardsService } from '../mcp-shared/mcp-tool-guards.service';
import { DayNotesService } from './day-notes.service';
import { idSchema, NOTE_COLORS, type NoteColor } from '@trek/shared';
import {
dayNoteCreateRequestSchema,
dayNoteUpdateRequestSchema,
idSchema,
NOTE_COLORS,
type NoteColor,
} from '@trek/shared';
import { z } from 'zod';
@@ -23,6 +29,18 @@ import { z } from 'zod';
*/
const noteColorSchema = z.enum(NOTE_COLORS);
/**
* The note's two text fields carry their names from the time a note was a line
* with a clock time: `text` is the heading and `time` the Markdown body under it.
* The REST contract holds the bounds, so a note written in the planner can always
* be edited here; the descriptions are what tells a model which field is which.
*/
const NOTE_TITLE = 'The note title, shown as its heading in the day plan. Keep it short';
const NOTE_BODY =
'The note body shown under the title: details, links, reminders, Markdown allowed. ' +
'Despite the field name this is the content, not a clock time';
const noteTitleSchema = dayNoteCreateRequestSchema.shape.text.describe(NOTE_TITLE);
function parseId(value: string | string[]): number | null {
const n = Number(Array.isArray(value) ? value[0] : value);
return Number.isInteger(n) && n > 0 ? n : null;
@@ -52,12 +70,12 @@ export class DayNotesMcp {
@Tool({
name: 'create_day_note',
description: 'Add a note to a specific day in a trip.',
description: 'Add a note to a specific day in a trip: a title in `text` and its body in `time`.',
inputSchema: {
tripId: idSchema,
dayId: idSchema,
text: z.string().min(1).max(500),
time: z.string().max(250).optional().describe('Time label (e.g. "09:00" or "Morning")'),
text: noteTitleSchema,
time: dayNoteCreateRequestSchema.shape.time.describe(NOTE_BODY),
icon: z.string().max(64).optional().describe('Emoji icon for the note'),
color: noteColorSchema
.nullable()
@@ -86,7 +104,7 @@ export class DayNotesMcp {
tripId: number;
dayId: number;
text: string;
time?: string;
time?: string | null;
icon?: string;
color?: NoteColor | null;
sort_order?: number;
@@ -104,18 +122,14 @@ export class DayNotesMcp {
@Tool({
name: 'update_day_note',
description: 'Edit an existing note on a specific day.',
description: 'Edit an existing note on a specific day: its title is `text`, its body `time`.',
inputSchema: {
tripId: idSchema,
dayId: idSchema,
noteId: idSchema,
text: z.string().min(1).max(500).optional(),
time: z
.string()
.max(250)
.nullable()
.optional()
.describe('Time label (e.g. "09:00" or "Morning"), or null to clear'),
// The create bound, so an update cannot blank the title the planner requires.
text: noteTitleSchema.optional(),
time: dayNoteUpdateRequestSchema.shape.time.describe(`${NOTE_BODY}, or null to clear it`),
icon: z.string().max(64).optional().describe('Emoji icon for the note'),
color: noteColorSchema
.nullable()
+76
View File
@@ -99,6 +99,43 @@ describe('Tool: create_day_note', () => {
});
});
it('describes text as the title and time as the body, as the planner shows them', async () => {
const { user } = createUser(testDb);
await withHarness(user.id, async (h) => {
const { tools } = await h.client.listTools();
for (const name of ['create_day_note', 'update_day_note']) {
const props = tools.find((t) => t.name === name)?.inputSchema.properties as Record<string, any>;
// The nullable body may come out as an anyOf, so read the property whole.
const time = JSON.stringify(props.time);
expect(JSON.stringify(props.text)).toMatch(/title/i);
expect(time).toMatch(/body/i);
expect(time).not.toMatch(/time label/i);
expect(time).toContain('"maxLength":2000');
}
});
});
it('takes a body of 2000 characters, the bound the planner allows, and refuses one more', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const day = createDay(testDb, trip.id);
await withHarness(user.id, async (h) => {
const body = 'b'.repeat(2000);
const result = await h.client.callTool({
name: 'create_day_note',
arguments: { tripId: trip.id, dayId: day.id, text: 'Museum day', time: body },
});
const data = parseToolResult(result) as any;
expect((await dayNote(data.note.id)).time).toBe(body);
const tooLong = await h.client.callTool({
name: 'create_day_note',
arguments: { tripId: trip.id, dayId: day.id, text: 'Museum day', time: `${body}b` },
});
expect(tooLong.isError).toBe(true);
expect(await countRows(orm, DayNotes, { day: day.id })).toBe(1);
});
});
it('defaults icon to 📝', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
@@ -220,6 +257,45 @@ describe('Tool: update_day_note', () => {
});
});
it('edits a note whose body is longer than 250 characters without shortening it', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const day = createDay(testDb, trip.id);
const longBody = 'Opening hours and the ticket links. '.repeat(20);
const note = createDayNote(testDb, day.id, trip.id, { text: 'Museum day', time: longBody });
await withHarness(user.id, async (h) => {
const renamed = await h.client.callTool({
name: 'update_day_note',
arguments: { tripId: trip.id, dayId: day.id, noteId: note.id, text: 'Museums' },
});
expect(renamed.isError).toBeFalsy();
const longer = `${longBody}Bring the pass.`;
const rewritten = await h.client.callTool({
name: 'update_day_note',
arguments: { tripId: trip.id, dayId: day.id, noteId: note.id, time: longer },
});
expect(rewritten.isError).toBeFalsy();
const row = await dayNote(note.id);
expect(row.text).toBe('Museums');
expect(row.time).toBe(longer);
});
});
it('refuses an empty title on update and keeps the stored one', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const day = createDay(testDb, trip.id);
const note = createDayNote(testDb, day.id, trip.id, { text: 'Keep me' });
await withHarness(user.id, async (h) => {
const result = await h.client.callTool({
name: 'update_day_note',
arguments: { tripId: trip.id, dayId: day.id, noteId: note.id, text: '' },
});
expect(result.isError).toBe(true);
expect((await dayNote(note.id)).text).toBe('Keep me');
});
});
it('trims text whitespace', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
@@ -142,7 +142,7 @@ describe('describeToolCall', () => {
});
expect(describe_('update_day_note', { dayId: 31, noteId: 41, time: null })).toMatchObject({
subject: 'Rail pass',
rows: [{ op: 'change', labelKey: 'time', before: '09:00', after: '' }],
rows: [{ op: 'change', labelKey: 'content', before: '09:00', after: '' }],
});
expect(describe_('create_day_note', { dayId: 33, text: 'Laundry', icon: '🧺' }).rows).toEqual([
{ op: 'add', labelKey: 'day', before: null, after: 'Spare day' },
+3
View File
@@ -154,6 +154,9 @@ export const ASSISTANT_CHANGE_LABEL_KEYS = [
'currency',
'stopType',
'text',
// A day note's heading and its body; `text` and `time` stay for rows already stored.
'title',
'content',
'icon',
'color',
'position',
+2
View File
@@ -191,6 +191,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'العملة',
'assistant.change.label.stopType': 'نوع التوقف',
'assistant.change.label.text': 'النص',
'assistant.change.label.title': 'العنوان',
'assistant.change.label.content': 'المحتوى',
'assistant.change.label.icon': 'الأيقونة',
'assistant.change.label.color': 'اللون',
'assistant.change.label.position': 'الترتيب',
+2
View File
@@ -182,6 +182,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Valyuta',
'assistant.change.label.stopType': 'Dayanacaq növü',
'assistant.change.label.text': 'Mətn',
'assistant.change.label.title': 'Başlıq',
'assistant.change.label.content': 'Məzmun',
'assistant.change.label.icon': 'İkon',
'assistant.change.label.color': 'Rəng',
'assistant.change.label.position': 'Sıra',
+2
View File
@@ -182,6 +182,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Moeda',
'assistant.change.label.stopType': 'Tipo de parada',
'assistant.change.label.text': 'Texto',
'assistant.change.label.title': 'Título',
'assistant.change.label.content': 'Conteúdo',
'assistant.change.label.icon': 'Ícone',
'assistant.change.label.color': 'Cor',
'assistant.change.label.position': 'Ordem',
+2
View File
@@ -183,6 +183,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Moneda',
'assistant.change.label.stopType': 'Tipus de parada',
'assistant.change.label.text': 'Text', // same-as-en
'assistant.change.label.title': 'Títol',
'assistant.change.label.content': 'Contingut',
'assistant.change.label.icon': 'Icona',
'assistant.change.label.color': 'Color',
'assistant.change.label.position': 'Ordre',
+2
View File
@@ -184,6 +184,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Měna',
'assistant.change.label.stopType': 'Typ zastávky',
'assistant.change.label.text': 'Text', // same-as-en
'assistant.change.label.title': 'Název',
'assistant.change.label.content': 'Obsah',
'assistant.change.label.icon': 'Ikona',
'assistant.change.label.color': 'Barva',
'assistant.change.label.position': 'Pořadí',
+2
View File
@@ -182,6 +182,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Währung',
'assistant.change.label.stopType': 'Art des Stopps',
'assistant.change.label.text': 'Text', // same-as-en
'assistant.change.label.title': 'Titel',
'assistant.change.label.content': 'Inhalt',
'assistant.change.label.icon': 'Symbol',
'assistant.change.label.color': 'Farbe',
'assistant.change.label.position': 'Reihenfolge',
+2
View File
@@ -178,6 +178,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Currency',
'assistant.change.label.stopType': 'Stop type',
'assistant.change.label.text': 'Text',
'assistant.change.label.title': 'Title',
'assistant.change.label.content': 'Content',
'assistant.change.label.icon': 'Icon',
'assistant.change.label.color': 'Colour',
'assistant.change.label.position': 'Position',
+2
View File
@@ -181,6 +181,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Moneda',
'assistant.change.label.stopType': 'Tipo de parada',
'assistant.change.label.text': 'Texto',
'assistant.change.label.title': 'Título',
'assistant.change.label.content': 'Contenido',
'assistant.change.label.icon': 'Icono',
'assistant.change.label.color': 'Color',
'assistant.change.label.position': 'Orden',
+2
View File
@@ -182,6 +182,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Valuuta',
'assistant.change.label.stopType': 'Peatuse tüüp',
'assistant.change.label.text': 'Tekst',
'assistant.change.label.title': 'Pealkiri',
'assistant.change.label.content': 'Sisu',
'assistant.change.label.icon': 'Ikoon',
'assistant.change.label.color': 'Värv',
'assistant.change.label.position': 'Järjekord',
+2
View File
@@ -183,6 +183,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Devise',
'assistant.change.label.stopType': 'Type d’arrêt',
'assistant.change.label.text': 'Texte',
'assistant.change.label.title': 'Titre',
'assistant.change.label.content': 'Contenu',
'assistant.change.label.icon': 'Icône',
'assistant.change.label.color': 'Couleur',
'assistant.change.label.position': 'Ordre',
+2
View File
@@ -185,6 +185,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Νόμισμα',
'assistant.change.label.stopType': 'Τύπος στάσης',
'assistant.change.label.text': 'Κείμενο',
'assistant.change.label.title': 'Τίτλος',
'assistant.change.label.content': 'Περιεχόμενο',
'assistant.change.label.icon': 'Εικονίδιο',
'assistant.change.label.color': 'Χρώμα',
'assistant.change.label.position': 'Σειρά',
+2
View File
@@ -184,6 +184,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Pénznem',
'assistant.change.label.stopType': 'Megálló típusa',
'assistant.change.label.text': 'Szöveg',
'assistant.change.label.title': 'Cím',
'assistant.change.label.content': 'Tartalom',
'assistant.change.label.icon': 'Ikon',
'assistant.change.label.color': 'Szín',
'assistant.change.label.position': 'Pozíció',
+2
View File
@@ -176,6 +176,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Mata uang',
'assistant.change.label.stopType': 'Jenis pemberhentian',
'assistant.change.label.text': 'Teks',
'assistant.change.label.title': 'Judul',
'assistant.change.label.content': 'Isi',
'assistant.change.label.icon': 'Ikon',
'assistant.change.label.color': 'Warna',
'assistant.change.label.position': 'Posisi',
+2
View File
@@ -184,6 +184,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Valuta',
'assistant.change.label.stopType': 'Tipo di tappa',
'assistant.change.label.text': 'Testo',
'assistant.change.label.title': 'Titolo',
'assistant.change.label.content': 'Contenuto',
'assistant.change.label.icon': 'Icona',
'assistant.change.label.color': 'Colore',
'assistant.change.label.position': 'Posizione',
+2
View File
@@ -176,6 +176,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': '通貨',
'assistant.change.label.stopType': '立ち寄りの種類',
'assistant.change.label.text': 'テキスト',
'assistant.change.label.title': 'タイトル',
'assistant.change.label.content': '内容',
'assistant.change.label.icon': 'アイコン',
'assistant.change.label.color': '色',
'assistant.change.label.position': '位置',
+2
View File
@@ -174,6 +174,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': '통화',
'assistant.change.label.stopType': '경유지 유형',
'assistant.change.label.text': '텍스트',
'assistant.change.label.title': '제목',
'assistant.change.label.content': '내용',
'assistant.change.label.icon': '아이콘',
'assistant.change.label.color': '색상',
'assistant.change.label.position': '위치',
+2
View File
@@ -182,6 +182,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Valuta',
'assistant.change.label.stopType': 'Soort stop',
'assistant.change.label.text': 'Tekst',
'assistant.change.label.title': 'Titel',
'assistant.change.label.content': 'Inhoud',
'assistant.change.label.icon': 'Pictogram',
'assistant.change.label.color': 'Kleur',
'assistant.change.label.position': 'Positie',
+2
View File
@@ -189,6 +189,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Waluta',
'assistant.change.label.stopType': 'Rodzaj przystanku',
'assistant.change.label.text': 'Tekst',
'assistant.change.label.title': 'Tytuł',
'assistant.change.label.content': 'Treść',
'assistant.change.label.icon': 'Ikona',
'assistant.change.label.color': 'Kolor',
'assistant.change.label.position': 'Pozycja',
+2
View File
@@ -189,6 +189,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Валюта',
'assistant.change.label.stopType': 'Тип остановки',
'assistant.change.label.text': 'Текст',
'assistant.change.label.title': 'Заголовок',
'assistant.change.label.content': 'Содержание',
'assistant.change.label.icon': 'Значок',
'assistant.change.label.color': 'Цвет',
'assistant.change.label.position': 'Позиция',
+2
View File
@@ -184,6 +184,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Mena',
'assistant.change.label.stopType': 'Typ zastávky',
'assistant.change.label.text': 'Text', // same-as-en
'assistant.change.label.title': 'Názov',
'assistant.change.label.content': 'Obsah',
'assistant.change.label.icon': 'Ikona',
'assistant.change.label.color': 'Farba',
'assistant.change.label.position': 'Poradie',
+2
View File
@@ -183,6 +183,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Valuta',
'assistant.change.label.stopType': 'Typ av stopp',
'assistant.change.label.text': 'Text', // same-as-en
'assistant.change.label.title': 'Titel',
'assistant.change.label.content': 'Innehåll',
'assistant.change.label.icon': 'Ikon',
'assistant.change.label.color': 'Färg',
'assistant.change.label.position': 'Position', // same-as-en
+2
View File
@@ -174,6 +174,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'สกุลเงิน',
'assistant.change.label.stopType': 'ประเภทจุดแวะ',
'assistant.change.label.text': 'ข้อความ',
'assistant.change.label.title': 'หัวข้อ',
'assistant.change.label.content': 'เนื้อหา',
'assistant.change.label.icon': 'ไอคอน',
'assistant.change.label.color': 'สี',
'assistant.change.label.position': 'ลำดับ',
+2
View File
@@ -181,6 +181,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Para birimi',
'assistant.change.label.stopType': 'Durak türü',
'assistant.change.label.text': 'Metin',
'assistant.change.label.title': 'Başlık',
'assistant.change.label.content': 'İçerik',
'assistant.change.label.icon': 'Simge',
'assistant.change.label.color': 'Renk',
'assistant.change.label.position': 'Sıra',
+2
View File
@@ -189,6 +189,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Валюта',
'assistant.change.label.stopType': 'Тип зупинки',
'assistant.change.label.text': 'Текст',
'assistant.change.label.title': 'Заголовок',
'assistant.change.label.content': 'Вміст',
'assistant.change.label.icon': 'Значок',
'assistant.change.label.color': 'Колір',
'assistant.change.label.position': 'Позиція',
+2
View File
@@ -176,6 +176,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': 'Tiền tệ',
'assistant.change.label.stopType': 'Loại điểm dừng',
'assistant.change.label.text': 'Văn bản',
'assistant.change.label.title': 'Tiêu đề',
'assistant.change.label.content': 'Nội dung',
'assistant.change.label.icon': 'Biểu tượng',
'assistant.change.label.color': 'Màu',
'assistant.change.label.position': 'Vị trí',
+2
View File
@@ -170,6 +170,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': '貨幣',
'assistant.change.label.stopType': '停靠類型',
'assistant.change.label.text': '文字',
'assistant.change.label.title': '標題',
'assistant.change.label.content': '內容',
'assistant.change.label.icon': '圖示',
'assistant.change.label.color': '顏色',
'assistant.change.label.position': '位置',
+2
View File
@@ -170,6 +170,8 @@ const assistant: TranslationStrings = {
'assistant.change.label.currency': '货币',
'assistant.change.label.stopType': '停靠类型',
'assistant.change.label.text': '文本',
'assistant.change.label.title': '标题',
'assistant.change.label.content': '内容',
'assistant.change.label.icon': '图标',
'assistant.change.label.color': '颜色',
'assistant.change.label.position': '位置',
+2 -2
View File
@@ -101,8 +101,8 @@ Requires `trips:read` or `trips:write` scope.
| Tool | Description |
|---|---|
| `create_day_note` | Add a note to a specific day with optional time label and emoji icon. |
| `update_day_note` | Edit a day note's text, time, or icon. |
| `create_day_note` | Add a note to a specific day: `text` is the title, `time` the Markdown body (up to 2000 characters), plus an optional icon and colour. |
| `update_day_note` | Edit a day note's title (`text`), body (`time`), icon, colour or position. |
| `delete_day_note` | Remove a note from a day. |
### Accommodations