MCP: edit_comment and delete_comment tools #121

Merged
jared merged 2 commits from mcp-comment-edit-delete into development 2026-11-25 17:27:57 -05:00
Owner

Adds two MCP tools so Claude (and other MCP clients) can edit and delete ticket comments, with the same rules as the web UI.

Tools

Tool Scope What it does
edit_comment tickets:write Replace a comment's text (comment_id, text, optional markdown, default on).
delete_comment tickets:write Delete a comment. Its replies are deleted with it, and the result reports replies_removed.
  • comment_id comes from get_ticket, which already lists each comment's id.
  • Who can do what: only the comment's author can edit or delete it. Admins can edit or delete any comment, including system comments with no author.
  • Hidden tickets: a comment on a ticket you can't see reads as "Comment N not found", the same as a missing one, so restricted tickets aren't revealed. This matches how the other tools treat tickets.
  • Annotations: edit_comment is an idempotent update. delete_comment is marked destructive, like unlink_tickets, so clients can ask before running it.

One code path with the web UI

  • The access check, the owner-or-admin rule and the audit entry used to sit inline in api/update_comment.php and api/delete_comment.php. They now live in CommentService::updateComment / deleteComment, the way add_comment was shared in #111. The two endpoints and the MCP tools all call the service.
  • The endpoints' responses and status codes are unchanged, apart from two extra fields on success: ticket_id and replies_removed.

Deleting a comment deletes its replies. This has always been true in the web UI too, through fk_parent_comment ON DELETE CASCADE, but nothing reported it. The delete tool's result and the audit entry now record how many replies went with it.

Verified locally (throwaway tinker_ui database, synthetic users)

MCP tools: 19/19 checks pass.

  • An author edits their own comment: the text is trimmed and stored, the markdown flag is saved, and the edit is audit-logged.
  • Empty text is rejected, and a missing comment reads as not found.
  • Another user can't edit or delete the comment, and its text stays unchanged.
  • On a confidential ticket the user can't see, both tools say "not found" and the comment is untouched.
  • An admin can edit a system comment; a non-admin can't.
  • Deleting a comment with a reply chain two deep removes all three rows and reports replies_removed: 2, in the result and in the audit row. Deleting it again says not found.
  • edit_comment and delete_comment are both gated by tickets:write.

Tool schemas: built from a real server build. comment_id is an integer, text is required, and markdown defaults to true.

Web endpoints with curl, with a real session and CSRF token:

Request Response
Edit own comment 200
Empty text 400
Someone else's comment 200 with the permission error
Hidden ticket, edit or delete 403
Delete own comment 200
Bad CSRF token 403

All match the old endpoints.

phpcs is clean.

There's no visual change, so this PR has no screenshots. It doesn't depend on #120.

🤖 Generated with Claude Code

