Skip to content

Commit 86c012c

Browse files
committed
Flag removed modules, update dependency files, add a batch-test harness
Three additions to mcp-codemod, closing the gaps a comparison with the TypeScript codemod surfaced: Imports of module namespaces v2 deleted outright (the experimental tasks namespaces, the WebSocket transports, `mcp.shared.progress`) are now marked with replacement guidance. A new ratchet test freezes the 107 public modules v1 shipped and asserts every one imports on v2, is renamed, or is in the removed table, so the whole v1 module namespace is provably accounted for. The codemod now also updates the `mcp` requirement in `pyproject.toml` (PEP 621 tables and dependency groups) and `requirements*.txt` to `>=2,<3` -- only where the current constraint cannot accept any v2 release, and only the version specifier: name, extras, environment marker, and spacing keep the user's spelling. Poetry tables and the removed `ws` extra are marked instead of guessed at, under the same `# mcp-codemod:` contract as source markers. `scripts/codemod-batch-test/` runs the codemod against pinned real repositories and audits the marker contract end to end: it type-checks the pristine clone against the latest v1 and the migrated copy against this workspace's v2 with identical pyright settings, then requires every error that exists only on the migrated side to sit next to a marker. Across the four repos in the manifest every migration-surface error is covered, and the audit caught two real bugs now fixed here: `Context` imported from the old `.server` submodule is rehomed to the package (the submodule holds the name at runtime, but a type checker treats a non-re-exported name as private), and `request_context` on a receiver the pre-pass proved holds a lowlevel `Server` is flagged again -- receiver-matched, so the live `ctx.request_context` idiom stays untouched.
1 parent ec8361b commit 86c012c

16 files changed

Lines changed: 1727 additions & 49 deletions

File tree

docs/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Version 2 of the MCP Python SDK introduces several breaking changes to improve t
88

99
## Automated migration
1010

11-
The `mcp-codemod` tool (published from `src/mcp-codemod` in this repository) rewrites every change in this guide whose meaning is unambiguous from the file alone -- the import moves, the symbol renames, the `MCPError` reshape, and the camelCase to snake_case field renames -- and inserts a `# mcp-codemod:` comment above every site it recognized but would not guess at. Run it on a clean branch first, then work through what it marked:
11+
The `mcp-codemod` tool (published from `src/mcp-codemod` in this repository) rewrites every change in this guide whose meaning is unambiguous from the file alone -- the import moves, the symbol renames, the `MCPError` reshape, the camelCase to snake_case field renames, and the `mcp` requirement in `pyproject.toml` / `requirements*.txt` -- and inserts a `# mcp-codemod:` comment above every site it recognized but would not guess at. Run it on a clean branch first, then work through what it marked:
1212

1313
```bash
1414
uvx mcp-codemod v1-to-v2 ./src
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
work/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Codemod batch test
2+
3+
Runs the `mcp-codemod` v1 -> v2 migration against real, pinned repositories and
4+
audits the result with pyright, to find silent misses the unit tests and the
5+
in-repo example corpus cannot.
6+
7+
## How it works
8+
9+
For each repository in `repos.json`:
10+
11+
1. Clone the pinned commit (shallow).
12+
2. Run the codemod (sources and dependency files) over a copy.
13+
3. Type-check the pristine clone against an environment holding the latest v1
14+
SDK, and the migrated copy against this workspace's v2 environment, with
15+
identical pyright settings.
16+
4. Diff the two error sets. Errors only on the migrated side are the migration
17+
surface; baseline noise (the repo's own issues, missing third-party stubs)
18+
appears on both sides and cancels out.
19+
5. Correlate each new error with the inserted `# mcp-codemod:` markers.
20+
21+
The codemod's contract is that the markers are the complete list of remaining
22+
manual work, so every new error should sit on or next to a marker. **A new
23+
error with no nearby marker is a silent miss** -- those are printed, written to
24+
`work/results/<slug>.json`, and make the run exit 1.
25+
26+
## Usage
27+
28+
From the repository root (the v1 environment is created on first run):
29+
30+
```bash
31+
uv run --frozen python scripts/codemod-batch-test/run.py # all repos
32+
uv run --frozen python scripts/codemod-batch-test/run.py --repo mcp-obsidian
33+
uv run --frozen python scripts/codemod-batch-test/run.py --fresh # re-clone
34+
```
35+
36+
## Adding a repository
37+
38+
Add an entry to `repos.json` with a pinned `sha` (never a branch), an
39+
`include` list when only part of the repository uses the SDK (empty means the
40+
whole tree), and a one-line `note`. Prefer repositories that depend on the
41+
`mcp` package directly; servers built on the external FastMCP library exercise
42+
that library's surface, not this SDK's.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[
2+
{
3+
"slug": "official-servers",
4+
"url": "https://github.com/modelcontextprotocol/servers",
5+
"sha": "7b1170d1da1e36bc9f553f51e76e64cbfd652b3e",
6+
"include": ["src/fetch", "src/git", "src/time"],
7+
"note": "The official reference servers; lowlevel Server and FastMCP usage."
8+
},
9+
{
10+
"slug": "mcp-obsidian",
11+
"url": "https://github.com/MarkusPfundstein/mcp-obsidian",
12+
"sha": "32285e9ac07049a8a23ea7d7903603a3e48a1bf7",
13+
"include": [],
14+
"note": "Popular community server; lowlevel Server with mcp.types throughout."
15+
},
16+
{
17+
"slug": "awslabs-aws-documentation",
18+
"url": "https://github.com/awslabs/mcp",
19+
"sha": "3a5294539de4de3a91d0ee72d5487bc8b8b1fcd7",
20+
"include": ["src/aws-documentation-mcp-server"],
21+
"note": "One server from the awslabs monorepo; production FastMCP usage."
22+
},
23+
{
24+
"slug": "android-mcp-server",
25+
"url": "https://github.com/minhalvp/android-mcp-server",
26+
"sha": "451d255a7305e6efef8a1a2b7374a21c512bba45",
27+
"include": [],
28+
"note": "Small community FastMCP server."
29+
}
30+
]

0 commit comments

Comments
 (0)