Skip to content

Commit 86ce175

Browse files
docs: generate hierarchical per-module API reference pages
The API docs previously consisted of a single page (`docs/api.md`) containing only `::: mcp`, which rendered just the top-level `mcp/__init__.py` exports. Most of the public API surface (`MCPServer`, `Context`, `Settings`, `Tool`, `Resource`, `Prompt`, etc.) was missing because those classes live in subpackages not re-exported at the top level. This replaces the single-page approach with auto-generated per-module pages using the standard mkdocstrings recipe: - `mkdocs-gen-files` runs `scripts/gen_ref_pages.py` at build time to create a virtual `.md` stub for every module under `src/mcp/` - `mkdocs-literate-nav` reads the generated `api/SUMMARY.md` to build a hierarchical sidebar navigation tree - Material theme's `navigation.indexes` handles section index pages (the `mkdocs-section-index` plugin is not needed and conflicts with it) Also updates `mkdocstrings` `paths` from `[src/mcp]` to `[src]` so that fully-qualified module identifiers like `mcp.server.mcpserver.server` resolve correctly.
1 parent c032854 commit 86ce175

File tree

7 files changed

+74
-7
lines changed

7 files changed

+74
-7
lines changed

docs/api.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ npx -y @modelcontextprotocol/inspector
6464

6565
## API Reference
6666

67-
Full API documentation is available in the [API Reference](api.md).
67+
Full API documentation is available in the [API Reference](api/mcp/index.md).

docs/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,6 @@ The lowlevel `Server` also now exposes a `session_manager` property to access th
828828

829829
If you encounter issues during migration:
830830

831-
1. Check the [API Reference](api.md) for updated method signatures
831+
1. Check the [API Reference](api/mcp/index.md) for updated method signatures
832832
2. Review the [examples](https://github.com/modelcontextprotocol/python-sdk/tree/main/examples) for updated usage patterns
833833
3. Open an issue on [GitHub](https://github.com/modelcontextprotocol/python-sdk/issues) if you find a bug or need further assistance

mkdocs.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ nav:
2525
- Introduction: experimental/tasks.md
2626
- Server Implementation: experimental/tasks-server.md
2727
- Client Usage: experimental/tasks-client.md
28-
- API Reference: api.md
28+
- API Reference: api/
2929

3030
theme:
3131
name: "material"
@@ -114,19 +114,22 @@ plugins:
114114
- search
115115
- social
116116
- glightbox
117+
- gen-files:
118+
scripts:
119+
- scripts/gen_ref_pages.py
120+
- literate-nav:
121+
nav_file: SUMMARY.md
117122
- mkdocstrings:
118123
handlers:
119124
python:
120-
paths: [src/mcp]
125+
paths: [src]
121126
options:
122127
relative_crossrefs: true
123128
members_order: source
124129
separate_signature: true
125130
show_signature_annotations: true
126131
signature_crossrefs: true
127132
group_by_category: false
128-
# 3 because docs are in pages with an H2 just above them
129-
heading_level: 3
130133
inventories:
131134
- url: https://docs.python.org/3/objects.inv
132135
- url: https://docs.pydantic.dev/latest/objects.inv

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ dev = [
7474
]
7575
docs = [
7676
"mkdocs>=1.6.1",
77+
"mkdocs-gen-files>=0.5.0",
7778
"mkdocs-glightbox>=0.4.0",
79+
"mkdocs-literate-nav>=0.6.1",
7880
"mkdocs-material>=9.5.45",
7981
"mkdocstrings-python>=2.0.1",
8082
]

scripts/gen_ref_pages.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Generate the code reference pages and navigation."""
2+
3+
from pathlib import Path
4+
5+
import mkdocs_gen_files
6+
7+
nav = mkdocs_gen_files.Nav()
8+
9+
root = Path(__file__).parent.parent
10+
src = root / "src"
11+
12+
for path in sorted(src.rglob("*.py")):
13+
module_path = path.relative_to(src).with_suffix("")
14+
doc_path = path.relative_to(src).with_suffix(".md")
15+
full_doc_path = Path("api", doc_path)
16+
17+
parts = tuple(module_path.parts)
18+
19+
if parts[-1] == "__init__":
20+
parts = parts[:-1]
21+
doc_path = doc_path.with_name("index.md")
22+
full_doc_path = full_doc_path.with_name("index.md")
23+
elif parts[-1].startswith("_"):
24+
continue
25+
26+
nav[parts] = doc_path.as_posix()
27+
28+
with mkdocs_gen_files.open(full_doc_path, "w") as fd:
29+
ident = ".".join(parts)
30+
fd.write(f"::: {ident}")
31+
32+
mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root))
33+
34+
with mkdocs_gen_files.open("api/SUMMARY.md", "w") as nav_file:
35+
nav_file.writelines(nav.build_literate_nav())

uv.lock

Lines changed: 28 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)