/
PETPO
/
google-docs-mcp
Обзор
Документация
Войти
/
PETPO
/
google-docs-mcp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/tools/docs/insertTable.ts
57 строк
2 KB
Morgan Wright
fix: resolve field mask conflict for tabbed docs + fix renameTab request type
01 июн 2026, 18:19
01 июн 2026, 18:19
d1d5694
Код
Авторство
О чём код?
import type { FastMCP } from 'fastmcp'; import { UserError } from 'fastmcp'; import { z } from 'zod'; import { getDocsClient } from '../../clients.js'; import { DocumentIdParameter } from '../../types.js'; import * as GDocsHelpers from '../../googleDocsApiHelpers.js'; export function register(server: FastMCP) { server.addTool({ name: 'insertTable', description: 'Inserts an empty table with the specified number of rows and columns at a character index in the document.', parameters: DocumentIdParameter.extend({ rows: z.number().int().min(1).describe('Number of rows for the new table.'), columns: z.number().int().min(1).describe('Number of columns for the new table.'), index: z .number() .int() .min(1) .describe( "1-based character index within the document body. Use readDocument with format='json' to inspect indices." ), tabId: z .string() .optional() .describe( 'The ID of the specific tab to insert into. Use listDocumentTabs to get tab IDs. If not specified, inserts into the first tab.' ), }), execute: async (args, { log }) => { const docs = await getDocsClient(); log.info( `Inserting ${args.rows}x${args.columns} table in doc ${args.documentId} at index ${args.index}${args.tabId ? ` (tab: ${args.tabId})` : ''}` ); try { // If tabId is specified, verify the tab exists if (args.tabId) { const targetTab = await GDocsHelpers.getDocumentTab(docs, args.documentId, args.tabId); } await GDocsHelpers.createTable( docs, args.documentId, args.rows, args.columns, args.index, args.tabId ); return `Successfully inserted a ${args.rows}x${args.columns} table at index ${args.index}${args.tabId ? ` in tab ${args.tabId}` : ''}.`; } catch (error: any) { log.error(`Error inserting table in doc ${args.documentId}: ${error.message || error}`); if (error instanceof UserError) throw error; throw new UserError(`Failed to insert table: ${error.message || 'Unknown error'}`); } }, }); }