write_sheet
Write data to specified ranges in Google Sheets using the Google Sheets MCP Server. Input spreadsheet ID, range, and values to update spreadsheets programmatically.
Instructions
スプレッドシートの指定された範囲にデータを書き込みます
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| range | Yes | 書き込む範囲(例: 'Sheet1!A1:C10') | |
| spreadsheetId | Yes | スプレッドシートのID | |
| values | Yes | 書き込むデータ(2次元配列) |
Implementation Reference
- src/index.ts:220-245 (handler)The handler function that writes the provided 2D array of values to the specified range in the Google Sheet using the Google Sheets v4 API's values.update method.async function writeSheet( spreadsheetId: string, range: string, values: string[][] ) { const authClient = await auth.getClient(); const sheets = google.sheets({ version: "v4", auth: authClient as any }); const response = await sheets.spreadsheets.values.update({ spreadsheetId, range, valueInputOption: "RAW", requestBody: { values, }, }); return { content: [ { type: "text", text: `データが正常に書き込まれました。更新されたセル数: ${response.data.updatedCells}`, }, ], }; }
- src/index.ts:59-82 (schema)Defines the input schema for the 'write_sheet' tool, specifying the required parameters: spreadsheetId, range, and values (2D array of strings).inputSchema: { type: "object", properties: { spreadsheetId: { type: "string", description: "スプレッドシートのID", }, range: { type: "string", description: "書き込む範囲(例: 'Sheet1!A1:C10')", }, values: { type: "array", items: { type: "array", items: { type: "string", }, }, description: "書き込むデータ(2次元配列)", }, }, required: ["spreadsheetId", "range", "values"], },
- src/index.ts:56-83 (registration)Registers the 'write_sheet' tool in the tools array, which is returned by the ListToolsRequestHandler, including name, description, and input schema.{ name: "write_sheet", description: "スプレッドシートの指定された範囲にデータを書き込みます", inputSchema: { type: "object", properties: { spreadsheetId: { type: "string", description: "スプレッドシートのID", }, range: { type: "string", description: "書き込む範囲(例: 'Sheet1!A1:C10')", }, values: { type: "array", items: { type: "array", items: { type: "string", }, }, description: "書き込むデータ(2次元配列)", }, }, required: ["spreadsheetId", "range", "values"], }, },
- src/index.ts:163-168 (handler)The switch case in the central CallToolRequestHandler that routes calls to the 'write_sheet' tool to the writeSheet function.case "write_sheet": return await writeSheet( args.spreadsheetId as string, args.range as string, args.values as string[][] );