Skip to content

fix(server): Server.__init__ compatibility with mcp>=1.12.0 - #326

Open
Daniyal0100101 wants to merge 1 commit into
tadata-org:mainfrom
Daniyal0100101:fix/322-server-init-mcp-compat
Open

fix(server): Server.__init__ compatibility with mcp>=1.12.0#326
Daniyal0100101 wants to merge 1 commit into
tadata-org:mainfrom
Daniyal0100101:fix/322-server-init-mcp-compat

Conversation

@Daniyal0100101

Copy link
Copy Markdown

Describe your changes

Fix Server.__init__ compatibility with mcp>=1.12.0 (issue #322).

Root Cause

In mcp>=1.12.0, the Server.__init__ signature changed:

# mcp 1.12.0+
def __init__(
    self,
    name: str,
    version: str | None = None,           # was `description` in older versions
    instructions: str | None = None,
    ...
):

The old code Server(self.name, self.description) passed self.description as the second positional argument, which now maps to version instead of instructions. This caused:

TypeError: Server.__init__() takes 2 positional arguments but 3 were given

Fix

  1. fastapi_mcp/server.py (line 144): Changed Server(self.name, self.description) to Server(name=self.name, instructions=self.description) — uses keyword arguments so the mapping is explicit and version-agnostic.

  2. pyproject.toml: Pinned mcp dependency to >=1.12.0,<2.0.0 to prevent future breaking changes from mcp 2.x.

Testing

  • All 117 existing tests pass (83.04% coverage)
  • Manual verification: FastApiMCP instantiation, mount_http(), mount_sse() all work without TypeError
  • Ruff, mypy, pre-commit all pass

Related

Closes #322

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.

[BUG] Server.__init__ incompatible with mcp>=1.12

1 participant