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({
+40 -1
View File
@@ -3,11 +3,13 @@
* called through a real MCP session on the whole app (buildApp, the real
* registry with its addon and sub-feature gates, scopes and error mapper,
* the real CollabService and a migrated temp SQLite), the way the
* assistant's note cards read them.
* assistant's note cards read them. The shared links (#3076) ride the same
* path: saved over MCP, read back over MCP and over the REST route.
*/
import { buildApp } from '../../src/bootstrap';
import { createLocalMcpServer, McpRegistryService } from '../../src/nest-mcp';
import { withRequestContext } from '../../src/nest/database/request-context';
import { authCookie } from '../helpers/auth';
import { makeCollabNote } from '../helpers/factories/collab';
import { setAddonEnabled, setCollabFeature } from '../helpers/factories/settings';
import { makeTrip } from '../helpers/factories/trips';
@@ -17,6 +19,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory';
import type { INestApplication } from '@nestjs/common';
import request from 'supertest';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
let app: INestApplication;
@@ -107,3 +110,39 @@ describe('the shared notes over MCP', () => {
expect((await session(user.id, 'list_collab_notes', { tripId: trip.id })).answer).toEqual({ notes: [] });
});
});
describe('the shared links over MCP', () => {
it('COLLAB-MCP-E2E-004: saves a link the Links panel then lists, and reads it back', async () => {
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id, { title: 'Lisbon' });
const created = await session(user.id, 'create_collab_link', {
tripId: trip.id,
title: 'Tram 28 timetable',
url: 'https://example.com/tram-28',
});
const link = (created.answer as { link: Record<string, unknown> }).link;
expect(link).toMatchObject({ title: 'Tram 28 timetable', url: 'https://example.com/tram-28', pinned: 0 });
const { answer } = await session(user.id, 'list_collab_links', { tripId: trip.id });
expect(answer).toEqual({ links: [expect.objectContaining({ id: link.id, username: user.username })] });
const rest = await request(app.getHttpServer())
.get(`/api/trips/${trip.id}/collab/links`)
.set('Cookie', authCookie(user.id));
expect(rest.status).toBe(200);
expect(rest.body.links.map((row: { id: number }) => row.id)).toEqual([link.id]);
});
it('COLLAB-MCP-E2E-005: is gone while the links are switched off', async () => {
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
await setCollabFeature(orm, 'links', false);
try {
const { offered } = await session(user.id, 'list_collab_links', { tripId: trip.id });
expect(offered).not.toContain('list_collab_links');
expect(offered).not.toContain('create_collab_link');
expect(offered).toContain('list_collab_notes');
} finally {
await setCollabFeature(orm, 'links', true);
}
});
});
+2 -2
View File
@@ -33,10 +33,10 @@ export async function setAddonEnabled(orm: FactoryOrm, addonId: string, enabled:
await upsertRow(orm, Addons, { id: addonId, name: addonId, type: 'global', enabled }, ['enabled']);
}
/** Collab's chat, notes, polls and next-up panels are opt-out app settings, not addon rows. */
/** Collab's chat, notes, polls, links and next-up panels are opt-out app settings, not addon rows. */
export async function setCollabFeature(
orm: FactoryOrm,
feature: 'chat' | 'notes' | 'polls' | 'whatsnext',
feature: 'chat' | 'notes' | 'polls' | 'links' | 'whatsnext',
enabled: boolean,
): Promise<void> {
await setAppSetting(orm, `collab_${feature}_enabled`, enabled ? 'true' : 'false');
+1 -1
View File
@@ -182,7 +182,7 @@ export function setAddonEnabled(db: Database.Database, addonId: string, enabled:
/** Collab's sub-feature flags are opt-out app_settings, not addon rows. */
export function setCollabFeature(
db: Database.Database,
feature: 'chat' | 'notes' | 'polls' | 'whatsnext',
feature: 'chat' | 'notes' | 'polls' | 'links' | 'whatsnext',
enabled: boolean,
): void {
db.prepare('INSERT OR REPLACE INTO app_settings (key, value) VALUES (?, ?)').run(
@@ -223,6 +223,34 @@ export const collabTrip: CaseGroup = {
},
expect: ['collab:message:reacted'],
},
{
tool: 'create_collab_link',
args: (s) => ({ tripId: s.trip.id, title: 'Ferry', url: 'https://example.com/ferry' }),
rest: {
method: 'post',
path: (s) => tripPath(s, '/collab/links'),
body: () => ({ title: 'Ferry', url: 'https://example.com/ferry' }),
},
expect: ['collab:link:created'],
},
{
tool: 'update_collab_link',
needs: ['collabLink'],
args: (s) => ({ tripId: s.trip.id, linkId: s.collabLink.id, pinned: true }),
rest: {
method: 'put',
path: (s) => tripPath(s, `/collab/links/${s.collabLink.id}`),
body: () => ({ pinned: true }),
},
expect: ['collab:link:updated'],
},
{
tool: 'delete_collab_link',
needs: ['collabLink'],
args: (s) => ({ tripId: s.trip.id, linkId: s.collabLink.id }),
rest: { method: 'delete', path: (s) => tripPath(s, `/collab/links/${s.collabLink.id}`) },
expect: ['collab:link:deleted'],
},
// ── Files and the document store ──────────────────────────────────────
{
@@ -1,6 +1,7 @@
import { ADDON_IDS } from '../../../src/addons';
import { buildApp } from '../../../src/bootstrap';
import { BudgetSettlements } from '../../../src/db/entities/BudgetSettlements.entity';
import { CollabLinks } from '../../../src/db/entities/CollabLinks.entity';
import { CollabPolls } from '../../../src/db/entities/CollabPolls.entity';
import { DayAccommodations } from '../../../src/db/entities/DayAccommodations.entity';
import { PackingTemplateCategories } from '../../../src/db/entities/PackingTemplateCategories.entity';
@@ -220,7 +221,9 @@ export async function openHarness(): Promise<ParityHarness> {
await app.init();
const orm = app.get(MikroORM);
await oneByOne(Object.values(ADDON_IDS), (addon) => setAddonEnabled(orm, addon, true));
await oneByOne(['chat', 'notes', 'polls', 'whatsnext'] as const, (feature) => setCollabFeature(orm, feature, true));
await oneByOne(['chat', 'notes', 'polls', 'links', 'whatsnext'] as const, (feature) =>
setCollabFeature(orm, feature, true),
);
// The wanderer tools show only while wanderer is allowed under Tours.
await setAppSetting(orm, 'tours_wanderer_enabled', 'true');
// The photo search tools show only while a provider is on.
@@ -319,6 +322,7 @@ export const NEED_KEYS: Record<Need, readonly (keyof Scene)[]> = {
collabNote: ['collabNote'],
collabMessage: ['collabMessage'],
poll: ['poll'],
collabLink: ['collabLink'],
file: ['file'],
collection: ['collection', 'collectionPlace'],
journey: ['journey', 'journeyEntry'],
@@ -443,6 +447,15 @@ const BUILDERS: Record<Need, Builder> = {
});
s.poll = { id: row.id };
},
async collabLink(s, _app, orm) {
const id = await insertRow(orm, CollabLinks, {
trip: s.trip.id,
user: s.owner.id,
title: `Ferry ${s.n}`,
url: 'https://example.com/ferry',
});
s.collabLink = { id };
},
async file(s, _app, orm) {
s.file = await makeTripFile(orm, s.trip.id);
},
@@ -36,6 +36,7 @@ export type Need =
| 'collabNote'
| 'collabMessage'
| 'poll'
| 'collabLink'
| 'file'
| 'guest'
| 'member'
@@ -100,6 +101,8 @@ export interface Scene {
collabMessage: CollabMessageRow;
/** Two options, open. */
poll: IdRow;
/** A shared link on the trip's Links panel, saved by the owner. */
collabLink: IdRow;
file: TripFileRow;
/** A guest (no account) on the trip. */
guest: UserRow;
@@ -0,0 +1,328 @@
/**
* Unit tests for the collab link tools (#3076): list_collab_links,
* create_collab_link, update_collab_link and delete_collab_link (CollabMcp).
*
* They are the Links panel's REST routes as tools, so these cases pin the
* same rules: trip access for every call, collab_edit for the writes, the
* http(s) contract of the shared body schemas, the collab:link:* broadcasts,
* and the links flag hiding all four.
*/
import { ADDON_IDS } from '../../../src/addons';
import { db as testDb } from '../../../src/db/database';
import { CollabLinks } from '../../../src/db/entities/CollabLinks.entity';
import { invalidatePermissionsCache } from '../../../src/nest/permissions/permissions-cache';
import { addTripMember, createTrip, createUser } from '../../helpers/factories';
import { countRows, findRow, insertRow } from '../../helpers/factories/rows';
import { setAppSetting } from '../../helpers/factories/settings';
import { FakeRealtimeService } from '../../helpers/fake-realtime';
import { createMcpHarness, parseToolResult, type McpHarness } from '../../helpers/mcp-harness';
import { resetTestDb, setAddonEnabled, setCollabFeature } from '../../helpers/test-db';
import { createTestOrm, type TestOrm } from '../../helpers/test-orm';
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
vi.mock('../../../src/db/database', async () => {
const { createSnapshotTestDb, buildDbMock } = await import('../../helpers/db-mock');
return buildDbMock(createSnapshotTestDb());
});
const realtime = new FakeRealtimeService();
const broadcastMock = realtime.broadcastMock;
beforeEach(async () => {
resetTestDb(testDb);
setAddonEnabled(testDb, ADDON_IDS.COLLAB, true);
broadcastMock.mockClear();
delete process.env.DEMO_MODE;
// resetTestDb truncates app_settings, but the permission cache is module-scoped
// and would keep serving whatever the previous case configured.
await invalidatePermissionsCache();
});
let orm: TestOrm;
beforeAll(async () => {
orm = await createTestOrm(testDb);
});
afterAll(async () => {
await orm.close();
testDb.close();
});
type ToolResult = Awaited<ReturnType<McpHarness['client']['callTool']>>;
async function call(userId: number, name: string, args: Record<string, unknown>): Promise<ToolResult> {
const h = await createMcpHarness({ realtime, userId, withResources: false });
try {
return await h.client.callTool({ name, arguments: args });
} finally {
await h.cleanup();
}
}
async function toolNames(userId: number): Promise<string[]> {
const h = await createMcpHarness({ realtime, userId, withResources: false });
try {
return (await h.client.listTools()).tools.map((tool) => tool.name);
} finally {
await h.cleanup();
}
}
function insertLink(tripId: number, userId: number, title = 'Ferry', pinned = 0): Promise<number> {
return insertRow(orm, CollabLinks, { trip: tripId, user: userId, title, url: 'https://example.com/ferry', pinned });
}
function linkRow(id: number) {
return findRow(orm, CollabLinks, { id });
}
/** A member of the owner's trip, once collab_edit is lowered to the owner alone. */
async function memberWithoutEdit() {
const { user: owner } = createUser(testDb);
const { user: member } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
addTripMember(testDb, trip.id, member.id);
await setAppSetting(orm, 'perm_collab_edit', 'trip_owner');
await invalidatePermissionsCache();
return { owner, member, trip };
}
const LINK_TOOLS = ['list_collab_links', 'create_collab_link', 'update_collab_link', 'delete_collab_link'];
describe('Tool: list_collab_links', () => {
it('MCP-COLLAB-LINK-001: lists the links pinned first, then newest first, with their author', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
await insertLink(trip.id, user.id, 'Timetable');
const pinned = await insertLink(trip.id, user.id, 'Hotel', 1);
const data = parseToolResult(await call(user.id, 'list_collab_links', { tripId: trip.id })) as {
links: Array<Record<string, unknown>>;
};
expect(data.links.map((link) => link.title)).toEqual(['Hotel', 'Timetable']);
expect(data.links[0]).toMatchObject({ id: pinned, pinned: 1, username: user.username });
});
it('MCP-COLLAB-LINK-002: refuses a trip the user is not part of', async () => {
const { user } = createUser(testDb);
const { user: owner } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
await insertLink(trip.id, owner.id);
expect((await call(user.id, 'list_collab_links', { tripId: trip.id })).isError).toBe(true);
});
it('MCP-COLLAB-LINK-003: is a read a member may make without collab_edit', async () => {
const { owner, member, trip } = await memberWithoutEdit();
await insertLink(trip.id, owner.id);
const result = await call(member.id, 'list_collab_links', { tripId: trip.id });
expect(result.isError).toBeFalsy();
expect((parseToolResult(result) as { links: unknown[] }).links).toHaveLength(1);
});
});
describe('Tool: create_collab_link', () => {
it('MCP-COLLAB-LINK-004: saves the link with the caller as author and broadcasts it', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const result = await call(user.id, 'create_collab_link', {
tripId: trip.id,
title: ' Ferry tickets ',
url: 'https://example.com/ferry',
pinned: true,
});
const { link } = parseToolResult(result) as { link: Record<string, unknown> };
expect(link).toMatchObject({
trip_id: trip.id,
user_id: user.id,
title: 'Ferry tickets',
url: 'https://example.com/ferry',
pinned: 1,
username: user.username,
});
expect(broadcastMock).toHaveBeenCalledWith(
trip.id,
'collab:link:created',
expect.objectContaining({ link: expect.objectContaining({ id: link.id }) }),
);
});
it('MCP-COLLAB-LINK-005: leaves a link unpinned unless asked', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const result = await call(user.id, 'create_collab_link', {
tripId: trip.id,
title: 'Map',
url: 'https://example.com/map',
});
expect((parseToolResult(result) as { link: { pinned: number } }).link.pinned).toBe(0);
});
it('MCP-COLLAB-LINK-006: refuses a URL that is not http(s), or an empty title, like the REST route', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
for (const args of [
{ title: 'Script', url: 'javascript:alert(1)' },
{ title: 'Mail', url: 'mailto:someone@example.com' },
{ title: ' ', url: 'https://example.com' },
]) {
expect((await call(user.id, 'create_collab_link', { tripId: trip.id, ...args })).isError).toBe(true);
}
expect(await countRows(orm, CollabLinks, { trip: trip.id })).toBe(0);
expect(broadcastMock).not.toHaveBeenCalled();
});
it('MCP-COLLAB-LINK-007: refuses a member without collab_edit and saves nothing', async () => {
const { member, trip } = await memberWithoutEdit();
const result = await call(member.id, 'create_collab_link', {
tripId: trip.id,
title: 'Ferry',
url: 'https://example.com/ferry',
});
expect(result.isError).toBe(true);
expect(await countRows(orm, CollabLinks, { trip: trip.id })).toBe(0);
});
it('MCP-COLLAB-LINK-008: refuses a trip the user is not part of', async () => {
const { user } = createUser(testDb);
const { user: owner } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
const result = await call(user.id, 'create_collab_link', {
tripId: trip.id,
title: 'Ferry',
url: 'https://example.com/ferry',
});
expect(result.isError).toBe(true);
expect(await countRows(orm, CollabLinks, { trip: trip.id })).toBe(0);
});
it('MCP-COLLAB-LINK-009: blocks the demo user', async () => {
process.env.DEMO_MODE = 'true';
const { user } = createUser(testDb, { email: 'demo@nomad.app' });
const trip = createTrip(testDb, user.id);
const result = await call(user.id, 'create_collab_link', {
tripId: trip.id,
title: 'Ferry',
url: 'https://example.com/ferry',
});
expect(result.isError).toBe(true);
});
});
describe('Tool: update_collab_link', () => {
it('MCP-COLLAB-LINK-010: changes only the fields given and broadcasts the link', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const id = await insertLink(trip.id, user.id, 'Ferry');
const result = await call(user.id, 'update_collab_link', { tripId: trip.id, linkId: id, pinned: true });
expect((parseToolResult(result) as { link: Record<string, unknown> }).link).toMatchObject({
id,
title: 'Ferry',
url: 'https://example.com/ferry',
pinned: 1,
});
expect(broadcastMock).toHaveBeenCalledWith(
trip.id,
'collab:link:updated',
expect.objectContaining({ link: expect.objectContaining({ id }) }),
);
});
it('MCP-COLLAB-LINK-011: renames, moves and unpins a link', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const id = await insertLink(trip.id, user.id, 'Ferry', 1);
await call(user.id, 'update_collab_link', {
tripId: trip.id,
linkId: id,
title: 'Night ferry',
url: 'https://example.com/night-ferry',
pinned: false,
});
expect(await linkRow(id)).toMatchObject({
title: 'Night ferry',
url: 'https://example.com/night-ferry',
pinned: 0,
});
});
it('MCP-COLLAB-LINK-012: says the link is not found when it belongs to another trip, and leaves it alone', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const other = createTrip(testDb, user.id);
const id = await insertLink(other.id, user.id, 'Ferry');
const result = await call(user.id, 'update_collab_link', { tripId: trip.id, linkId: id, title: 'Moved' });
expect(result.isError).toBe(true);
expect(JSON.stringify(result.content)).toContain('Link not found.');
expect((await linkRow(id))?.title).toBe('Ferry');
expect(broadcastMock).not.toHaveBeenCalled();
});
it('MCP-COLLAB-LINK-013: refuses a URL that is not http(s)', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const id = await insertLink(trip.id, user.id);
const result = await call(user.id, 'update_collab_link', { tripId: trip.id, linkId: id, url: 'ftp://example.com' });
expect(result.isError).toBe(true);
expect((await linkRow(id))?.url).toBe('https://example.com/ferry');
});
it('MCP-COLLAB-LINK-014: refuses a member without collab_edit', async () => {
const { owner, member, trip } = await memberWithoutEdit();
const id = await insertLink(trip.id, owner.id);
const result = await call(member.id, 'update_collab_link', { tripId: trip.id, linkId: id, title: 'Mine' });
expect(result.isError).toBe(true);
expect((await linkRow(id))?.title).toBe('Ferry');
});
});
describe('Tool: delete_collab_link', () => {
it('MCP-COLLAB-LINK-015: removes the link and broadcasts its id', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const id = await insertLink(trip.id, user.id);
const result = await call(user.id, 'delete_collab_link', { tripId: trip.id, linkId: id });
expect(parseToolResult(result)).toEqual({ success: true });
expect(await linkRow(id)).toBeNull();
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'collab:link:deleted', expect.objectContaining({ linkId: id }));
});
it('MCP-COLLAB-LINK-016: says the link is not found for a link of another trip', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id);
const other = createTrip(testDb, user.id);
const id = await insertLink(other.id, user.id);
const result = await call(user.id, 'delete_collab_link', { tripId: trip.id, linkId: id });
expect(result.isError).toBe(true);
expect(await linkRow(id)).not.toBeNull();
});
it('MCP-COLLAB-LINK-017: refuses a member without collab_edit', async () => {
const { owner, member, trip } = await memberWithoutEdit();
const id = await insertLink(trip.id, owner.id);
expect((await call(member.id, 'delete_collab_link', { tripId: trip.id, linkId: id })).isError).toBe(true);
expect(await linkRow(id)).not.toBeNull();
});
});
describe('Collab link tools, gating', () => {
it('MCP-COLLAB-LINK-018: are offered only while the links are switched on', async () => {
const { user } = createUser(testDb);
expect(await toolNames(user.id)).toEqual(expect.arrayContaining(LINK_TOOLS));
setCollabFeature(testDb, 'links', false);
try {
const names = await toolNames(user.id);
expect(names.filter((name) => LINK_TOOLS.includes(name))).toEqual([]);
expect(names).toContain('list_collab_notes');
} finally {
setCollabFeature(testDb, 'links', true);
}
});
it('MCP-COLLAB-LINK-019: are gone with the collab addon', async () => {
const { user } = createUser(testDb);
setAddonEnabled(testDb, ADDON_IDS.COLLAB, false);
const names = await toolNames(user.id);
expect(names.filter((name) => LINK_TOOLS.includes(name))).toEqual([]);
});
});
+6 -1
View File
@@ -70,13 +70,14 @@ Requires `atlas:read` or `atlas:write` scope.
Requires `collab:read` or `collab:write` scope.
The addon alone is not enough. Collab has five sub-features an admin switches on and off independently in Admin → Addons — Notes, Polls, Chat, Links and What's Next, all on by default — and three of them gate MCP entries. A tool or resource is only registered when its own sub-feature is enabled on top of the addon, so switching one off makes its entries vanish from the tool list rather than return an error. Links and What's Next have no MCP tools or resources of their own, so toggling them changes nothing here.
The addon alone is not enough. Collab has five sub-features an admin switches on and off independently in Admin → Addons — Notes, Polls, Chat, Links and What's Next, all on by default — and four of them gate MCP entries. A tool or resource is only registered when its own sub-feature is enabled on top of the addon, so switching one off makes its entries vanish from the tool list rather than return an error. What's Next has no MCP tools or resources of its own, so toggling it changes nothing here.
| Sub-feature | Tools it gates | Resource it gates |
|---|---|---|
| Notes | `list_collab_notes`, `create_collab_note`, `update_collab_note`, `delete_collab_note` | `trek://trips/{tripId}/collab-notes` |
| Polls | `list_collab_polls`, `create_collab_poll`, `vote_collab_poll`, `close_collab_poll`, `delete_collab_poll` | `trek://trips/{tripId}/collab/polls` |
| Chat | `list_collab_messages`, `send_collab_message`, `delete_collab_message`, `react_collab_message` | `trek://trips/{tripId}/collab/messages` |
| Links | `list_collab_links`, `create_collab_link`, `update_collab_link`, `delete_collab_link` | none |
| Tool | Description |
|---|---|
@@ -93,6 +94,10 @@ The addon alone is not enough. Collab has five sub-features an admin switches on
| `send_collab_message` | Send a chat message to a trip's collab channel, with optional reply threading. |
| `delete_collab_message` | Delete a chat message (own messages only). |
| `react_collab_message` | Toggle a reaction emoji on a chat message. |
| `list_collab_links` | List the shared links of a trip (Collab → Links), pinned first and then newest first. |
| `create_collab_link` | Save a link with a title on a trip, optionally pinned. The URL must be http(s). |
| `update_collab_link` | Change a shared link's title or URL, or pin or unpin it. |
| `delete_collab_link` | Remove a shared link. |
### Collections _(Collections addon required)_