fix: reject self-mount to prevent infinite recursion (#3925)

* fix: server safety guards for self-mount, duplicate middleware, mount arg order

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Remove duplicate middleware and mount arg order checks

These are runtime type checking, not bugs — a type checker catches them.
Keep only the self-mount guard which is a semantic check.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bill Easton 2026-04-14 11:10:19 -05:00 committed by GitHub
commit 757678bc7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View file

@ -2047,6 +2047,9 @@ class FastMCP(
from fastmcp.server.providers.fastmcp_provider import FastMCPProvider
if server is self:
raise ValueError("Cannot mount a server onto itself")
# Handle deprecated prefix parameter
if prefix is not None:
warnings.warn(

View file

@ -0,0 +1,10 @@
import pytest
from fastmcp import FastMCP
class TestMountSafety:
def test_self_mount_raises(self):
mcp = FastMCP("test")
with pytest.raises(ValueError, match="Cannot mount a server onto itself"):
mcp.mount(mcp)