Skip to content

fix(activities): Add comment MCP tools - #43

Merged
Rishavraaj merged 2 commits into
mainfrom
feat/mcp-comments-tools
Sep 16, 2026
Merged

Rishavraaj merged 2 commits into
mainfrom
feat/mcp-comments-tools

Conversation

@anujeet98

@anujeet98 anujeet98 commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

Adds MCP tools for comments (add_comment, list_comments, update_comment, delete_comment) covering tasks, deals, companies, and contacts through ActivityService, scoped by new comments:read/comments:write.

While building this, found that the activities REST endpoints (list/get/update/delete + per-entity comment/timeline routes) had no org-membership check — only session auth. Fixed by verifying the underlying entity belongs to the caller's org before touching ActivityService, and applied the same check inside the new MCP tools (which call ActivityService directly, not through the REST controllers).

Also extracted ActivitiesController into its own ActivitiesModule — it now needs TaskService alongside the existing Deals/Companies/Contacts services, and that didn't belong bolted onto SalesModule.

Changes

  • MCP: add_comment, list_comments, update_comment, delete_comment in mcp-server.ts, new comments:* scopes
  • Fix: OrganizationGuard + entity-org verification on all 5 activities controllers; generic GET /activities now requires entityType/entityId (was optional and unscoped — confirmed unused by the frontend without them)
  • Refactor: new ActivitiesModule (imports SalesModule + TasksModule), SalesModule back to deals/contacts/companies only
  • Docs: docs/concepts/mcp-server.mdx
  • Tests: activities.controller.spec.ts (org-check coverage), 14 new MCP tool tests

Test plan

  • bun nx run @zuko/backend:test — 279/279 pass
  • bun nx run @zuko/backend:build — clean
  • Booted the app directly to confirm ActivitiesModule resolves (caught a missing PrismaModule import this way)
  • oxfmt / oxlint — no new issues
  • Manual: existing UI comment/timeline flow still works for a normal same-org user
  • Manual: add_comment/list_comments via Claude, confirm it shows up in the UI

🤖 Generated with Claude Code

@anujeet98
anujeet98 force-pushed the feat/mcp-comments-tools branch from db82f92 to 91af346 Compare September 16, 2026 11:07
… MCP tools

Security fix: Activity rows have no organizationId column (only
entityType/entityId), and ActivitiesController's routes (list, get,
update, delete) plus the four nested per-entity comment/timeline
routes only checked AuthGuard. Since Prisma ids are globally unique,
any authenticated user could read, comment on, edit, or delete
comments/timeline entries for any deal/company/contact/task id,
regardless of organization membership. The old (now-dead)
libs/agents leave-comment LangChain tool had the same gap.

Fixed by adding OrganizationGuard to every activities route and
verifying the underlying entity belongs to the caller's active org
(via each entity service's existing org-scoped findById /
TaskService.getTaskById, which already throw NotFoundException)
before touching ActivityService. The generic /activities list
endpoint previously allowed omitting entityType/entityId entirely,
which can't be scoped safely without a join across four tables and
wasn't used by the frontend — now requires both.

TaskService is exported from TasksModule and imported into
SalesModule so ActivitiesController can reach it alongside the
existing Deals/Companies/Contacts services.

Also adds four MCP tools mirroring this: add_comment, list_comments,
update_comment, delete_comment, generic across task/deal/company/
contact via ActivityService (comments:read/comments:write scopes).
Since MCP calls ActivityService directly rather than through the now
org-checked REST controllers, each tool independently resolves the
entity's org via prisma and checks it against the caller's
memberships before proceeding.

Unrelated: added .nxignore for apps/ai-agent/.eve/ (local Eve sandbox
runtime snapshots were duplicating project names and breaking the Nx
project graph for every target).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@anujeet98
anujeet98 force-pushed the feat/mcp-comments-tools branch from 91af346 to 6f5c90c Compare September 16, 2026 11:50
SalesModule owns deals/contacts/companies; importing TasksModule into
it just so ActivitiesController could inject TaskService for the
org-check muddied that scope, since activities/comments already span
tasks too (not just sales entities). Moved the 5 activities
controllers into a new ActivitiesModule that imports SalesModule and
TasksModule, and reverted SalesModule to its original imports/scope.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@anujeet98 anujeet98 changed the title fix(activities): scope comments to caller's org; add comment MCP tools fix(activities): Add comment MCP tools Sep 16, 2026
@Rishavraaj
Rishavraaj merged commit c9b18b7 into main Sep 16, 2026
1 check passed
@Rishavraaj
Rishavraaj deleted the feat/mcp-comments-tools branch September 16, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants