Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

gcp-spanner-list-instances

List all Cloud Spanner instances in your Google Cloud project to manage database resources and configurations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
_dummyNoNot used, just to ensure parameter compatibility

Implementation Reference

  • The handler function for the 'gcp-spanner-list-instances' tool. It determines the GCP project ID, creates a Spanner client, lists all instances, formats the results as a Markdown table with instance details (ID, state, config, nodes), and provides resource links for further exploration.
    async (_params, _extra) => {
      try {
        // First try to get the project ID from the state manager
        let projectId = stateManager.getCurrentProjectId();
    
        if (projectId) {
          logger.debug(`Got project ID from state manager: ${projectId}`);
        } else {
          // If not in state manager, try to get it from environment
          const envProjectId = process.env.GOOGLE_CLOUD_PROJECT;
    
          if (envProjectId) {
            projectId = envProjectId;
            logger.debug(`Got project ID from environment: ${projectId}`);
            // Store in state manager for future use
            await stateManager.setCurrentProjectId(projectId);
          } else {
            // If not in environment, try to get it from our function
            projectId = await getProjectId();
            logger.debug(`Got project ID from getProjectId: ${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 explicit project ID: ${projectId} for list-spanner-instances`,
        );
    
        const [instances] = await spanner.getInstances();
    
        if (!instances || instances.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `# Spanner Instances\n\nProject: ${projectId}\n\nNo instances found in the project.`,
              },
            ],
          };
        }
    
        let markdown = `# Spanner Instances\n\nProject: ${projectId}\n\n`;
    
        // Table header
        markdown += "| Instance ID | State | Config | Nodes |\n";
        markdown += "|-------------|-------|--------|-------|\n";
    
        // Table rows
        for (const instance of instances) {
          const metadata = instance.metadata || {};
          markdown += `| ${instance.id || "unknown"} | ${metadata.state || "unknown"} | ${metadata.config?.split("/").pop() || "unknown"} | ${metadata.nodeCount || "unknown"} |\n`;
        }
    
        // Add resource links for further exploration
        markdown += "\n## Available Resources\n\n";
        markdown += `- All Instances: \`gcp-spanner://${projectId}/instances\`\n`;
    
        for (const instance of instances) {
          markdown += `- Databases in ${instance.id}: \`gcp-spanner://${projectId}/${instance.id}/databases\`\n`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: markdown,
            },
          ],
        };
      } catch (error: any) {
        logger.error(
          `Error listing Spanner instances: ${error instanceof Error ? error.message : String(error)}`,
        );
        throw error;
      }
    },
  • The Zod input schema for the tool. It defines an optional dummy string parameter to ensure compatibility with MCP clients that expect an object parameter.
    {
      _dummy: z
        .string()
        .optional()
        .describe("Not used, just to ensure parameter compatibility"),
    },
  • The registration of the 'gcp-spanner-list-instances' tool using server.tool(), including the inline schema and handler function.
    // Tool to list instances
    server.tool(
      "gcp-spanner-list-instances",
      // Define an empty schema with a dummy parameter that's optional
      // This ensures compatibility with clients that expect an object parameter
      {
        _dummy: z
          .string()
          .optional()
          .describe("Not used, just to ensure parameter compatibility"),
      },
      async (_params, _extra) => {
        try {
          // First try to get the project ID from the state manager
          let projectId = stateManager.getCurrentProjectId();
    
          if (projectId) {
            logger.debug(`Got project ID from state manager: ${projectId}`);
          } else {
            // If not in state manager, try to get it from environment
            const envProjectId = process.env.GOOGLE_CLOUD_PROJECT;
    
            if (envProjectId) {
              projectId = envProjectId;
              logger.debug(`Got project ID from environment: ${projectId}`);
              // Store in state manager for future use
              await stateManager.setCurrentProjectId(projectId);
            } else {
              // If not in environment, try to get it from our function
              projectId = await getProjectId();
              logger.debug(`Got project ID from getProjectId: ${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 explicit project ID: ${projectId} for list-spanner-instances`,
          );
    
          const [instances] = await spanner.getInstances();
    
          if (!instances || instances.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `# Spanner Instances\n\nProject: ${projectId}\n\nNo instances found in the project.`,
                },
              ],
            };
          }
    
          let markdown = `# Spanner Instances\n\nProject: ${projectId}\n\n`;
    
          // Table header
          markdown += "| Instance ID | State | Config | Nodes |\n";
          markdown += "|-------------|-------|--------|-------|\n";
    
          // Table rows
          for (const instance of instances) {
            const metadata = instance.metadata || {};
            markdown += `| ${instance.id || "unknown"} | ${metadata.state || "unknown"} | ${metadata.config?.split("/").pop() || "unknown"} | ${metadata.nodeCount || "unknown"} |\n`;
          }
    
          // Add resource links for further exploration
          markdown += "\n## Available Resources\n\n";
          markdown += `- All Instances: \`gcp-spanner://${projectId}/instances\`\n`;
    
          for (const instance of instances) {
            markdown += `- Databases in ${instance.id}: \`gcp-spanner://${projectId}/${instance.id}/databases\`\n`;
          }
    
          return {
            content: [
              {
                type: "text",
                text: markdown,
              },
            ],
          };
        } catch (error: any) {
          logger.error(
            `Error listing Spanner instances: ${error instanceof Error ? error.message : String(error)}`,
          );
          throw error;
        }
      },
    );
  • src/index.ts:170-170 (registration)
    Top-level registration call that invokes registerSpannerTools(server), which registers the Spanner tools including 'gcp-spanner-list-instances'.
    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