mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 14:04:18 +02:00
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:
parent
55f3cade10
commit
757678bc7e
2 changed files with 13 additions and 0 deletions
|
|
@ -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(
|
||||
|
|
|
|||
10
tests/server/test_server_safety.py
Normal file
10
tests/server/test_server_safety.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue