Skip to main content
Glama

gcp_setup

Idempotent

Create and manage GCP configuration files (.hi-gcloud.json) for individual projects. Set project ID, region, and account details per project path.

Instructions

설정|초기화|프로필|setup|init|configure - 프로젝트별 GCP 설정 파일(.hi-gcloud.json)을 생성합니다. project_path에 현재 작업 폴더 경로를 지정하세요.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionNo수행할 작업. status: 현재 설정 확인, create: 설정 생성, update: 설정 업데이트status
project_pathNo프로젝트 경로 (현재 작업 폴더 경로를 지정하세요)
project_idNoGCP 프로젝트 ID
regionNo기본 리전 (예: asia-northeast3)
accountNo계정 이메일

Implementation Reference

  • Main handler function for the gcp_setup tool. Dispatches to getStatus (status action) or saveConfig (create/update action).
    export async function gcpSetup(args: GcpSetupArgs) {
      const action = args.action || 'status';
    
      try {
        switch (action) {
          case 'status':
            return await getStatus(args.project_path);
          case 'create':
          case 'update':
            return await saveConfig(args);
          default:
            return {
              content: [{ type: 'text', text: `알 수 없는 액션: ${action}` }],
              isError: true,
            };
        }
      } catch (error: any) {
        return {
          content: [{ type: 'text', text: `오류: ${error.message}` }],
          isError: true,
        };
      }
    }
  • Helper handler for 'status' action - reads current gcloud config and checks for .hi-gcloud.json config file.
    async function getStatus(projectPath?: string) {
      // Get current gcloud config
      let currentProject = '';
      let currentRegion = '';
      let currentAccount = '';
    
      try {
        const projectResult = await executeGcloud('config get-value project', 5000);
        currentProject = projectResult.stdout.trim();
        if (currentProject === '(unset)') currentProject = '';
      } catch {}
    
      try {
        const regionResult = await executeGcloud('config get-value compute/region', 5000);
        currentRegion = regionResult.stdout.trim();
        if (currentRegion === '(unset)') currentRegion = '';
      } catch {}
    
      try {
        const accountResult = await executeGcloud('auth list --format="value(account)" --filter="status:ACTIVE"', 5000);
        currentAccount = accountResult.stdout.trim();
      } catch {}
    
      // Check if .hi-gcloud.json exists
      let configExists = false;
      let existingConfig: any = null;
      if (projectPath) {
        const configPath = join(projectPath, '.hi-gcloud.json');
        if (existsSync(configPath)) {
          configExists = true;
          try {
            const { readFile } = await import('fs/promises');
            const content = await readFile(configPath, 'utf-8');
            existingConfig = JSON.parse(content);
          } catch {}
        }
      }
    
      const lines = [
        '📋 GCP 설정 상태',
        '',
        '## gcloud CLI 설정',
        `- 프로젝트: ${currentProject || '(미설정)'}`,
        `- 리전: ${currentRegion || '(미설정)'}`,
        `- 계정: ${currentAccount || '(미설정)'}`,
      ];
    
      if (projectPath) {
        lines.push('', '## 프로젝트 설정 파일');
        if (configExists && existingConfig) {
          lines.push(`✅ ${projectPath}/.hi-gcloud.json 존재`);
          lines.push(`- project_id: ${existingConfig.project_id || '(미설정)'}`);
          lines.push(`- region: ${existingConfig.region || '(미설정)'}`);
          lines.push(`- account: ${existingConfig.account || '(미설정)'}`);
        } else {
          lines.push(`❌ ${projectPath}/.hi-gcloud.json 없음`);
          lines.push('');
          lines.push('💡 설정 생성: gcp_setup(action: "create", project_path: "...")');
        }
      } else {
        lines.push('');
        lines.push('💡 project_path를 지정하면 프로젝트별 설정 파일을 확인할 수 있습니다.');
      }
    
      return {
        content: [{ type: 'text', text: lines.join('\n') }],
      };
    }
  • Helper handler for 'create'/'update' actions - builds config from gcloud defaults, auto-detects Cloud SQL instances, and writes .hi-gcloud.json file.
    async function saveConfig(args: GcpSetupArgs) {
      if (!args.project_path) {
        return {
          content: [{
            type: 'text',
            text: '❌ project_path가 필요합니다.\n\n예: gcp_setup(action: "create", project_path: "/path/to/project", project_id: "my-project")',
          }],
          isError: true,
        };
      }
    
      // Get current gcloud config as defaults
      let defaultProject = '';
      let defaultRegion = '';
      let defaultAccount = '';
    
      try {
        const projectResult = await executeGcloud('config get-value project', 5000);
        defaultProject = projectResult.stdout.trim();
        if (defaultProject === '(unset)') defaultProject = '';
      } catch {}
    
      try {
        const regionResult = await executeGcloud('config get-value compute/region', 5000);
        defaultRegion = regionResult.stdout.trim();
        // Handle various "unset" responses from gcloud
        if (!defaultRegion || defaultRegion === '(unset)' || defaultRegion === 'unset') {
          defaultRegion = '';
        }
      } catch {
        defaultRegion = '';
      }
    
      try {
        const accountResult = await executeGcloud('auth list --format="value(account)" --filter="status:ACTIVE"', 5000);
        defaultAccount = accountResult.stdout.trim();
      } catch {}
    
      // Auto-detect Cloud SQL instances
      let cloudSqlInstances: CloudSqlInstance[] = [];
      try {
        const projectId = args.project_id || defaultProject;
        if (projectId) {
          const sqlResult = await executeGcloud(`sql instances list --project=${projectId} --format="json"`, 15000);
          const instances = JSON.parse(sqlResult.stdout || '[]');
          cloudSqlInstances = instances.map((inst: any) => ({
            name: inst.name,
            region: inst.region,
            port: inst.databaseVersion?.startsWith('MYSQL') ? 3306 : 5432,
            database: inst.databaseVersion?.startsWith('MYSQL') ? 'mysql' : 'postgres',
          }));
        }
      } catch {}
    
      // Read existing config if updating
      const configPath = join(args.project_path, '.hi-gcloud.json');
      let existingConfig: any = {};
      if (existsSync(configPath)) {
        try {
          const { readFile } = await import('fs/promises');
          const content = await readFile(configPath, 'utf-8');
          existingConfig = JSON.parse(content);
        } catch {}
      }
    
      const newConfig = {
        project_id: args.project_id || existingConfig.project_id || defaultProject,
        region: args.region || existingConfig.region || defaultRegion || undefined,
        account: args.account || existingConfig.account || defaultAccount,
        cloud_sql: args.cloud_sql || existingConfig.cloud_sql || (cloudSqlInstances.length > 0 ? cloudSqlInstances : undefined),
      };
    
      if (!newConfig.project_id) {
        return {
          content: [{
            type: 'text',
            text: '❌ project_id가 필요합니다. gcloud에 설정된 프로젝트가 없으므로 직접 지정해주세요.\n\n예: gcp_setup(action: "create", project_path: "...", project_id: "my-project")',
          }],
          isError: true,
        };
      }
    
      await writeFile(configPath, JSON.stringify(newConfig, null, 2));
    
      const sqlInfo = newConfig.cloud_sql?.length
        ? `\n🗄️ Cloud SQL:\n${newConfig.cloud_sql.map((sql: CloudSqlInstance) => `   - ${sql.name} (${sql.region}, 포트: ${sql.port})`).join('\n')}`
        : '';
    
      return {
        content: [{
          type: 'text',
          text: `✅ ${configPath} 저장됨
    
    📁 프로젝트: ${newConfig.project_id}
    🌍 리전: ${newConfig.region || '(미설정)'}
    👤 계정: ${newConfig.account || '(미설정)'}${sqlInfo}
    
    > ⚠️ .gitignore에 .hi-gcloud.json 추가를 권장합니다.`,
        }],
      };
    }
  • TypeScript interface for the GcpSetupArgs used by the gcpSetup handler.
    interface GcpSetupArgs {
      action?: 'status' | 'create' | 'update';
      project_path?: string;
      project_id?: string;
      region?: string;
      account?: string;
      cloud_sql?: CloudSqlInstance[];
    }
  • src/gcp/setup.ts:6-44 (registration)
    Tool definition/schema for 'gcp_setup' - includes name, description, annotations, and inputSchema with action/project_path/project_id/region/account properties.
    export const gcpSetupDefinition = {
      name: 'gcp_setup',
      description: '설정|초기화|프로필|setup|init|configure - 프로젝트별 GCP 설정 파일(.hi-gcloud.json)을 생성합니다. project_path에 현재 작업 폴더 경로를 지정하세요.',
      annotations: {
        title: 'GCP 프로젝트 설정',
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false,
      },
      inputSchema: {
        type: 'object' as const,
        properties: {
          action: {
            type: 'string',
            enum: ['status', 'create', 'update'],
            description: '수행할 작업. status: 현재 설정 확인, create: 설정 생성, update: 설정 업데이트',
            default: 'status',
          },
          project_path: {
            type: 'string',
            description: '프로젝트 경로 (현재 작업 폴더 경로를 지정하세요)',
          },
          project_id: {
            type: 'string',
            description: 'GCP 프로젝트 ID',
          },
          region: {
            type: 'string',
            description: '기본 리전 (예: asia-northeast3)',
          },
          account: {
            type: 'string',
            description: '계정 이메일',
          },
        },
        required: [],
      },
    };
  • src/index.ts:77-89 (registration)
    Registration of gcpSetupDefinition in the tools array sent to the MCP server.
    const tools = [
      gcpSetupDefinition,
      gcpLogsReadDefinition,
      gcpRunStatusDefinition,
      gcpRunLogsDefinition,
      gcpSqlQueryDefinition,
      gcpSqlProxyDefinition,
      gcpStorageListDefinition,
      gcpSecretListDefinition,
      gcpAuthStatusDefinition,
      gcpServicesListDefinition,
      gcpBillingInfoDefinition,
    ];
  • src/index.ts:212-214 (registration)
    Routing of gcp_setup tool call in the CallToolRequestSchema handler to the gcpSetup function.
    switch (name) {
      case 'gcp_setup':
        return await gcpSetup(args as any) as CallToolResult;
Behavior3/5

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

Annotations already mark idempotent and non-destructive. Description adds file name (.hi-gcloud.json) but does not elaborate on side effects or permissions. No contradiction with annotations.

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

Conciseness4/5

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

Single sentence plus a hint. The leading keyword list (설정|초기화|...) is slightly redundant but overall efficient.

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?

Adequate for a simple config tool. Lacks details on error scenarios, return values, or prerequisites (e.g., authenticated gcloud). No output schema, so return format is unclear.

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

Parameters4/5

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

Schema covers all 5 parameters with descriptions. Description adds contextual hint that project_path should be current working folder, which is helpful beyond schema defaults.

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

Purpose5/5

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

Description clearly states it creates project-specific GCP configuration file (.hi-gcloud.json). Keywords like setup/init/configure distinguish it from sibling tools that handle auth, billing, logs, etc.

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?

No explicit guidance on when to use this tool versus alternatives (e.g., gcp_auth_status for auth, gcp_services_list for services). Simply instructs to set project_path to current folder.

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/su-record/hi-gcloud'

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