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
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
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>
This commit is contained in:
1 parent
bdc6028572
commit
450b2fac3b
6 files changed
+209
-102
No files matched your search
@@ -15,7 +15,10 @@ use TinkerTickets\Mcp\Tools\TicketWriteTools;
|
||||
final class ToolCatalog
|
||||
{
|
||||
/** Tool names that mutate data and require tickets:write. */
|
||||
private const WRITE_TOOLS = ['create_ticket', 'add_comment', 'update_status', 'assign_ticket', 'link_tickets', 'unlink_tickets'];
|
||||
private const WRITE_TOOLS = [
|
||||
'create_ticket', 'add_comment', 'edit_comment', 'delete_comment',
|
||||
'update_status', 'assign_ticket', 'link_tickets', 'unlink_tickets',
|
||||
];
|
||||
|
||||
public static function isWriteTool(string $name): bool
|
||||
{
|
||||
@@ -27,7 +30,7 @@ final class ToolCatalog
|
||||
$read = new TicketReadTools($conn);
|
||||
$write = new TicketWriteTools($conn);
|
||||
$readOnly = new ToolAnnotations(readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false);
|
||||
// Writes change tickets (and notify people); only unlink_tickets removes anything.
|
||||
// Writes change tickets (and notify people); unlink_tickets and delete_comment remove things.
|
||||
$additive = new ToolAnnotations(readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false);
|
||||
$update = new ToolAnnotations(readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false);
|
||||
$remove = new ToolAnnotations(readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false);
|
||||
@@ -38,6 +41,8 @@ final class ToolCatalog
|
||||
->addTool([$read, 'findSimilarTickets'], 'find_similar_tickets', 'Find similar tickets', null, $readOnly)
|
||||
->addTool([$write, 'createTicket'], 'create_ticket', 'Create ticket', null, $additive)
|
||||
->addTool([$write, 'addComment'], 'add_comment', 'Add comment', null, $additive)
|
||||
->addTool([$write, 'editComment'], 'edit_comment', 'Edit comment', null, $update)
|
||||
->addTool([$write, 'deleteComment'], 'delete_comment', 'Delete comment', null, $remove)
|
||||
->addTool([$write, 'updateStatus'], 'update_status', 'Update ticket status', null, $update)
|
||||
->addTool([$write, 'assignTicket'], 'assign_ticket', 'Assign ticket', null, $update)
|
||||
->addTool([$write, 'linkTickets'], 'link_tickets', 'Link tickets', null, $additive)
|
||||
|
||||
@@ -111,6 +111,55 @@ final class TicketWriteTools
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit one of your comments (admins can edit anyone's). The new text
|
||||
* replaces the old; comment_id comes from get_ticket.
|
||||
*
|
||||
* @param int $comment_id The comment to edit.
|
||||
* @param string $text The new comment text.
|
||||
* @param bool $markdown Render the comment as markdown.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function editComment(int $comment_id, string $text, bool $markdown = true): array
|
||||
{
|
||||
$user = McpIdentity::user();
|
||||
$result = \CommentService::updateComment($this->conn, $user, [
|
||||
'comment_id' => $comment_id,
|
||||
'comment_text' => $text,
|
||||
'markdown_enabled' => $markdown,
|
||||
]);
|
||||
if (empty($result['success'])) {
|
||||
throw new ToolCallException($this->commentError($result, $comment_id));
|
||||
}
|
||||
|
||||
return ['comment_id' => $comment_id, 'ticket_id' => (string)$result['ticket_id'], 'edited' => true];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete one of your comments (admins can delete anyone's). Replies to it
|
||||
* are deleted with it; replies_removed says how many. This can't be undone.
|
||||
*
|
||||
* @param int $comment_id The comment to delete; comment_id comes from get_ticket.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function deleteComment(int $comment_id): array
|
||||
{
|
||||
$user = McpIdentity::user();
|
||||
$result = \CommentService::deleteComment($this->conn, $user, ['comment_id' => $comment_id]);
|
||||
if (empty($result['success'])) {
|
||||
throw new ToolCallException($this->commentError($result, $comment_id));
|
||||
}
|
||||
|
||||
return [
|
||||
'comment_id' => $comment_id,
|
||||
'ticket_id' => (string)$result['ticket_id'],
|
||||
'deleted' => true,
|
||||
'replies_removed' => (int)($result['replies_removed'] ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Change a ticket's status. Transitions follow the Workflow Designer rules;
|
||||
* some transitions (e.g. closing) require a comment, which is posted as the reason.
|
||||
@@ -301,6 +350,22 @@ final class TicketWriteTools
|
||||
return (int)$match['user_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Comment failures: a comment on a ticket the user can't see reads as
|
||||
* "not found", like a missing one. "Not your comment" is passed through:
|
||||
* the user can already see that comment on the ticket.
|
||||
*
|
||||
* @param array<string, mixed> $result
|
||||
*/
|
||||
private function commentError(array $result, int $commentId): string
|
||||
{
|
||||
$error = (string)($result['error'] ?? 'Request failed');
|
||||
if (in_array($error, ['Access denied', 'Comment not found'], true)) {
|
||||
return "Comment {$commentId} not found";
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a shared-service failure to a tool error. A ticket the user can't
|
||||
* see reads as "not found" (like get_ticket), never "access denied", so a
|
||||
|
||||
Reference in new issue
Block a user