File size: 1,655 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
import type { FastMCP } from 'fastmcp';
import { UserError } from 'fastmcp';
import { z } from 'zod';
import { google } from 'googleapis';
import { getAuthClient } from '../../../clients.js';

export function register(server: FastMCP) {
  server.addTool({
    name: 'replyToSheetsComment',
    description:
      'Adds a reply to an existing comment thread in a Google Spreadsheet. Use listSheetsComments or getSheetsComment to find the comment ID.',
    parameters: z.strictObject({
      spreadsheetId: z
        .string()
        .describe(
          'The spreadsheet ID — the long string between /d/ and /edit in a Google Sheets URL.'
        ),
      commentId: z.string().describe('The ID of the comment to reply to.'),
      content: z.string().min(1).describe('The text content of the reply.'),
    }),
    execute: async (args, { log }) => {
      log.info(`Adding reply to comment ${args.commentId} in spreadsheet ${args.spreadsheetId}`);

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

        const response = await drive.replies.create({
          fileId: args.spreadsheetId,
          commentId: args.commentId,
          fields: 'id,content,author,createdTime',
          requestBody: {
            content: args.content,
          },
        });

        return `Reply added successfully. Reply ID: ${response.data.id}`;
      } catch (error: any) {
        log.error(`Error adding reply to sheets comment: ${error.message || error}`);
        throw new UserError(`Failed to add reply: ${error.message || 'Unknown error'}`);
      }
    },
  });
}