Skip to main content
Glama

gcp_sql_query

Read-onlyIdempotent

Run read-only SELECT queries on Cloud SQL databases to retrieve data from specified GCP instances.

Instructions

Cloud SQL 쿼리|DB 조회|sql query - Cloud SQL에서 읽기 전용 쿼리를 실행합니다

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instanceYesCloud SQL 인스턴스 이름
databaseYes데이터베이스 이름
queryYesSELECT 쿼리 (읽기 전용만 허용)
project_idNoGCP 프로젝트 ID (기본: 현재 설정된 프로젝트)
formatNo출력 형식 (기본: text)text

Implementation Reference

  • Schema definition for the gcp_sql_query tool. Defines tool name, description, annotations (readOnlyHint, etc.), and input schema with required fields: instance, database, query, and optional: project_id, format.
    export const gcpSqlQueryDefinition = {
      name: 'gcp_sql_query',
      description: 'Cloud SQL 쿼리|DB 조회|sql query - Cloud SQL에서 읽기 전용 쿼리를 실행합니다',
      annotations: {
        title: 'Cloud SQL 쿼리 실행',
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: true,
      },
      inputSchema: {
        type: 'object' as const,
        properties: {
          instance: {
            type: 'string',
            description: 'Cloud SQL 인스턴스 이름',
          },
          database: {
            type: 'string',
            description: '데이터베이스 이름',
          },
          query: {
            type: 'string',
            description: 'SELECT 쿼리 (읽기 전용만 허용)',
          },
          project_id: {
            type: 'string',
            description: 'GCP 프로젝트 ID (기본: 현재 설정된 프로젝트)',
          },
          format: {
            type: 'string',
            enum: ['text', 'json'],
            description: '출력 형식 (기본: text)',
            default: 'text',
          },
        },
        required: ['instance', 'database', 'query'],
      },
    };
  • TypeScript interface for the gcp_sql_query arguments, matching the inputSchema definition.
    interface GcpSqlQueryArgs {
      instance: string;
      database: string;
      query: string;
      project_id?: string;
      format?: 'text' | 'json';
    }
  • Handler function that executes the gcp_sql_query tool logic. Resolves project ID, enforces read-only SELECT-only queries with safety checks (dangerous keywords, auto-appends LIMIT 100), constructs a gcloud sql connect command, but currently returns a warning stub indicating Cloud SQL direct connection is not fully implemented.
    export async function gcpSqlQuery(args: GcpSqlQueryArgs) {
      try {
        const projectId = await getProjectId(args.project_id);
    
        // Security check: only allow SELECT queries
        const normalizedQuery = args.query.trim().toLowerCase();
        if (!normalizedQuery.startsWith('select')) {
          return {
            content: [
              {
                type: 'text',
                text: '❌ 보안 제한: SELECT 쿼리만 허용됩니다.\n\nINSERT, UPDATE, DELETE, DROP 등의 쿼리는 실행할 수 없습니다.',
              },
            ],
            isError: true,
          };
        }
    
        // Check for dangerous keywords
        const dangerousKeywords = ['insert', 'update', 'delete', 'drop', 'truncate', 'alter', 'create', 'grant', 'revoke'];
        for (const keyword of dangerousKeywords) {
          if (normalizedQuery.includes(keyword)) {
            return {
              content: [
                {
                  type: 'text',
                  text: `❌ 보안 제한: "${keyword.toUpperCase()}" 키워드가 포함된 쿼리는 실행할 수 없습니다.`,
                },
              ],
              isError: true,
            };
          }
        }
    
        // Add LIMIT if not present (safety measure)
        let safeQuery = args.query.trim();
        if (!normalizedQuery.includes('limit')) {
          safeQuery += ' LIMIT 100';
        }
    
        // Note: Cloud SQL direct query requires Cloud SQL Proxy or gcloud sql connect
        // This implementation uses gcloud sql connect with --quiet flag
        // For production, consider using Cloud SQL Admin API
    
        const command = `sql connect ${args.instance} --database=${args.database} --project=${projectId} --quiet <<< "${safeQuery.replace(/"/g, '\\"')}"`;
    
        // This is a simplified implementation
        // Real implementation would need proper SQL connection handling
        return {
          content: [
            {
              type: 'text',
              text: `⚠️ Cloud SQL 직접 연결 기능\n\n현재 구현에서는 Cloud SQL Proxy 또는 직접 연결이 필요합니다.\n\n실행하려던 쿼리:\n${safeQuery}\n\n대안:\n1. Cloud SQL Studio 사용 (GCP Console)\n2. Cloud SQL Proxy 설정 후 로컬에서 연결\n3. gcloud sql connect ${args.instance} --database=${args.database} 명령어 직접 실행`,
            },
          ],
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: formatError(error),
            },
          ],
          isError: true,
        };
      }
    }
  • src/index.ts:22-22 (registration)
    Import of the gcp_sql_query definition and handler into the main server file.
    import { gcpSqlQueryDefinition, gcpSqlQuery } from './gcp/sql.js';
  • src/index.ts:82-82 (registration)
    Registration of gcp_sql_query in the tools array, making it available via ListToolsRequestSchema.
    gcpSqlQueryDefinition,
  • src/index.ts:221-222 (registration)
    Handler dispatch in CallToolRequestSchema switch-case, routing the 'gcp_sql_query' tool name to the gcpSqlQuery function.
    case 'gcp_sql_query':
      return await gcpSqlQuery(args as any) as CallToolResult;
Behavior3/5

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

Annotations already provide readOnlyHint, destructiveHint, and idempotentHint. The description reinforces that queries are read-only but does not add additional behavioral context beyond the annotations. No contradictions.

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?

The description is a single sentence with pipe-separated keywords, which is concise but somewhat messy. It front-loads the purpose effectively, though a more structured format could be clearer.

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?

The description does not detail return values or error behavior, but the format parameter implies output options. Given high schema coverage and annotations, it is adequate but not fully complete for a query tool.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters well. The description adds no extra meaning to the parameters beyond what is in the schema.

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?

The description clearly states the tool executes read-only SQL queries on Cloud SQL, using both Korean and English terms. It differentiates from sibling tools like gcp_logs_read or gcp_storage_list by specifying 'Cloud SQL' and '쿼리' (query).

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

Usage Guidelines4/5

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

The description indicates read-only queries, and the parameter 'query' specifies only SELECT queries are allowed. Context for when to use this vs. other tools is implied but not explicitly stated, e.g., for database querying rather than log reading or storage listing.

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