Update Spec Types #159
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Spec Types | |
| on: | |
| schedule: | |
| # Run nightly at 4 AM UTC | |
| - cron: '0 4 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-spec-types: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0 | |
| id: pnpm-install | |
| with: | |
| run_install: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: pnpm | |
| cache-dependency-path: pnpm-lock.yaml | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Fetch latest spec types | |
| run: pnpm run fetch:spec-types | |
| - name: Check for changes | |
| id: check_changes | |
| run: | | |
| if git diff --quiet packages/core/src/types/spec.types.ts; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| LATEST_SHA=$(grep "Last updated from commit:" packages/core/src/types/spec.types.ts | cut -d: -f2 | tr -d ' ') | |
| echo "sha=$LATEST_SHA" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create Pull Request | |
| if: steps.check_changes.outputs.has_changes == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| # Skip lefthook pre-push (typecheck/lint/build); spec drift that breaks | |
| # typecheck should still open a PR so it can be fixed there. | |
| LEFTHOOK: 0 | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout -B update-spec-types | |
| git add packages/core/src/types/spec.types.ts | |
| git commit -m "chore: update spec.types.ts from upstream" | |
| git push -f --no-verify origin update-spec-types | |
| # Create PR if it doesn't exist, or update if it does | |
| PR_BODY="This PR updates \`packages/core/src/types/spec.types.ts\` from the Model Context Protocol specification. | |
| Source file: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/${{ steps.check_changes.outputs.sha }}/schema/draft/schema.ts | |
| This is an automated update triggered by the nightly cron job." | |
| # `gh pr view <branch>` matches closed PRs too, so check for an *open* PR explicitly. | |
| EXISTING_PR=$(gh pr list --head update-spec-types --state open --json number --jq '.[0].number // empty') | |
| if [ -n "$EXISTING_PR" ]; then | |
| echo "PR #$EXISTING_PR already exists, updating description..." | |
| gh pr edit "$EXISTING_PR" --body "$PR_BODY" | |
| else | |
| gh pr create \ | |
| --title "chore: update spec.types.ts from upstream" \ | |
| --body "$PR_BODY" \ | |
| --base main \ | |
| --head update-spec-types | |
| fi |