File size: 1,983 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
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: 'getComment',
    description:
      'Gets a specific comment and its full reply thread. Use listComments first to find the comment ID.',
    parameters: DocumentIdParameter.extend({
      commentId: z.string().describe('The ID of the comment to retrieve'),
    }),
    execute: async (args, { log }) => {
      log.info(`Getting comment ${args.commentId} from document ${args.documentId}`);

      try {
        const authClient = await getAuthClient();
        const drive = google.drive({ version: 'v3', auth: authClient });
        const response = await drive.comments.get({
          fileId: args.documentId,
          commentId: args.commentId,
          fields:
            'id,content,quotedFileContent,author,createdTime,resolved,replies(id,content,author,createdTime)',
        });

        const comment = response.data;
        return JSON.stringify(
          {
            id: comment.id,
            author: comment.author?.displayName || null,
            content: comment.content,
            quotedText: comment.quotedFileContent?.value || null,
            resolved: comment.resolved || false,
            createdTime: comment.createdTime,
            replies: (comment.replies || []).map((r: any) => ({
              id: r.id,
              author: r.author?.displayName || null,
              content: r.content,
              createdTime: r.createdTime,
            })),
          },
          null,
          2
        );
      } catch (error: any) {
        log.error(`Error getting comment: ${error.message || error}`);
        throw new UserError(`Failed to get comment: ${error.message || 'Unknown error'}`);
      }
    },
  });
}