Skip to main content
Glama
HosakaKeigo

Spreadsheet MCP Server

by HosakaKeigo

getSheetData

Extract data from specific sheets in Google Spreadsheets by providing the URL and sheet name to access structured information.

Instructions

スプレッドシートの特定シートのデータを取得

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesスプレッドシートのURL
sheetNameYes取得するシート名

Implementation Reference

  • The main execution logic for the 'getSheetData' tool handler. It processes the input URL and sheetName, validates the spreadsheet and sheet, fetches the data using helper functions, formats the result, and returns it in the expected MCP format.
    handler: async ({ url, sheetName }: { url: string; sheetName: string }) => {
      try {
        const spreadsheetId = extractSpreadsheetId(url);
    
        if (!spreadsheetId) {
          return {
            content: [
              {
                type: "text" as const,
                text: "有効なスプレッドシートURLではありません。Google SpreadsheetのURLを入力してください。"
              }
            ],
            isError: true
          };
        }
    
        // スプレッドシート情報を取得して、シート名が有効かチェック
        const spreadsheetInfo = await getSpreadsheetInfo(spreadsheetId);
        const isValidSheet = spreadsheetInfo.sheets.some(sheet => sheet.name === sheetName);
    
        if (!isValidSheet) {
          const availableSheets = spreadsheetInfo.sheets.map(sheet => sheet.name).join(", ");
          return {
            content: [
              {
                type: "text" as const,
                text: `シート「${sheetName}」は存在しません。利用可能なシート: ${availableSheets}`
              }
            ],
            isError: true
          };
        }
    
        // シートデータを取得
        const sheetData = await getSheetData(spreadsheetId, sheetName);
    
        // データをフォーマットして返す
        const formattedResult = formatSheetData(sheetData, sheetName, spreadsheetInfo.name);
    
        return {
          content: [
            {
              type: "text" as const,
              text: formattedResult
            }
          ]
        };
      } catch (error) {
        console.error("シートデータ取得エラー:", error);
        return {
          content: [
            {
              type: "text" as const,
              text: `シートデータの取得中にエラーが発生しました: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the getSheetData tool: spreadsheet URL and sheet name.
    schema: {
      url: z.string().describe("スプレッドシートのURL"),
      sheetName: z.string().describe("取得するシート名")
    },
  • src/server.ts:34-40 (registration)
    Registration of the getSheetData tool with the MCP server using server.tool().
    // シートデータ取得ツール
    server.tool(
      getSheetDataTool.name,
      getSheetDataTool.description,
      getSheetDataTool.schema,
      getSheetDataTool.handler
    );
  • Helper function that makes the actual API call to the Google Apps Script web app to retrieve sheet data, handling both real API and mock mode.
    export async function getSheetData(
      spreadsheetId: string,
      sheetName: string
    ): Promise<SheetData> {
      // モックモードの場合はモックデータを返す
      if (config.isMockMode) {
        return getMockSheetData(spreadsheetId, sheetName);
      }
    
      // API呼び出し用のURLを生成
      const apiUrl = new URL(config.gas.webAppUrl);
      apiUrl.searchParams.append('action', 'getSheetData');
      apiUrl.searchParams.append('id', spreadsheetId);
      apiUrl.searchParams.append('sheetName', sheetName);
      apiUrl.searchParams.append('apiKey', config.gas.apiKey);
    
      // 任意のパラメータ(必要に応じて)
      // apiUrl.searchParams.append('maxRows', '1000');
    
      // APIリクエスト
      const response = await fetch(apiUrl);
    
      // ステータスコードのチェック
      if (!response.ok) {
        const errorData = await response.json();
        throw new Error(errorData.message || `API Error: ${response.status}`);
      }
    
      // レスポンスをJSONとしてパース
      const result = await response.json();
    
      // APIのレスポンス形式を SheetData 形式(二次元配列)に変換
      return result.data as SheetData;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While '取得' (get) implies a read operation, the description doesn't specify whether this requires authentication, what format the data is returned in (e.g., array, object), whether there are rate limits, or if there are any side effects. For a data retrieval tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single Japanese sentence that directly states the tool's function without any unnecessary words. It's front-loaded with the core purpose and contains zero redundant information. Every word earns its place in communicating the essential function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there's no output schema and no annotations, the description should provide more context about what the tool returns and how it behaves. The description only states what the tool does at a high level without addressing the return format, error conditions, or operational constraints. For a data retrieval tool with 2 parameters, this level of description is insufficient for an agent to understand the complete context of use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with both parameters ('url' and 'sheetName') fully documented in the schema. The description doesn't add any parameter-specific information beyond what's already in the schema. According to the scoring rules, when schema coverage is high (>80%), the baseline score is 3 even without parameter details in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'スプレッドシートの特定シートのデータを取得' (Get data from a specific sheet in a spreadsheet). It specifies the verb ('取得' - get) and resource ('スプレッドシートの特定シートのデータ' - data from a specific sheet in a spreadsheet), making the function unambiguous. However, it doesn't explicitly differentiate from the sibling tool 'getSpreadsheet', which likely retrieves spreadsheet metadata rather than sheet data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tool 'getSpreadsheet' or explain scenarios where one would choose this tool over others. There's no information about prerequisites, constraints, or typical use cases beyond the basic function.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/HosakaKeigo/spreadsheet-mcp-server'

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