Skip to main content
Glama

write_sheet

Write data to specified ranges in Google Sheets. Use this tool to update spreadsheet cells with new values programmatically.

Instructions

スプレッドシートの指定された範囲にデータを書き込みます

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
spreadsheetIdYesスプレッドシートのID
rangeYes書き込む範囲(例: 'Sheet1!A1:C10')
valuesYes書き込むデータ(2次元配列)

Implementation Reference

  • The handler function that executes the write_sheet tool logic, using Google Sheets API to update values in the specified range.
    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}`,
          },
        ],
      };
    }
  • The input schema defining parameters for the write_sheet tool: spreadsheetId, range, and values (2D array).
    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 (registration)
    The switch case in the CallToolRequestSchema handler that registers and dispatches to the writeSheet function for write_sheet tool calls.
    case "write_sheet":
      return await writeSheet(
        args.spreadsheetId as string,
        args.range as string,
        args.values as string[][]
      );
  • src/index.ts:56-83 (registration)
    The tool definition object in the tools array used for ListToolsRequestSchema, registering the write_sheet tool's name, description, and 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"],
      },
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Kyohei-9841/google-spreadsheet-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server