feat(mcp): manage the trip's shared links over MCP (#3076)

list_collab_links, create_collab_link, update_collab_link and
delete_collab_link run the Links panel's REST routes as tools: the shared
body contracts, trip access, collab_edit on writes and the collab🔗*
broadcasts, behind the links sub-feature flag. Unit, e2e and broadcast
parity cases cover them; the wiki lists the tools.
This commit is contained in:
Maurice
2026-11-13 09:22:31 +01:00
parent 489ba93c0c
commit b9231ffb53
11 changed files with 529 additions and 11 deletions
+2 -2
View File
@@ -32,9 +32,9 @@ export function addonGate(addonId: string) {
/**
* Gate on one of collab's sub-feature flags. Every collab entry rides both the
* addon toggle and its own flag — notes, polls or chat.
* addon toggle and its own flag — notes, polls, chat or links.
*/
export function collabFeatureGate(feature: 'chat' | 'notes' | 'polls') {
export function collabFeatureGate(feature: 'chat' | 'notes' | 'polls' | 'links') {
return async (_ctx: McpContext, self: HasAddons): Promise<boolean> =>
(await self.addons.isAddonEnabled(ADDON_IDS.COLLAB)) && (await self.addons.getCollabFeatures())[feature];
}
@@ -359,7 +359,10 @@ const CORE_TOOL_GROUPS: ToolGroups = {
about: 'Collections: saved places across trips, their labels and ratings.',
controllers: ['CollectionsMcp'],
},
collab: { about: 'Trip chat: notes, polls and messages to the people on the trip.', controllers: ['CollabMcp'] },
collab: {
about: 'Trip chat: notes, polls, shared links and messages to the people on the trip.',
controllers: ['CollabMcp'],
},
files: {
about: 'Files and imports: the trip files, document sync, flights from AirTrail.',
controllers: ['FilesMcp', 'DocSyncMcp', 'ReservationImportMcp', 'AirtrailMcp'],
+101 -2
View File
@@ -16,7 +16,7 @@ import { collabFeatureGate } from '../addons/addon-gate';
import { AddonsService } from '../addons/addons.service';
import { McpToolGuardsService } from '../mcp-shared/mcp-tool-guards.service';
import { CollabService } from './collab.service';
import { idSchema } from '@trek/shared';
import { collabLinkCreateRequestSchema, collabLinkUpdateRequestSchema, idSchema } from '@trek/shared';
import { z } from 'zod';
@@ -28,6 +28,7 @@ import { z } from 'zod';
const collabNotesOn = collabFeatureGate('notes');
const collabPollsOn = collabFeatureGate('polls');
const collabChatOn = collabFeatureGate('chat');
const collabLinksOn = collabFeatureGate('links');
function parseId(value: string | string[]): number | null {
const n = Number(Array.isArray(value) ? value[0] : value);
@@ -71,7 +72,10 @@ function jsonContent(uri: string, data: unknown) {
* matching every other collab write tool. The two note write tools have since
* gained `website`, which the REST route has always accepted and the note card
* renders as a link preview. list_collab_notes came later, for the assistant's
* note cards: the notes resource as a tool, under the same gates.
* note cards: the notes resource as a tool, under the same gates. The four
* link tools came later still (#3076): the Links panel's REST routes as tools,
* with their body contracts, the collab_edit check and the collab:link:*
* broadcasts, behind the links flag.
*/
@McpController()
export class CollabMcp {
@@ -231,6 +235,101 @@ export class CollabMcp {
return ok({ notes });
}
// --- COLLAB LINKS ---
@Tool({
name: 'list_collab_links',
description:
'List the shared links of a trip (Collab → Links), pinned first and then newest first. Read this before saving links, so a URL already on the trip is not added twice.',
inputSchema: {
tripId: idSchema,
},
annotations: TOOL_ANNOTATIONS_READONLY,
when: collabLinksOn,
access: { group: 'collab', mode: 'read' },
})
async listCollabLinks({ tripId }: { tripId: number }, ctx: McpContext) {
if (!(await this.collab.verifyTripAccess(tripId, ctx.userId))) return noAccess();
const links = await this.collab.listLinks(tripId);
return ok({ links });
}
@Tool({
name: 'create_collab_link',
description:
'Save a link on a trip (Collab → Links) for every trip member to find, e.g. a reservation, a map, a timetable or an event page.',
inputSchema: {
tripId: idSchema,
title: collabLinkCreateRequestSchema.shape.title.describe('What the link is, as the list shows it'),
url: collabLinkCreateRequestSchema.shape.url.describe('An http(s) URL'),
pinned: z.boolean().optional().describe('Pin the link to the top of the list'),
},
annotations: TOOL_ANNOTATIONS_NON_IDEMPOTENT,
when: collabLinksOn,
access: { group: 'collab', mode: 'write' },
})
async createCollabLink(
{ tripId, title, url, pinned }: { tripId: number; title: string; url: string; pinned?: boolean },
ctx: McpContext,
) {
if (!(await this.collab.verifyTripAccess(tripId, ctx.userId))) return noAccess();
if (!(await this.guards.hasTripPermission('collab_edit', tripId, ctx.userId))) return permissionDenied();
const link = await this.collab.createLink(tripId, ctx.userId, { title, url, pinned: Boolean(pinned) });
this.guards.safeBroadcast(tripId, 'collab:link:created', { link });
return ok({ link });
}
@Tool({
name: 'update_collab_link',
description: "Change a shared link's title or URL, or pin or unpin it. Fields left out keep their value.",
inputSchema: {
tripId: idSchema,
linkId: idSchema,
title: collabLinkUpdateRequestSchema.shape.title.describe('What the link is, as the list shows it'),
url: collabLinkUpdateRequestSchema.shape.url.describe('An http(s) URL'),
pinned: z.boolean().optional().describe('Pin the link to the top of the list, or false to unpin it'),
},
annotations: TOOL_ANNOTATIONS_WRITE,
when: collabLinksOn,
access: { group: 'collab', mode: 'write' },
})
async updateCollabLink(
{
tripId,
linkId,
title,
url,
pinned,
}: { tripId: number; linkId: number; title?: string; url?: string; pinned?: boolean },
ctx: McpContext,
) {
if (!(await this.collab.verifyTripAccess(tripId, ctx.userId))) return noAccess();
if (!(await this.guards.hasTripPermission('collab_edit', tripId, ctx.userId))) return permissionDenied();
const link = await this.collab.updateLink(tripId, linkId, { title, url, pinned });
if (!link) return errorResult('Link not found.');
this.guards.safeBroadcast(tripId, 'collab:link:updated', { link });
return ok({ link });
}
@Tool({
name: 'delete_collab_link',
description: 'Remove a shared link from a trip.',
inputSchema: {
tripId: idSchema,
linkId: idSchema,
},
annotations: TOOL_ANNOTATIONS_DELETE,
when: collabLinksOn,
access: { group: 'collab', mode: 'write' },
})
async deleteCollabLink({ tripId, linkId }: { tripId: number; linkId: number }, ctx: McpContext) {
if (!(await this.collab.verifyTripAccess(tripId, ctx.userId))) return noAccess();
if (!(await this.guards.hasTripPermission('collab_edit', tripId, ctx.userId))) return permissionDenied();
if (!(await this.collab.deleteLink(tripId, linkId))) return errorResult('Link not found.');
this.guards.safeBroadcast(tripId, 'collab:link:deleted', { linkId });
return ok({ success: true });
}
// --- COLLAB POLLS & CHAT ---
@Tool({