Skip to content

Commit 5023e06

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 `docs/_data/versions.yml` with a list of all versions for Jekyll templates to consume 2. **Jekyll template files** (see `docs/` directory) - `docs/_config.yml` - Jekyll configuration - `docs/index.md` - Landing page template that links to all versions based on generated `docs/_data/versions.yml` - `docs/latest/index.html` - Redirect page template that redirects to the latest version based on generated `docs/_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 ----------------- Custom documentation will be available at: https://modelcontextprotocol.github.io/typescript-sdk/ Versioned API documentation will be available at: - https://modelcontextprotocol.github.io/typescript-sdk/latest/ (latest version) - https://modelcontextprotocol.github.io/typescript-sdk/v1.2.3/ (specific versions) Co-Authored-By: Claude <[email protected]>
1 parent 41c6b35 commit 5023e06

File tree

10 files changed

+436
-1
lines changed

10 files changed

+436
-1
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,35 @@ jobs:
7676
- run: npm publish --provenance --access public ${{ steps.npm-tag.outputs.tag }}
7777
env:
7878
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
79+
80+
publish-gh-pages:
81+
runs-on: ubuntu-latest
82+
if: github.event_name == 'release'
83+
needs: [publish]
84+
85+
permissions:
86+
contents: write
87+
88+
steps:
89+
- uses: actions/checkout@v4
90+
with:
91+
fetch-depth: 0 # Fetch all history for all branches
92+
93+
- uses: actions/setup-node@v4
94+
with:
95+
node-version: 24
96+
cache: npm
97+
98+
- name: Install dependencies
99+
run: npm ci
100+
101+
- name: Configure Git
102+
run: |
103+
git config --global user.name "github-actions[bot]"
104+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
105+
106+
- name: Generate documentation
107+
run: ./scripts/generate-gh-pages.sh ${{ github.ref_name }}
108+
109+
- name: Push to gh-pages
110+
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
@@ -1579,6 +1579,7 @@ app.listen(3000);
15791579

15801580
## Documentation
15811581

1582+
- [SDK API documentation](https://modelcontextprotocol.github.io/typescript-sdk/)
15821583
- [Model Context Protocol documentation](https://modelcontextprotocol.io)
15831584
- [MCP Specification](https://spec.modelcontextprotocol.io)
15841585
- [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>

0 commit comments

Comments
 (0)