Skip to content

Commit 757678b

Browse files
strawgateclaude
andauthored
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>
1 parent 55f3cad commit 757678b

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/fastmcp/server/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,9 @@ def mount(
20472047

20482048
from fastmcp.server.providers.fastmcp_provider import FastMCPProvider
20492049

2050+
if server is self:
2051+
raise ValueError("Cannot mount a server onto itself")
2052+
20502053
# Handle deprecated prefix parameter
20512054
if prefix is not None:
20522055
warnings.warn(

tests/server/test_server_safety.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
3+
from fastmcp import FastMCP
4+
5+
6+
class TestMountSafety:
7+
def test_self_mount_raises(self):
8+
mcp = FastMCP("test")
9+
with pytest.raises(ValueError, match="Cannot mount a server onto itself"):
10+
mcp.mount(mcp)

0 commit comments

Comments
 (0)