gcp_auth_status
Verify your GCP authentication status and view active account details. Optionally list all authenticated accounts in text or JSON format.
Instructions
인증 상태|로그인 확인|계정 정보|auth status|whoami - GCP 인증 상태와 계정 정보를 확인합니다
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| show_all_accounts | No | 모든 인증된 계정 표시 (기본: false) | |
| format | No | 출력 형식 (기본: text) | text |
Implementation Reference
- src/gcp/auth.ts:38-131 (handler)The main handler function that checks GCP auth status. Calls checkGcloudAuth() to verify authentication, then fetches config and optionally all accounts. Returns formatted output in text or JSON format with details about active account, project, region, zone.
export async function gcpAuthStatus(args: GcpAuthStatusArgs) { try { const authStatus = await checkGcloudAuth(); if (!authStatus.authenticated) { return { content: [ { type: 'text', text: formatError(authStatus.error), }, ], isError: true, }; } // Get additional configuration const configResult = await executeGcloud('config list --format=json', 10000); let config: any = {}; try { config = JSON.parse(configResult.stdout || '{}'); } catch { config = {}; } // Get all accounts if requested let allAccounts: string[] = []; if (args.show_all_accounts) { try { const accountsResult = await executeGcloud('auth list --format="value(account)"', 10000); allAccounts = accountsResult.stdout.trim().split('\n').filter(Boolean); } catch { // Ignore errors } } const result = { authenticated: true, activeAccount: authStatus.account, project: authStatus.project, region: config.compute?.region || 'not set', zone: config.compute?.zone || 'not set', allAccounts: args.show_all_accounts ? allAccounts : undefined, }; if (args.format === 'json') { return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } const lines = [ '🔑 GCP 인증 상태', '', `✅ 인증됨`, `👤 계정: ${result.activeAccount}`, `📁 프로젝트: ${result.project || '(설정 안됨)'}`, `🌍 리전: ${result.region}`, `📍 존: ${result.zone}`, ]; if (args.show_all_accounts && allAccounts.length > 1) { lines.push('', '📋 모든 인증된 계정:'); allAccounts.forEach((account) => { const isActive = account === result.activeAccount; lines.push(` ${isActive ? '→' : ' '} ${account}${isActive ? ' (활성)' : ''}`); }); } return { content: [ { type: 'text', text: lines.join('\n'), }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: formatError(error), }, ], isError: true, }; } } - src/gcp/auth.ts:4-31 (schema)The tool definition/input schema for 'gcp_auth_status'. Includes name, description, annotations (readOnly, idempotent), and inputSchema with optional 'show_all_accounts' (boolean) and 'format' (text/json) parameters.
export const gcpAuthStatusDefinition = { name: 'gcp_auth_status', description: '인증 상태|로그인 확인|계정 정보|auth status|whoami - GCP 인증 상태와 계정 정보를 확인합니다', annotations: { title: 'GCP 인증 상태 확인', readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, inputSchema: { type: 'object' as const, properties: { show_all_accounts: { type: 'boolean', description: '모든 인증된 계정 표시 (기본: false)', default: false, }, format: { type: 'string', enum: ['text', 'json'], description: '출력 형식 (기본: text)', default: 'text', }, }, required: [], }, }; - src/gcp/auth.ts:33-36 (schema)TypeScript interface GcpAuthStatusArgs defining the shape of input arguments (show_all_accounts?: boolean, format?: 'text' | 'json').
interface GcpAuthStatusArgs { show_all_accounts?: boolean; format?: 'text' | 'json'; } - src/index.ts:86-89 (registration)Registration of gcpAuthStatusDefinition in the tools array (line 86) and import from './gcp/auth.js' (line 25). Also the switch-case handler at lines 227-228 dispatches calls to gcp_auth_status.
gcpAuthStatusDefinition, gcpServicesListDefinition, gcpBillingInfoDefinition, ]; - src/utils/exec.ts:123-168 (helper)Helper function checkGcloudAuth() that checks if gcloud is installed and authenticated. Runs 'gcloud auth list' to get active account and 'gcloud config get-value project' to get the current project.
export async function checkGcloudAuth(): Promise<{ authenticated: boolean; project?: string; account?: string; error?: GcloudError }> { const gcloudPath = await findGcloudPath(); if (!gcloudPath) { return { authenticated: false, error: { type: 'NOT_INSTALLED', message: 'gcloud CLI가 설치되지 않았습니다.', suggestion: 'https://cloud.google.com/sdk/docs/install 에서 Google Cloud SDK를 설치해주세요.', }, }; } try { // Check authentication status const authResult = await execAsync(`${gcloudPath} auth list --format="value(account)" --filter="status:ACTIVE"`, { timeout: 10000 }); const account = authResult.stdout.trim(); if (!account) { return { authenticated: false, error: { type: 'NOT_AUTHENTICATED', message: 'GCP 인증이 필요합니다.', suggestion: '`gcloud auth login` 명령어를 실행해주세요.', }, }; } // Get current project const projectResult = await execAsync(`${gcloudPath} config get-value project`, { timeout: 5000 }); const project = projectResult.stdout.trim(); return { authenticated: true, account, project: project || undefined, }; } catch (error: any) { return { authenticated: false, error: parseGcloudError(error.message || ''), }; } }