Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

gcp-spanner-list-databases

List all databases in a Google Cloud Spanner instance to manage and query database resources through the Google Cloud MCP Server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instanceIdYesSpanner instance ID

Implementation Reference

  • The main execution handler for the 'gcp-spanner-list-databases' tool. Retrieves project ID from state or auth, creates Spanner client, lists databases for the given instanceId, formats results as Markdown table with project/instance info and resource URIs for tables/schema.
    async ({ instanceId }, _extra) => {
      try {
        // First try to get the project ID from the state manager
        let projectId = stateManager.getCurrentProjectId();
    
        if (!projectId) {
          // If not in state manager, try to get it from our function
          const authProjectId = await getProjectId();
          if (authProjectId) {
            projectId = authProjectId;
            logger.debug(`Got project ID from getProjectId: ${projectId}`);
          }
        } else {
          logger.debug(`Got project ID from state manager: ${projectId}`);
        }
    
        if (!projectId) {
          throw new Error(
            "Project ID could not be determined. Please set a project ID using the set-project-id tool.",
          );
        }
    
        // Create Spanner client with explicit project ID
        const spanner = new (await import("@google-cloud/spanner")).Spanner({
          projectId: projectId,
        });
    
        logger.debug(
          `Using Spanner client with project ID: ${projectId} for list-spanner-databases`,
        );
        const instance = spanner.instance(
          Array.isArray(instanceId) ? instanceId[0] : instanceId,
        );
    
        const [databases] = await instance.getDatabases();
    
        if (!databases || databases.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `# Spanner Databases\n\nProject: ${projectId}\nInstance: ${Array.isArray(instanceId) ? instanceId[0] : instanceId}\n\nNo databases found in the instance.`,
              },
            ],
          };
        }
    
        let markdown = `# Spanner Databases\n\nProject: ${projectId}\nInstance: ${Array.isArray(instanceId) ? instanceId[0] : instanceId}\n\n`;
    
        // Table header
        markdown += "| Database ID | State |\n";
        markdown += "|-------------|-------|\n";
    
        // Table rows
        for (const database of databases) {
          const metadata = database.metadata || {};
          markdown += `| ${database.id || "unknown"} | ${metadata.state || "unknown"} |\n`;
        }
    
        // Add resource links for further exploration
        markdown += "\n## Available Resources\n\n";
    
        for (const database of databases) {
          markdown += `- Tables in ${database.id}: \`gcp-spanner://${projectId}/${Array.isArray(instanceId) ? instanceId[0] : instanceId}/${database.id}/tables\`\n`;
          markdown += `- Schema for ${database.id}: \`gcp-spanner://${projectId}/${Array.isArray(instanceId) ? instanceId[0] : instanceId}/${database.id}/schema\`\n`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: markdown,
            },
          ],
        };
      } catch (error: any) {
        logger.error(
          `Error listing Spanner databases: ${error instanceof Error ? error.message : String(error)}`,
        );
        throw error;
      }
  • Zod input schema for the tool, requiring 'instanceId' as a string.
    {
      instanceId: z.string().describe("Spanner instance ID"),
    },
  • Direct registration of the tool via server.tool() call inside registerSpannerTools(), specifying name, schema, and inline handler.
    server.tool(
      "gcp-spanner-list-databases",
      {
        instanceId: z.string().describe("Spanner instance ID"),
      },
      async ({ instanceId }, _extra) => {
        try {
          // First try to get the project ID from the state manager
          let projectId = stateManager.getCurrentProjectId();
    
          if (!projectId) {
            // If not in state manager, try to get it from our function
            const authProjectId = await getProjectId();
            if (authProjectId) {
              projectId = authProjectId;
              logger.debug(`Got project ID from getProjectId: ${projectId}`);
            }
          } else {
            logger.debug(`Got project ID from state manager: ${projectId}`);
          }
    
          if (!projectId) {
            throw new Error(
              "Project ID could not be determined. Please set a project ID using the set-project-id tool.",
            );
          }
    
          // Create Spanner client with explicit project ID
          const spanner = new (await import("@google-cloud/spanner")).Spanner({
            projectId: projectId,
          });
    
          logger.debug(
            `Using Spanner client with project ID: ${projectId} for list-spanner-databases`,
          );
          const instance = spanner.instance(
            Array.isArray(instanceId) ? instanceId[0] : instanceId,
          );
    
          const [databases] = await instance.getDatabases();
    
          if (!databases || databases.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `# Spanner Databases\n\nProject: ${projectId}\nInstance: ${Array.isArray(instanceId) ? instanceId[0] : instanceId}\n\nNo databases found in the instance.`,
                },
              ],
            };
          }
    
          let markdown = `# Spanner Databases\n\nProject: ${projectId}\nInstance: ${Array.isArray(instanceId) ? instanceId[0] : instanceId}\n\n`;
    
          // Table header
          markdown += "| Database ID | State |\n";
          markdown += "|-------------|-------|\n";
    
          // Table rows
          for (const database of databases) {
            const metadata = database.metadata || {};
            markdown += `| ${database.id || "unknown"} | ${metadata.state || "unknown"} |\n`;
          }
    
          // Add resource links for further exploration
          markdown += "\n## Available Resources\n\n";
    
          for (const database of databases) {
            markdown += `- Tables in ${database.id}: \`gcp-spanner://${projectId}/${Array.isArray(instanceId) ? instanceId[0] : instanceId}/${database.id}/tables\`\n`;
            markdown += `- Schema for ${database.id}: \`gcp-spanner://${projectId}/${Array.isArray(instanceId) ? instanceId[0] : instanceId}/${database.id}/schema\`\n`;
          }
    
          return {
            content: [
              {
                type: "text",
                text: markdown,
              },
            ],
          };
        } catch (error: any) {
          logger.error(
            `Error listing Spanner databases: ${error instanceof Error ? error.message : String(error)}`,
          );
          throw error;
        }
      },
    );
  • src/index.ts:170-170 (registration)
    Top-level call to registerSpannerTools(server) in the main server initialization, which triggers the tool registrations including gcp-spanner-list-databases.
    registerSpannerTools(server);
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