Files
wehub-resource-sync 2cab53bc94
Docker Publish / Build and Push Docker Images (map[description:Skill Seekers CLI - Convert documentation to AI skills dockerfile:Dockerfile name:skill-seekers]) (push) Waiting to run
Docker Publish / Build and Push Docker Images (map[description:Skill Seekers MCP Server - 25 tools for AI assistants dockerfile:Dockerfile.mcp name:skill-seekers-mcp]) (push) Waiting to run
Docker Publish / Test Docker Images (push) Blocked by required conditions
Test Vector Database Adaptors / Test chroma Adaptor (push) Waiting to run
Test Vector Database Adaptors / Test faiss Adaptor (push) Waiting to run
Test Vector Database Adaptors / Test qdrant Adaptor (push) Waiting to run
Test Vector Database Adaptors / Test weaviate Adaptor (push) Waiting to run
Test Vector Database Adaptors / Test MCP Vector DB Tools (push) Waiting to run
Tests / Code Quality (Ruff & Mypy) (push) Waiting to run
Tests / Fast Unit Tests (parallel) (macos-latest, 3.11) (push) Waiting to run
Tests / Fast Unit Tests (parallel) (macos-latest, 3.12) (push) Waiting to run
Tests / Fast Unit Tests (parallel) (ubuntu-latest, 3.10) (push) Waiting to run
Tests / Fast Unit Tests (parallel) (ubuntu-latest, 3.11) (push) Waiting to run
Tests / Fast Unit Tests (parallel) (ubuntu-latest, 3.12) (push) Waiting to run
Tests / Tests (push) Blocked by required conditions
Tests / Serial / Integration / E2E Tests (push) Blocked by required conditions
Tests / MCP Server Tests (push) Blocked by required conditions
chore: import upstream snapshot with attribution
2026-07-13 12:46:28 +08:00

171 lines
5.0 KiB
Python

#!/usr/bin/env python3
"""
Tests for FastMCP server HTTP transport support.
"""
import sys
import pytest
# Skip all tests if mcp package is not installed
pytest.importorskip("mcp.server")
# Check if starlette is available
try:
from starlette.testclient import TestClient
STARLETTE_AVAILABLE = True
except ImportError:
STARLETTE_AVAILABLE = False
from skill_seekers.mcp.server_fastmcp import mcp
pytestmark = [
pytest.mark.mcp_only,
pytest.mark.skipif(
not STARLETTE_AVAILABLE, reason="starlette not installed (pip install starlette httpx)"
),
]
class TestFastMCPHTTP:
"""Test FastMCP HTTP transport functionality."""
def test_health_check_endpoint(self):
"""Test that health check endpoint returns correct response."""
# Skip if mcp is None (graceful degradation for testing)
if mcp is None:
pytest.skip("FastMCP not available (graceful degradation)")
# Get the SSE app
app = mcp.sse_app()
# Add health check endpoint
from starlette.responses import JSONResponse
from starlette.routing import Route
async def health_check(_request):
return JSONResponse(
{
"status": "healthy",
"server": "skill-seeker-mcp",
"version": "2.1.1",
"transport": "http",
"endpoints": {
"health": "/health",
"sse": "/sse",
"messages": "/messages/",
},
}
)
app.routes.insert(0, Route("/health", health_check, methods=["GET"]))
# Test with TestClient
with TestClient(app) as client:
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert data["server"] == "skill-seeker-mcp"
assert data["transport"] == "http"
assert "endpoints" in data
assert data["endpoints"]["health"] == "/health"
assert data["endpoints"]["sse"] == "/sse"
def test_sse_endpoint_exists(self):
"""Test that SSE endpoint is available."""
# Skip if mcp is None (graceful degradation for testing)
if mcp is None:
pytest.skip("FastMCP not available (graceful degradation)")
app = mcp.sse_app()
with TestClient(app):
# SSE endpoint should exist (even if we can't fully test it without MCP client)
# Just verify the route is registered
routes = [route.path for route in app.routes if hasattr(route, "path")]
# The SSE app has routes registered by FastMCP
assert len(routes) > 0
def test_cors_middleware(self):
"""Test that CORS middleware can be added."""
# Skip if mcp is None (graceful degradation for testing)
if mcp is None:
pytest.skip("FastMCP not available (graceful degradation)")
app = mcp.sse_app()
from starlette.middleware.cors import CORSMiddleware
# Should be able to add CORS middleware without error
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Verify middleware was added
assert len(app.user_middleware) > 0
class TestArgumentParsing:
"""Test command-line argument parsing."""
def test_parse_args_default(self):
"""Test default argument parsing (stdio mode)."""
from skill_seekers.mcp.server_fastmcp import parse_args
# Save original argv
original_argv = sys.argv
try:
# Test default (no arguments)
sys.argv = ["server_fastmcp.py"]
args = parse_args()
assert args.http is False # Default is stdio
assert args.port == 8000
assert args.host == "127.0.0.1"
assert args.log_level == "INFO"
finally:
sys.argv = original_argv
def test_parse_args_http_mode(self):
"""Test HTTP mode argument parsing."""
from skill_seekers.mcp.server_fastmcp import parse_args
original_argv = sys.argv
try:
sys.argv = ["server_fastmcp.py", "--http", "--port", "8080", "--host", "0.0.0.0"]
args = parse_args()
assert args.http is True
assert args.port == 8080
assert args.host == "0.0.0.0"
finally:
sys.argv = original_argv
def test_parse_args_log_level(self):
"""Test log level argument parsing."""
from skill_seekers.mcp.server_fastmcp import parse_args
original_argv = sys.argv
try:
sys.argv = ["server_fastmcp.py", "--log-level", "DEBUG"]
args = parse_args()
assert args.log_level == "DEBUG"
finally:
sys.argv = original_argv
if __name__ == "__main__":
pytest.main([__file__, "-v"])