Skip to main content
Glama
HosakaKeigo

Spreadsheet MCP Server

by HosakaKeigo

getSpreadsheet

Retrieve spreadsheet metadata and sheet listings from Google Sheets using a URL to access document structure and contents.

Instructions

スプレッドシートの基本情報と含まれるシート一覧を取得

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesスプレッドシートのURL

Implementation Reference

  • Complete definition of the getSpreadsheet tool, including schema, description, and the handler function that extracts the spreadsheet ID from the URL, fetches the spreadsheet information using helper functions, formats the result, and returns it as structured content or error.
    export const getSpreadsheetTool = {
      name: "getSpreadsheet",
      description: "スプレッドシートの基本情報と含まれるシート一覧を取得",
      schema: {
        url: z.string().describe("スプレッドシートのURL")
      },
      handler: async ({ url }: { url: 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 formattedResult = formatSpreadsheetInfo(spreadsheetInfo);
    
          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
          };
        }
      }
    };
  • src/server.ts:27-32 (registration)
    Registers the getSpreadsheet tool with the MCP server using the server.tool method.
    server.tool(
      getSpreadsheetTool.name,
      getSpreadsheetTool.description,
      getSpreadsheetTool.schema,
      getSpreadsheetTool.handler
    );
  • Helper function that retrieves spreadsheet information by calling the Google Apps Script web app API (or mock data in mock mode). Called by the tool handler.
    export async function getSpreadsheetInfo(spreadsheetId: string): Promise<SpreadsheetInfo> {
      // モックモードの場合はモックデータを返す
      if (config.isMockMode) {
        return getMockSpreadsheetInfo(spreadsheetId);
      }
    
      // API呼び出し用のURLを生成
      const apiUrl = new URL(config.gas.webAppUrl);
      apiUrl.searchParams.append('action', 'getSpreadsheet');
      apiUrl.searchParams.append('id', spreadsheetId);
      apiUrl.searchParams.append('apiKey', config.gas.apiKey);
    
      // APIリクエスト
      const response = await fetch(apiUrl);
    
      // ステータスコードのチェック
      if (!response.ok) {
        const errorData = await response.json();
        throw new Error(errorData.message || `API Error: ${response.status}`);
      }
    
      // レスポンスをJSONとしてパース
      return await response.json() as SpreadsheetInfo;
    }
  • Helper function to extract the spreadsheet ID from a Google Sheets URL using regex. Used in the tool handler.
    export function extractSpreadsheetId(url: string): string | null {
      try {
        // URL自体がnullまたはundefinedの場合
        if (!url) {
          return null;
        }
    
        // 実際のGoogle SpreadsheetのURLからIDを抽出
        // 例: https://docs.google.com/spreadsheets/d/1a2b3c4d5e6f7g8h9i0j/edit#gid=0
        const regex = /\/d\/([a-zA-Z0-9_-]+)/;
        const match = url.match(regex);
    
        if (match && match[1]) {
          return match[1];
        }
    
        // モック用に特殊なURLも処理
        if (config.isMockMode && (url.includes("budget") || url.includes("project"))) {
          return url.includes("budget") ? "mock_budget" : "mock_project";
        }
    
        return null;
      } catch (error) {
        console.error("URL解析エラー:", error);
        return null;
      }
    }
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. It states the tool retrieves information (implying a read-only operation), but doesn't specify whether it requires authentication, has rate limits, returns paginated results, or handles errors. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 a single, concise sentence in Japanese that directly states the tool's function without unnecessary words. It's front-loaded with the core purpose and efficiently communicates the scope. Every part of the sentence earns its place by specifying what is retrieved.

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

Completeness3/5

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

Given the tool's low complexity (one parameter, no annotations, no output schema), the description is minimally adequate. It covers the basic purpose but lacks details on usage guidelines, behavioral traits, and output format. Without annotations or an output schema, the description should ideally provide more context about what 'basic information' includes and how results are structured.

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 input schema has 100% description coverage, with the single parameter 'url' documented as 'spreadsheet URL.' The description doesn't add any semantic details beyond what the schema provides (e.g., URL format, validation rules). Since schema coverage is high, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

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 basic information of a spreadsheet and the list of sheets it contains.' It specifies the verb ('get') and resource ('spreadsheet'), making the function unambiguous. However, it doesn't explicitly differentiate from the sibling tool 'getSheetData,' which likely retrieves different data (e.g., cell contents vs. metadata).

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 'getSheetData' or clarify the distinction between retrieving spreadsheet metadata versus sheet data. There's no context about prerequisites, limitations, or appropriate 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