Adds two MCP tools so Claude (and other MCP clients) can edit and delete ticket comments, with the same rules as the web UI. ## Tools | Tool | Scope | What it does | |---|---|---| | `edit_comment` | `tickets:write` | Replace a comment's text (`comment_id`, `text`, optional `markdown`, default on). | | `delete_comment` | `tickets:write` | Delete a comment. Its replies are deleted with it, and the result reports `replies_removed`. | - `comment_id` comes from `get_ticket`, which already lists each comment's id. - **Who can do what:** only the comment's author can edit or delete it. Admins can edit or delete any comment, including system comments with no author. - **Hidden tickets:** a comment on a ticket you can't see reads as "Comment N not found", the same as a missing one, so restricted tickets aren't revealed. This matches how the other tools treat tickets. - **Annotations:** `edit_comment` is an idempotent update. `delete_comment` is marked destructive, like `unlink_tickets`, so clients can ask before running it. ## One code path with the web UI - The access check, the owner-or-admin rule and the audit entry used to sit inline in `api/update_comment.php` and `api/delete_comment.php`. They now live in `CommentService::updateComment` / `deleteComment`, the way `add_comment` was shared in #111. The two endpoints and the MCP tools all call the service. - The endpoints' responses and status codes are unchanged, apart from two extra fields on success: `ticket_id` and `replies_removed`. **Deleting a comment deletes its replies.** This has always been true in the web UI too, through `fk_parent_comment ON DELETE CASCADE`, but nothing reported it. The delete tool's result and the audit entry now record how many replies went with it. ## Verified locally (throwaway `tinker_ui` database, synthetic users) **MCP tools: 19/19 checks pass.** - An author edits their own comment: the text is trimmed and stored, the markdown flag is saved, and the edit is audit-logged. - Empty text is rejected, and a missing comment reads as not found. - Another user can't edit or delete the comment, and its text stays unchanged. - On a confidential ticket the user can't see, both tools say "not found" and the comment is untouched. - An admin can edit a system comment; a non-admin can't. - Deleting a comment with a reply chain two deep removes all three rows and reports `replies_removed: 2`, in the result and in the audit row. Deleting it again says not found. - `edit_comment` and `delete_comment` are both gated by `tickets:write`. **Tool schemas:** built from a real server build. `comment_id` is an integer, `text` is required, and `markdown` defaults to true. **Web endpoints with curl, with a real session and CSRF token:** | Request | Response | |---|---| | Edit own comment | 200 | | Empty text | 400 | | Someone else's comment | 200 with the permission error | | Hidden ticket, edit or delete | 403 | | Delete own comment | 200 | | Bad CSRF token | 403 | All match the old endpoints. phpcs is clean. There's no visual change, so this PR has no screenshots. It doesn't depend on #120. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared added 1 commit 2026-11-25 17:20:08 -05:00
MCP: edit_comment and delete_comment tools
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 35s
Lint / PHP requirements (version + extensions) (push) Successful in 34s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m0s
Security / PHP Security (semgrep) (push) Successful in 2m44s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 1m9s
Lint / JS (eslint) (pull_request) Successful in 14s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (pull_request) Successful in 1m44s
450b2fac3b
Two new tickets:write tools, on the same code path as the web UI's comment
edit/delete. The access check, owner-or-admin rule and audit entry moved
out of api/update_comment.php and api/delete_comment.php into
CommentService::updateComment/deleteComment (as add_comment did in #111),
and both endpoints now call it; their responses and status codes are
unchanged apart from extra ticket_id/replies_removed fields.

- edit_comment: replace a comment's text (own comments; admins any).
- delete_comment: delete a comment; replies go with it
  (fk_parent_comment ON DELETE CASCADE), so the result and the audit
  entry report replies_removed.
- A comment on a ticket the user can't see reads as "Comment N not
  found", like a missing one, so restricted tickets stay hidden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jared added 1 commit 2026-11-25 17:23:10 -05:00
MCP get_ticket: say which tools take a comment_id
Lint / PHP (phpcs PSR-12) (push) Successful in 35s
Lint / JS (eslint) (push) Successful in 12s
Lint / PHP requirements (version + extensions) (push) Successful in 33s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / JS (eslint) (pull_request) Successful in 12s
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 29s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 35s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (push) Successful in 2m18s
Security / PHP Security (semgrep) (pull_request) Successful in 2m4s
a819b1cb49
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Docs updated for this PR:

  • README: MCP tool table and the CommentService entry, in the PR itself.
  • get_ticket tool description: now says which tools take a comment_id (commit a819b1c).
  • Wiki, four pages:

After this reaches prod: two pages mark the new tools as "not deployed yet" / "coming with the next deploy" and should have that wording removed: Architecture/mcp-servers and Services/service-mcp-servers.

🤖 Generated with Claude Code

Docs updated for this PR: - **README:** MCP tool table and the `CommentService` entry, in the PR itself. - **`get_ticket` tool description:** now says which tools take a `comment_id` (commit a819b1c). - **Wiki, four pages:** - [Architecture/mcp-servers](https://wiki.lotusguild.org/Architecture/mcp-servers): the full Tinker tool table, which was also missing `find_similar_tickets`, `link_tickets` and `unlink_tickets` from #113. Also two troubleshooting rows and a change-log entry. - [Services/service-mcp-servers](https://wiki.lotusguild.org/Services/service-mcp-servers) (public): tool list and summary. - [Services/service-tinker-tickets](https://wiki.lotusguild.org/Services/service-tinker-tickets) (public): the comment edit/delete line, plus a short MCP section. - [Services/Productivity/tinkertickets](https://wiki.lotusguild.org/Services/Productivity/tinkertickets): the MCP bullet, the reply-cascade gotcha, and the deploy row. The deploy row was corrected too: `development` deploys beta and `main` deploys prod. **After this reaches prod:** two pages mark the new tools as "not deployed yet" / "coming with the next deploy" and should have that wording removed: `Architecture/mcp-servers` and `Services/service-mcp-servers`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jared merged commit 13ffc51cb7 into development 2026-11-25 17:27:57 -05:00
Sign in to join this conversation.