Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

gcp-spanner-list-tables

Lists all tables in a Google Cloud Spanner database to view database structure and schema information. Specify instance and database IDs to retrieve table names.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instanceIdNoSpanner instance ID (defaults to SPANNER_INSTANCE env var)
databaseIdNoSpanner database ID (defaults to SPANNER_DATABASE env var)

Implementation Reference

  • The handler function executes the tool logic: retrieves project and Spanner config, runs SQL query on information_schema.tables to list tables and column counts, formats results as Markdown table with project/instance/database info and resource URIs.
    async ({ instanceId, databaseId }, _extra) => {
      try {
        const projectId = await getProjectId();
        const config = await getSpannerConfig(
          Array.isArray(instanceId) ? instanceId[0] : instanceId,
          Array.isArray(databaseId) ? databaseId[0] : databaseId,
        );
    
        const spanner = await getSpannerClient();
        logger.debug(
          `Using Spanner client with project ID: ${spanner.projectId} for execute-spanner-query`,
        );
        const instance = spanner.instance(config.instanceId);
        const database = instance.database(config.databaseId);
    
        // Query for tables
        // Execute query to list tables
        const [tablesResult] = await database.run({
          sql: `SELECT t.table_name, 
                    (SELECT COUNT(1) FROM information_schema.columns 
                     WHERE table_name = t.table_name) as column_count
              FROM information_schema.tables t
              WHERE t.table_catalog = '' AND t.table_schema = ''
              ORDER BY t.table_name`,
        });
    
        if (!tablesResult || tablesResult.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `# Spanner Tables\n\nProject: ${projectId}\nInstance: ${config.instanceId}\nDatabase: ${config.databaseId}\n\nNo tables found in the database.`,
              },
            ],
          };
        }
    
        let markdown = `# Spanner Tables\n\nProject: ${projectId}\nInstance: ${config.instanceId}\nDatabase: ${config.databaseId}\n\n`;
    
        // Table header
        markdown += "| Table Name | Column Count |\n";
        markdown += "|------------|-------------|\n";
    
        // Table rows
        for (const row of tablesResult) {
          // Access the row properties directly
    
          // Extract table name and column count
          const tableName = ((row as any).table_name as string) || "unknown";
          const columnCount = ((row as any).column_count as number) || 0;
    
          markdown += `| ${tableName} | ${columnCount} |\n`;
        }
    
        // Add resource links for further exploration
        markdown += "\n## Available Resources\n\n";
        markdown += `- Schema: \`gcp-spanner://${projectId}/${config.instanceId}/${config.databaseId}/schema\`\n`;
    
        for (const row of tablesResult) {
          const tableName = ((row as any).table_name as string) || "unknown";
          markdown += `- Table Preview: \`gcp-spanner://${projectId}/${config.instanceId}/${config.databaseId}/tables/${tableName}/preview\`\n`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: markdown,
            },
          ],
        };
      } catch (error: any) {
        logger.error(
          `Error listing Spanner tables: ${error instanceof Error ? error.message : String(error)}`,
        );
        throw error;
      }
    },
  • Input schema using Zod for optional instanceId and databaseId parameters, with descriptions.
      instanceId: z
        .string()
        .optional()
        .describe("Spanner instance ID (defaults to SPANNER_INSTANCE env var)"),
      databaseId: z
        .string()
        .optional()
        .describe("Spanner database ID (defaults to SPANNER_DATABASE env var)"),
    },
  • Registration of the 'gcp-spanner-list-tables' tool using server.tool() inside the registerSpannerTools function.
    server.tool(
      "gcp-spanner-list-tables",
      {
        instanceId: z
          .string()
          .optional()
          .describe("Spanner instance ID (defaults to SPANNER_INSTANCE env var)"),
        databaseId: z
          .string()
          .optional()
          .describe("Spanner database ID (defaults to SPANNER_DATABASE env var)"),
      },
      async ({ instanceId, databaseId }, _extra) => {
        try {
          const projectId = await getProjectId();
          const config = await getSpannerConfig(
            Array.isArray(instanceId) ? instanceId[0] : instanceId,
            Array.isArray(databaseId) ? databaseId[0] : databaseId,
          );
    
          const spanner = await getSpannerClient();
          logger.debug(
            `Using Spanner client with project ID: ${spanner.projectId} for execute-spanner-query`,
          );
          const instance = spanner.instance(config.instanceId);
          const database = instance.database(config.databaseId);
    
          // Query for tables
          // Execute query to list tables
          const [tablesResult] = await database.run({
            sql: `SELECT t.table_name, 
                      (SELECT COUNT(1) FROM information_schema.columns 
                       WHERE table_name = t.table_name) as column_count
                FROM information_schema.tables t
                WHERE t.table_catalog = '' AND t.table_schema = ''
                ORDER BY t.table_name`,
          });
    
          if (!tablesResult || tablesResult.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `# Spanner Tables\n\nProject: ${projectId}\nInstance: ${config.instanceId}\nDatabase: ${config.databaseId}\n\nNo tables found in the database.`,
                },
              ],
            };
          }
    
          let markdown = `# Spanner Tables\n\nProject: ${projectId}\nInstance: ${config.instanceId}\nDatabase: ${config.databaseId}\n\n`;
    
          // Table header
          markdown += "| Table Name | Column Count |\n";
          markdown += "|------------|-------------|\n";
    
          // Table rows
          for (const row of tablesResult) {
            // Access the row properties directly
    
            // Extract table name and column count
            const tableName = ((row as any).table_name as string) || "unknown";
            const columnCount = ((row as any).column_count as number) || 0;
    
            markdown += `| ${tableName} | ${columnCount} |\n`;
          }
    
          // Add resource links for further exploration
          markdown += "\n## Available Resources\n\n";
          markdown += `- Schema: \`gcp-spanner://${projectId}/${config.instanceId}/${config.databaseId}/schema\`\n`;
    
          for (const row of tablesResult) {
            const tableName = ((row as any).table_name as string) || "unknown";
            markdown += `- Table Preview: \`gcp-spanner://${projectId}/${config.instanceId}/${config.databaseId}/tables/${tableName}/preview\`\n`;
          }
    
          return {
            content: [
              {
                type: "text",
                text: markdown,
              },
            ],
          };
        } catch (error: any) {
          logger.error(
            `Error listing Spanner tables: ${error instanceof Error ? error.message : String(error)}`,
          );
          throw error;
        }
      },
    );
  • src/index.ts:169-170 (registration)
    Call to registerSpannerTools(server) in the main server initialization, which registers the Spanner tools including gcp-spanner-list-tables.
    registerSpannerResources(server);
    registerSpannerTools(server);
  • Re-export of registerSpannerTools from tools.ts for use in main index.ts.
    export { registerSpannerTools } from "./tools.js";
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/krzko/google-cloud-mcp'

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