From 76e7a7e343ff52ce7960225561138c76750fd906 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Tue, 23 Jun 2026 21:55:36 +0530 Subject: [PATCH 1/2] ci: auto-generate skills on toolbox version updates --- .github/scripts/generate_skills.sh | 103 ++++++++++++++++++++++++++ .github/workflows/skills-generate.yml | 57 ++++++++++++++ 2 files changed, 160 insertions(+) create mode 100755 .github/scripts/generate_skills.sh create mode 100644 .github/workflows/skills-generate.yml diff --git a/.github/scripts/generate_skills.sh b/.github/scripts/generate_skills.sh new file mode 100755 index 0000000..2eaa51d --- /dev/null +++ b/.github/scripts/generate_skills.sh @@ -0,0 +1,103 @@ +#!/bin/bash +set -e + +# Ensure VERSION is passed from the environment +if [ -z "$VERSION" ]; then + echo "Error: VERSION environment variable is not set." + exit 1 +fi + +# SKILL CONFIGURATION +# Format: "toolset" "description" +# The skill name is automatically generated as "spanner-" +SKILLS=( + "data" + "Use these skills when you need to explore the database structure, discover schema objects like tables and graphs, and execute custom SQL queries to interact with your data." +) + +echo "VALIDATING TOOLSETS BEFORE GENERATION" + +# Dynamically build the SUPPORTED_TOOLSETS array from the SKILLS array. +# We use 'set --' to process the array in chunks without index arithmetic. +SUPPORTED_TOOLSETS=() +set -- "${SKILLS[@]}" +while [ $# -gt 0 ]; do + SUPPORTED_TOOLSETS+=("$1") + shift 2 +done + +echo "Currently Supported Toolsets: ${SUPPORTED_TOOLSETS[*]}" + +# Fetch the upstream source of truth YAML for this specific version +RAW_URL="https://raw.githubusercontent.com/googleapis/mcp-toolbox/v${VERSION}/internal/prebuiltconfigs/tools/spanner.yaml" +echo "Fetching upstream config from: $RAW_URL" +UPSTREAM_YAML=$(curl -sL --fail "$RAW_URL" || { echo "Error: Could not fetch upstream YAML for v$VERSION"; exit 1; }) + +# Extract the list of toolsets. Each toolset is its own YAML document: +# kind: toolset +# name: +UPSTREAM_TOOLSETS=$(echo "$UPSTREAM_YAML" | awk '$1=="kind:" && $2=="toolset"{f=1; next} f && $1=="name:"{print $2; f=0}') + +# Compare upstream toolsets against our supported list +MISSING_TOOLSETS=false + +for upstream_tool in $UPSTREAM_TOOLSETS; do + if [ -z "$upstream_tool" ] || [ "$upstream_tool" == "-" ]; then continue; fi + + if [[ ! " ${SUPPORTED_TOOLSETS[*]} " =~ " ${upstream_tool} " ]]; then + echo "ERROR: Upstream configuration contains a new toolset: '$upstream_tool'" + MISSING_TOOLSETS=true + fi +done + +if [ "$MISSING_TOOLSETS" = true ]; then + echo "PIPELINE FAILED: Missing Toolset Generators" + echo "The source of truth file has toolsets that your script does not support." + echo "Please update the SKILLS array in generate_skills.sh to include generators" + echo "for the missing toolsets above, then commit your changes to unblock this PR." + exit 1 +fi + +echo "Validation passed. All upstream toolsets are supported." + +echo "BEGINNING SKILL GENERATION" + +LICENSE_HEADER="// Copyright 2026 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." + +ADDITIONAL_NOTES="Note: The scripts automatically load the environment variables from various .env files. Do not ask the user to set vars unless skill executions fails due to env var absence." + +# Base Command Function +generate_skill() { + local TOOLSET="$1" + local SKILL_DESC="$2" + local SKILL_NAME="spanner-$TOOLSET" + + echo "Generating skill: $SKILL_NAME..." + + npx "@toolbox-sdk/server@${VERSION}" --prebuilt spanner skills-generate \ + --name "$SKILL_NAME" \ + --description "$SKILL_DESC" \ + --toolset="$TOOLSET" \ + --license-header "$LICENSE_HEADER" \ + --additional-notes="$ADDITIONAL_NOTES" +} + +set -- "${SKILLS[@]}" +while [ $# -gt 0 ]; do + generate_skill "$1" "$2" + shift 2 +done + +echo "All skills generated successfully!" diff --git a/.github/workflows/skills-generate.yml b/.github/workflows/skills-generate.yml new file mode 100644 index 0000000..e31c015 --- /dev/null +++ b/.github/workflows/skills-generate.yml @@ -0,0 +1,57 @@ +# Copyright 2026 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. + +name: Generate Skills + +on: + pull_request: + paths: + - "toolbox_version.txt" + +jobs: + generate-skills: + # Only run for same-repo PRs (e.g. renovate's toolbox bump), where the + # built-in GITHUB_TOKEN can push back to the PR branch. + if: github.event.pull_request.head.repo.full_name == github.repository + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Check out PR branch + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + ref: ${{ github.head_ref }} + + - name: Generate skills + run: | + VERSION="$(tr -d '\n' < toolbox_version.txt)" + echo "Detected toolbox version: $VERSION" + export VERSION + chmod +x ./.github/scripts/generate_skills.sh + ./.github/scripts/generate_skills.sh + + - name: Commit and push regenerated skills + run: | + if [ -z "$(git status --porcelain)" ]; then + echo "No skill changes generated. Nothing to commit." + exit 0 + fi + + echo "Changes detected. Committing regenerated skills..." + git config user.name "release-please[bot]" + git config user.email "55107282+release-please[bot]@users.noreply.github.com" + + git add . + git commit -m "chore: auto-generate skills for toolbox v$(tr -d '\n' < toolbox_version.txt)" + git push From 7532ad5bd3a2b7fe03ae287c57b1303687a94a25 Mon Sep 17 00:00:00 2001 From: Twisha Bansal Date: Tue, 23 Jun 2026 21:59:14 +0530 Subject: [PATCH 2/2] ci: add data_with_discovery toolset to skill generation --- .github/scripts/generate_skills.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/scripts/generate_skills.sh b/.github/scripts/generate_skills.sh index 2eaa51d..1418a22 100755 --- a/.github/scripts/generate_skills.sh +++ b/.github/scripts/generate_skills.sh @@ -13,6 +13,9 @@ fi SKILLS=( "data" "Use these skills when you need to explore the database structure, discover schema objects like tables and graphs, and execute custom SQL queries to interact with your data." + + "data_with_discovery" + "Use these skills when you need to explore the database structure, discover schema objects like tables and graphs, execute custom SQL queries, and search the data catalog to find relevant instances, databases, tables, or views." ) echo "VALIDATING TOOLSETS BEFORE GENERATION"