Skip to content

Commit a79839c

Browse files
Add API documentation with GitHub Pages deployment
This adds automated generation and deployment of versioned API documentation using TypeDoc and GitHub Pages. Documentation will be generated and published when a new release is created. Changes ------- 1. **Documentation generation script** (see `scripts/generate-gh-pages.sh`) Generates TypeDoc documentation for a specific version tag and commits it to the gh-pages branch. The script uses git worktrees to isolate the documentation generation process from the main workspace. Documentation for each release is stored in a versioned directory (e.g., `v1.2.3/`) on the gh-pages branch. The script: - Creates the gh-pages branch as an orphan branch if it doesn't exist - Parses semantic versions from tag names, ignoring arbitrary prefixes (e.g., tags `1.2.3`, `v1.2.3`, and `release-1.2.3` all create `v1.2.3/`) - Preserves all existing version directories when generating new documentation - Determines the latest version using semantic version sorting - Copies static Jekyll template files from the `docs/` directory to the gh-pages root (for the latest version only) - Generates `_data/versions.yml` with a list of all versions for Jekyll templates to consume 2. **Jekyll template files** (see `docs/` directory) - `_config.yml` - Jekyll configuration (can set title and theme here) - `index.md` - Landing page template that links to all versions based on generated `_data/versions.yml` - `latest/index.html` - Redirect page template that redirects to the latest version based on generated `_data/versions.yml` 3. **GitHub Actions workflow** (see `.github/workflows/main.yml`) Added a `publish-gh-pages` job that runs after the `publish` job on release events. This ensures documentation is generated and published only after the npm package is successfully published. The job invokes the generation script with the release tag name and pushes the updated gh-pages branch. 4. **CI validation** (see `package.json`) Updated the `check` script to include TypeDoc validation with `--emit none`. This ensures TypeDoc can successfully parse the codebase (without generating output), catching documentation issues early in CI. 5. **Documentation link** (see `README.md`) Added a link to the published API documentation in the Documentation section of the README. TypeDoc Configuration --------------------- TypeDoc is configured via `typedoc.json`: - Uses the `src` directory as the entry point with the `expand` strategy - Uses `tsconfig.prod.json` which excludes test files Documentation URL ----------------- Published documentation will be available at: https://modelcontextprotocol.github.io/typescript-sdk/ Individual versions will be accessible at: - https://modelcontextprotocol.github.io/typescript-sdk/v1.2.3/ - https://modelcontextprotocol.github.io/typescript-sdk/latest/ Co-Authored-By: Claude <[email protected]>
1 parent 5bcf53f commit a79839c

File tree

10 files changed

+429
-1
lines changed

10 files changed

+429
-1
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,35 @@ jobs:
6666
- run: npm publish --provenance --access public
6767
env:
6868
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
69+
70+
publish-gh-pages:
71+
runs-on: ubuntu-latest
72+
if: github.event_name == 'release'
73+
needs: [publish]
74+
75+
permissions:
76+
contents: write
77+
78+
steps:
79+
- uses: actions/checkout@v4
80+
with:
81+
fetch-depth: 0 # Fetch all history for all branches
82+
83+
- uses: actions/setup-node@v4
84+
with:
85+
node-version: 24
86+
cache: npm
87+
88+
- name: Install dependencies
89+
run: npm ci
90+
91+
- name: Configure Git
92+
run: |
93+
git config --global user.name "github-actions[bot]"
94+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
95+
96+
- name: Generate documentation
97+
run: ./scripts/generate-gh-pages.sh ${{ github.ref_name }}
98+
99+
- name: Push to gh-pages
100+
run: git push origin gh-pages

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ pnpm-lock.yaml
1111

1212
# Ignore generated files
1313
src/spec.types.ts
14+
15+
# Jekyll/Liquid template files with special formatting requirements
16+
docs/index.md

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ app.listen(3000);
14981498

14991499
## Documentation
15001500

1501+
- [SDK API documentation](https://modelcontextprotocol.github.io/typescript-sdk/)
15011502
- [Model Context Protocol documentation](https://modelcontextprotocol.io)
15021503
- [MCP Specification](https://spec.modelcontextprotocol.io)
15031504
- [Example Servers](https://github.com/modelcontextprotocol/servers)

docs/_config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
title: '@modelcontextprotocol/sdk'
2+
3+
# Include generated files and directories which may start with underscores
4+
include:
5+
- '_*'

docs/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
# Empty Jekyll front matter to enable Liquid templating (see {{ ... }} below)
3+
---
4+
5+
{% for version in site.data.versions %}
6+
- [v{{ version }}](v{{ version }}/)
7+
{% endfor %}

docs/latest/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
# Empty Jekyll front matter to enable Liquid templating (see {{ ... }} below)
3+
---
4+
5+
<!doctype html>
6+
<html>
7+
<head>
8+
<meta charset="utf-8" />
9+
<title>Redirecting to latest documentation...</title>
10+
<meta http-equiv="refresh" content="0; url=../v{{ site.data.versions[0] }}/" />
11+
<link rel="canonical" href="../v{{ site.data.versions[0] }}/" />
12+
</head>
13+
<body>
14+
<p>Redirecting to <a href="../v{{ site.data.versions[0] }}/">latest documentation</a>...</p>
15+
<script>
16+
window.location.href = '../v{{ site.data.versions[0] }}/';
17+
</script>
18+
</body>
19+
</html>

package-lock.json

Lines changed: 216 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)