Files
fastmcp-feedback/examples/test_demo.py
T
rsp2k ddf23d10e4
Tests / test (==2.12.2) (push) Canceled after 0s
Tests / test (==2.14.3) (push) Canceled after 0s
Tests / test (>=4,<5) (push) Canceled after 0s
Tests / canary (push) Canceled after 0s
Support FastMCP 4 and fix silent composition failure
compose_feedback_services() called import_server() without awaiting it.
That method became async in FastMCP 2.14, so on the version this package
was built against it composed nothing while logging success. FastMCP 4
removed it outright. Use mount(), which is sync on 2.12 through 4.x.

The test suite could not start (pytest-html hook, plugin not installed),
so nothing caught this. Add pytest-html, bring examples/ over from the docs
repo since the integration tests import them, and fix the tests that had
drifted from the code. 407 tests pass on FastMCP 2.12.2, 2.14.3 and 4.0.10.

- Declare fastmcp>=2.12.2,<5; CI matrix covers each family plus a
  non-blocking canary on the newest FastMCP
- Add a composition test with real servers; the mocked ones could not
  see a missing await
- Rewrite the README against the actual API and execute its examples
- Ignore ruff UP042: StrEnum would change stored enum formatting
- Version 2026.09.27
2026-09-27 06:09:30 -06:00

91 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify demo server functionality without running the full MCP server.
"""
import asyncio
import sys
from pathlib import Path
# Add the src directory to the path for development
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
sys.path.insert(0, str(Path(__file__).parent))
from demo_server import create_demo_server
from fastmcp import Client
async def test_demo_functionality():
"""Test the demo server tools without running the MCP server."""
print("🧪 Testing FastMCP Feedback Demo Functionality")
print("=" * 55)
try:
# Create the demo server
server = create_demo_server()
async with Client(server) as client:
# Get available tools
tools = {tool.name: tool for tool in await client.list_tools()}
print(f"✅ Server created with {len(tools)} tools")
# List available tools
print("\n📋 Available Tools:")
for name, tool in tools.items():
print(f" • {name}: {tool.description}")
# Test system info tool
if "get_system_info" in tools:
print("\n🔍 Testing system info...")
result = await client.call_tool("get_system_info", {})
info = result.structured_content
print(f" Version: {info['versions']['fastmcp_feedback']}")
print(f" Python: {info['versions']['python']}")
print(f" Features: {len(info['demo_features'])}")
# Test sample data setup
if "setup_sample_data" in tools:
print("\n📊 Testing sample data setup...")
result = await client.call_tool("setup_sample_data", {})
data_result = result.structured_content
if data_result["success"]:
print(f" ✅ Added {data_result['items_added']} sample items")
else:
print(f" ❌ Failed: {data_result['error']}")
# Test feedback listing
if "list_feedback" in tools:
print("\n📝 Testing feedback listing...")
result = await client.call_tool("list_feedback", {})
feedback_data = result.structured_content
print(f" Found {len(feedback_data['feedback'])} feedback items")
# Show first item details
if feedback_data["feedback"]:
first = feedback_data["feedback"][0]
print(f" First item: {first['type']} - {first['title']}")
# Test statistics
if "get_feedback_statistics" in tools:
print("\n📈 Testing statistics...")
result = await client.call_tool("get_feedback_statistics", {})
stats = result.structured_content
print(f" Total items: {stats['total_count']}")
print(f" By type: {stats['by_type']}")
print(f" By status: {stats['by_status']}")
print("\n🎉 All tests passed! Demo server is working correctly.")
return True
except Exception as e:
print(f"\n❌ Test failed: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
success = asyncio.run(test_demo_functionality())
sys.exit(0 if success else 1)