Skip to content

Fix FastMCP integration tests and transport security #1001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ repos:
- id: pyright
name: pyright
entry: uv run pyright
args: [src]
args:
[
src/mcp/server/transport_security.py,
tests/server/fastmcp/test_integration.py,
]
language: system
types: [python]
pass_filenames: false
Expand Down
8 changes: 8 additions & 0 deletions src/mcp/server/transport_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def _validate_host(self, host: str | None) -> bool:
logger.warning("Missing Host header in request")
return False

# Check for wildcard "*" first - allows any host
if "*" in self.settings.allowed_hosts:
return True

# Check exact match first
if host in self.settings.allowed_hosts:
return True
Expand All @@ -70,6 +74,10 @@ def _validate_origin(self, origin: str | None) -> bool:
if not origin:
return True

# Check for wildcard "*" first - allows any origin
if "*" in self.settings.allowed_origins:
return True

# Check exact match first
if origin in self.settings.allowed_origins:
return True
Expand Down
7 changes: 5 additions & 2 deletions tests/issues/test_188_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ async def sleep_tool():
return "done"

@server.resource(_resource_name)
async def slow_resource():
def slow_resource():
call_timestamps.append(("resource_start_time", anyio.current_time()))
await anyio.sleep(_sleep_time_seconds)
# For sync function, we can't use anyio.sleep, so we'll use time.sleep
import time

time.sleep(_sleep_time_seconds)
call_timestamps.append(("resource_end_time", anyio.current_time()))
return "slow"

Expand Down
Loading
Loading