Skip to content

Commit 97f9dc4

Browse files
SamuelBrudnerclaude
andcommitted
fix: restore MCP server startup under pydantic 2.11 / fastmcp 2.12
The server crashed on startup with two cascading pydantic errors while fastmcp built output schemas from typed tool return annotations: 1. typing.TypedDict is rejected by pydantic on Python < 3.12 — import TypedDict/NotRequired/Required from typing_extensions instead (tool_responses.py and vector_backend/sync.py). 2. The hand-rolled recursive JsonValue alias was "not fully defined": fastmcp builds the output TypeAdapter in its own module namespace, so the "JsonValue" string forward-ref could not be resolved. Use pydantic's built-in recursive JsonValue and drop the now-unneeded `from __future__ import annotations`. Loose version pins (pydantic>=2.7, fastmcp>=2.1) let newer releases pull in the stricter behavior; the startup test mocks FastMCP, so the real schema-building path was never exercised in CI. Verified: server completes the MCP initialize handshake, tools/list returns all 18 tools with schemas, and `claude mcp list` reports Connected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 22f3c3b commit 97f9dc4

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎src/labarchives_mcp/schemas/tool_responses.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Typed response contracts for LabArchives MCP tools."""
22

3-
from __future__ import annotations
3+
from typing import Literal, TypeAlias
44

5-
from typing import Literal, NotRequired, Required, TypeAlias, TypedDict
5+
from pydantic import JsonValue
6+
from typing_extensions import NotRequired, Required, TypedDict
67

78
JsonScalar: TypeAlias = str | int | float | bool | None
8-
JsonValue: TypeAlias = JsonScalar | list["JsonValue"] | dict[str, "JsonValue"]
99
JsonObject: TypeAlias = dict[str, JsonValue]
1010

1111

‎src/vector_backend/sync.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
from collections.abc import Mapping, Sequence
1111
from datetime import UTC, datetime, timedelta
12-
from typing import TypedDict
12+
13+
from typing_extensions import TypedDict
1314

1415
from vector_backend.build_state import should_rebuild
1516
from vector_backend.models import BuildRecord

0 commit comments

Comments
 (0)