File size: 2,465 Bytes
7dc28be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { FastMCP } from 'fastmcp';
import { UserError } from 'fastmcp';
import { z } from 'zod';
import { google } from 'googleapis';
import { getAuthClient } from '../../../clients.js';
import { DocumentIdParameter } from '../../../types.js';

export function register(server: FastMCP) {
  server.addTool({
    name: 'resolveComment',
    description:
      'Marks a comment as resolved. Note: resolved status may not persist in the Google Docs UI due to a Drive API limitation.',
    parameters: DocumentIdParameter.extend({
      commentId: z.string().describe('The ID of the comment to resolve'),
    }),
    execute: async (args, { log }) => {
      log.info(`Resolving comment ${args.commentId} in doc ${args.documentId}`);

      try {
        const authClient = await getAuthClient();
        const drive = google.drive({ version: 'v3', auth: authClient });

        // First, get the current comment content (required by the API)
        const currentComment = await drive.comments.get({
          fileId: args.documentId,
          commentId: args.commentId,
          fields: 'content',
        });

        // Update with both content and resolved status
        await drive.comments.update({
          fileId: args.documentId,
          commentId: args.commentId,
          fields: 'id,resolved',
          requestBody: {
            content: currentComment.data.content,
            resolved: true,
          },
        });

        // Verify the resolved status was set
        const verifyComment = await drive.comments.get({
          fileId: args.documentId,
          commentId: args.commentId,
          fields: 'resolved',
        });

        if (verifyComment.data.resolved) {
          return `Comment ${args.commentId} has been marked as resolved.`;
        } else {
          return `Attempted to resolve comment ${args.commentId}, but the resolved status may not persist in the Google Docs UI due to API limitations. The comment can be resolved manually in the Google Docs interface.`;
        }
      } catch (error: any) {
        log.error(`Error resolving comment: ${error.message || error}`);
        const errorDetails =
          error.response?.data?.error?.message || error.message || 'Unknown error';
        const errorCode = error.response?.data?.error?.code;
        throw new UserError(
          `Failed to resolve comment: ${errorDetails}${errorCode ? ` (Code: ${errorCode})` : ''}`
        );
      }
    },
  });
}