# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

sources:
  mysql-source:
    kind: mysql
    host: ${MYSQL_HOST:localhost}
    port: ${MYSQL_PORT:3306}
    database: ${MYSQL_DATABASE}
    user: ${MYSQL_USER}
    password: ${MYSQL_PASSWORD}
    # Optional: supply additional DSN parameters (e.g. TLS, charset) via env var.
    # Provide a YAML-encoded map in MYSQL_QUERY_PARAMS, for example:
    #   export MYSQL_QUERY_PARAMS="{tls: preferred, charset: utf8mb4}"
    # When the variable is empty/undefined, queryParams will be treated as nil.
    queryParams: ${MYSQL_QUERY_PARAMS:}
    queryTimeout: 30s # Optional
tools:
  execute_sql:
    kind: mysql-execute-sql
    source: mysql-source
    description: Use this tool to execute SQL.
  list_active_queries:
    kind: mysql-list-active-queries
    source: mysql-source
    description: Lists top N (default 10) ongoing queries from processlist and innodb_trx, ordered by execution time in descending order. Returns detailed information of those queries in json format, including process id, query, transaction duration, transaction wait duration, process time, transaction state, process state, username with host, transaction rows locked, transaction rows modified, and db schema.
  get_query_plan:
    kind: mysql-get-query-plan
    source: mysql-source
    description: "Provide information about how MySQL executes a SQL statement. Common use cases include: 1) analyze query plan to improve its performance, and 2) determine effectiveness of existing indexes and evalueate new ones."
  list_tables:
    kind: mysql-list-tables
    source: mysql-source
    description: "Lists detailed schema information (object type, columns, constraints, indexes, triggers, comment) as JSON for user-created tables (ordinary or partitioned). Filters by a comma-separated list of names. If names are omitted, lists all tables in user schemas."
  list_tables_missing_unique_indexes:
    kind: mysql-list-tables-missing-unique-indexes
    source: mysql-source
    description: "Find tables that do not have primary or unique key constraint. A primary key or unique key is the only mechanism that guaranttes a row is unique. Without them, the database-level protection against data integrity issues will be missing."
  list_table_fragmentation:
    kind: mysql-list-table-fragmentation
    source: mysql-source
    description: List table fragmentation in MySQL, by calculating the size of the data and index files and free space allocated to each table. The query calculates fragmentation percentage which represents the proportion of free space relative to the total data and index size. Storage can be reclaimed for tables with high fragmentation using OPTIMIZE TABLE.

toolsets:
  mysql_database_tools:
    - execute_sql
    - list_tables
    - get_query_plan
    - list_active_queries
    - list_tables_missing_unique_indexes
    - list_table_fragmentation
