diff --git a/server/src/nest/assistant/assistant-tool-offer.ts b/server/src/nest/assistant/assistant-tool-offer.ts index 119dfe1ff..0d902148e 100644 --- a/server/src/nest/assistant/assistant-tool-offer.ts +++ b/server/src/nest/assistant/assistant-tool-offer.ts @@ -75,7 +75,8 @@ export const ASSISTANT_DENIED_TOOLS: Readonly> = { get_journey_share_link: 'reads a public link token', create_journey_share_link: 'mints a public link token', delete_journey_share_link: 'belongs with the share links above', - list_journey_subscribers: 'reads the email addresses of people without an account, which would reach the AI provider', + add_journey_comment: "speaks in the user's name to the journey's people and the readers of its share link", + list_journey_subscribers:'reads the email addresses of people without an account, which would reach the AI provider', remove_journey_subscriber: 'belongs with the followers above', get_trip_calendar_feed: 'reads a calendar feed token', enable_trip_calendar_feed: 'mints a calendar feed token', diff --git a/server/src/nest/journey/journey-social.mcp.ts b/server/src/nest/journey/journey-social.mcp.ts index 9304fd74a..9559cc13c 100644 --- a/server/src/nest/journey/journey-social.mcp.ts +++ b/server/src/nest/journey/journey-social.mcp.ts @@ -12,14 +12,15 @@ import { addonGate } from '../addons/addon-gate'; import { AddonsService } from '../addons/addons.service'; import { JourneyCommentsService } from './journey-comments.service'; import { JourneySubscriptionsService } from './journey-subscriptions.service'; -import { idSchema, journeyCommentHideRequestSchema } from '@trek/shared'; +import { idSchema, journeyCommentCreateRequestSchema, journeyCommentHideRequestSchema } from '@trek/shared'; const journeyAddonOn = addonGate(ADDON_IDS.JOURNEY); /** * The comments under a journey's entries and the addresses following its * share link (#1702, #1669), over the same services and checks as - * `JourneySocialController`: the comments for everyone on the journey (hiding + * `JourneySocialController`: the comments for everyone on the journey (writing + * for everyone on it, hiding * for its editors, deleting for the author or an editor), the followers for * the journey's owner only, under the share scope like the link itself. */ @@ -44,6 +45,26 @@ export class JourneySocialMcp { return ok(await this.comments.list(journeyId, ctx.userId)); } + @Tool({ + name: 'add_journey_comment', + description: + 'Comment under an entry of a journey the caller is on, as plain text (at most 2000 characters, no markdown). The comment shows to everyone on the journey and, while the share link allows comments, to every reader of the link. Answers with the new comment.', + inputSchema: { + journeyId: idSchema, + entryId: idSchema, + body: journeyCommentCreateRequestSchema.shape.body, + }, + annotations: TOOL_ANNOTATIONS_WRITE, + when: journeyAddonOn, + access: { group: 'journey', mode: 'write' }, + }) + async addJourneyComment( + { journeyId, entryId, body }: { journeyId: number; entryId: number; body: string }, + ctx: McpContext, + ) { + return ok({ comment: await this.comments.add(journeyId, entryId, ctx.userId, body) }); + } + @Tool({ name: 'set_journey_comment_hidden', description: diff --git a/server/tests/integration/broadcast-parity/user.cases.ts b/server/tests/integration/broadcast-parity/user.cases.ts index 88c3c472e..ed49ad35c 100644 --- a/server/tests/integration/broadcast-parity/user.cases.ts +++ b/server/tests/integration/broadcast-parity/user.cases.ts @@ -495,6 +495,18 @@ const journeyCases: ParityCase[] = [ // To the owner and the new contributor alike; the contributor routes read no X-Socket-Id. expect: [{ event: 'journey:contributor:changed', user: 'actor', all: true }], }, + { + // #1702: the owner comments on their own journey, so nobody is notified; the tabs read the comments again. + tool: 'add_journey_comment', + needs: ['journey'], + args: (s) => ({ journeyId: s.journey.id, entryId: s.journeyEntry.id, body: 'Lovely light' }), + rest: { + method: 'post', + path: (s) => `/api/journeys/${s.journey.id}/entries/${s.journeyEntry.id}/comments`, + body: () => ({ body: 'Lovely light' }), + }, + expect: [{ event: 'journey:entry:commented', user: 'actor' }], + }, { // #1702: content-free, every tab on the journey reads its comments again with its own rights. tool: 'set_journey_comment_hidden', diff --git a/server/tests/unit/mcp/tools-journey-social.test.ts b/server/tests/unit/mcp/tools-journey-social.test.ts index 712ed0677..7770ccd71 100644 --- a/server/tests/unit/mcp/tools-journey-social.test.ts +++ b/server/tests/unit/mcp/tools-journey-social.test.ts @@ -90,6 +90,41 @@ describe('Tools: journey comments', () => { }); }); + it('JSOCIAL-MCP-003: a viewer comments like the REST route lets them; a stranger and a foreign entry are refused', async () => { + const { viewer, journey, entry } = await journeyWithComment(); + const { user: stranger } = await makeUser(orm); + const other = await makeJourney(orm, stranger.id); + const foreignEntry = await makeJourneyEntry(orm, other.id, stranger.id); + await withHarness(viewer.id, async (h) => { + const added = parseToolResult( + await h.client.callTool({ + name: 'add_journey_comment', + arguments: { journeyId: journey.id, entryId: entry.id, body: ' Wish I was there ' }, + }), + ) as { comment: { body: string; own: boolean; user_id: number } }; + expect(added.comment).toMatchObject({ body: 'Wish I was there', own: true, user_id: viewer.id }); + + const foreign = await h.client.callTool({ + name: 'add_journey_comment', + arguments: { journeyId: journey.id, entryId: foreignEntry.id, body: 'Nope' }, + }); + expect(foreign.isError).toBe(true); + const empty = await h.client.callTool({ + name: 'add_journey_comment', + arguments: { journeyId: journey.id, entryId: entry.id, body: ' ' }, + }); + expect(empty.isError).toBe(true); + }); + await withHarness(stranger.id, async (h) => { + const refused = await h.client.callTool({ + name: 'add_journey_comment', + arguments: { journeyId: journey.id, entryId: entry.id, body: 'Hi' }, + }); + expect(refused.isError).toBe(true); + }); + expect(await countRows(orm, JourneyEntryComments, { journey: journey.id })).toBe(2); + }); + it('JSOCIAL-MCP-002: a viewer may not hide, but deletes their own; a stranger reaches nothing', async () => { const { viewer, journey, comment } = await journeyWithComment(); const { user: stranger } = await makeUser(orm); diff --git a/wiki/MCP-Addon-Tools.md b/wiki/MCP-Addon-Tools.md index 3968ee4b4..ea3f54237 100644 --- a/wiki/MCP-Addon-Tools.md +++ b/wiki/MCP-Addon-Tools.md @@ -252,6 +252,7 @@ Requires `journey:read` or `journey:write` scope. | `list_journey_subscribers` | List the email addresses following a journey's share link: the confirmed ones (`count`) and the ones still waiting for their confirmation (`pending`). Owner only, requires `journey:share`. | | `remove_journey_subscriber` | Remove one address from the followers of a journey's share link. Owner only, requires `journey:share`. | | `list_journey_comments` | List the comments under a journey's entries, oldest first. Hidden comments are listed for the journey's editors only. | +| `add_journey_comment` | Comment under an entry of a journey you are on, as plain text (up to 2000 characters). It shows to everyone on the journey and, while the share link allows comments, to its readers. | | `set_journey_comment_hidden` | Hide a comment from everyone but the journey's editors, or show it again. Editors only. | | `delete_journey_comment` | Delete a comment. Its author, or an editor of the journey. | | `get_book` | The journey's photo book from the Studio, without its document: version, title, page format and every page with its id, role, photos and first words. Page and element ids for the tools below come from here. Any member may read it. |