Skip to content

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

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

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

@K4bain

K4bain commented Aug 27, 2026

Copy link
Copy Markdown

Hi @Daniyal0100101 - since this PR has been open a while, I rebased your patch onto current main and verified it (69/69 unit tests pass against mcp 1.29.1): see #331. Your original diff was applied as-is with attribution in the commit message. Noted there: with mcp 2.x now released, the cap in this patch is the critical part - uncapped installs currently break at import time.

Copy link
Copy Markdown
Author

Superseded by #331, which carries this patch forward on current main and verifies it against the current MCP 1.x release. Closing this one to avoid keeping duplicate PRs open.

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

2 participants