Skip to content

✨ WP12: mcp SDK 2.0 support — dual-path compat, pin widened to <3 - #10

Merged
Wuesteon merged 5 commits into
mainfrom
worktree-wp12-mcp2-migration
Jul 29, 2026
Merged

✨ WP12: mcp SDK 2.0 support — dual-path compat, pin widened to <3#10
Wuesteon merged 5 commits into
mainfrom
worktree-wp12-mcp2-migration

Conversation

@Wuesteon

Copy link
Copy Markdown
Owner

Summary

Lifts the v0.2.2 emergency mcp<2 cap by supporting BOTH SDK majors (packet WP12):

  • Compat layers (lean_memory._mcp_compat, lean_memory_console._mcp_compat — duplicated on purpose; console↔core version skew makes cross-package private imports fragile): handle the 2.0 FastMCPMCPServer rename, ctor version= (replacing the 1.x _mcp_server.version poke), and transport params moving from the constructor to streamable_http_app(...) for the console's HTTP mount.
  • Real 2.0 bug found & fixed: mcp 2.0 runs sync tool handlers in anyio worker threads (1.x ran them inline), tripping SQLite's same-thread guard on every core tool call. Store connections now open with check_same_thread=False — safe for serial MCP traffic (CPython sqlite3 threadsafety=3, serialized); nothing enables concurrent cross-thread access.
  • Tests dual-path: shared tests/mcp_client_compat.py wraps 2.0's in-memory Client(server) vs 1.x's create_connected_server_and_client_session; console's server-side call_tool unwrap handles 2.0's CallToolResult.structured_content.
  • Pins widened to mcp>=1.2,<3 (core extra + console); the pyproject guard test now asserts the <3 cap.

Test plan

Verified against BOTH majors locally:

  • mcp 1.29 (dev venvs): core 301 passed, console 153 passed.
  • mcp 2.0.0 (fresh venv, editable installs): core 300 passed + 1 unrelated skip (no [llm] extra), console 153 passed.
  • CI resolves mcp 2.0.x fresh, so all six legs exercise the v2 path.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YRU73aDWiYUqgaL5UETUMp

Wuesteon added 5 commits July 29, 2026 14:39
mcp SDK 2.0 runs sync tool handlers in anyio worker threads (1.x ran
them inline on the event loop), so the serving SQLite connection is
touched from a different thread per tool call and the stock
check_same_thread guard crashes every request — reproduced across the
whole MCP suite under mcp==2.0.0. Sequential cross-thread use is safe:
CPython's sqlite3 ships threadsafety=3 (serialized) and MCP stdio
traffic is serial. Nothing enables concurrent cross-thread access.
@Wuesteon
Wuesteon merged commit 4efe4ca into main Jul 29, 2026
6 checks passed
@Wuesteon
Wuesteon deleted the worktree-wp12-mcp2-migration branch July 29, 2026 06:50
Wuesteon added a commit that referenced this pull request Jul 29, 2026
Resolves the import-block conflict in mcp_server.py: keep the compat
factory (make_stdio_server) AND the metadata imports (ToolAnnotations,
Field). Renumbers this packet WP12 → WP13 — the mcp 2.0 migration claimed
WP12 concurrently and merged first (PR #10).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VgxNBms5npMWXD2krUofs3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant