|
| 1 | +import pytest |
| 2 | +from fastmcp import Client |
| 3 | + |
| 4 | + |
| 5 | +# Helper functions |
| 6 | +async def get_mcp_server_detail_helper(client, server_id): |
| 7 | + """Helper function to get MCP server detail and validate basic response structure.""" |
| 8 | + result = await client.call_tool("get_mcp_server_detail", {"server_id": server_id}) |
| 9 | + assert hasattr(result, "data"), "Result should have data attribute" |
| 10 | + server_detail = result.data |
| 11 | + return server_detail |
| 12 | + |
| 13 | + |
| 14 | +def print_server_detail_info(server_detail): |
| 15 | + """Print server detail information.""" |
| 16 | + print(f"ID: {server_detail.id}") |
| 17 | + print(f"Name: {server_detail.name}") |
| 18 | + print(f"Author: {server_detail.author}") |
| 19 | + print(f"Description: {server_detail.description}") |
| 20 | + print(f"Is Hosted: {server_detail.is_hosted}") |
| 21 | + print(f"Is Verified: {server_detail.is_verified}") |
| 22 | + print(f"View Count: {server_detail.view_count}") |
| 23 | + print(f"GitHub Stars: {server_detail.github_stars}") |
| 24 | + print(f"Tags: {server_detail.tags}") |
| 25 | + print(f"Source URL: {server_detail.source_url}") |
| 26 | + print(f"Logo URL: {server_detail.logo_url}") |
| 27 | + print(f"ModelScope URL: {server_detail.modelscope_url}") |
| 28 | + print(f"Server Config: {server_detail.server_config}") |
| 29 | + print(f"Env Schema: {server_detail.env_schema}") |
| 30 | + print(f"Readme: {server_detail.readme}") |
| 31 | + |
| 32 | + |
| 33 | +def validate_server_detail_fields(server_detail): |
| 34 | + """Validate that server detail has all required fields.""" |
| 35 | + required_fields = [ |
| 36 | + "id", |
| 37 | + "name", |
| 38 | + "description", |
| 39 | + "author", |
| 40 | + "tags", |
| 41 | + "env_schema", |
| 42 | + "server_config", |
| 43 | + "is_hosted", |
| 44 | + "is_verified", |
| 45 | + "modelscope_url", |
| 46 | + "source_url", |
| 47 | + "logo_url", |
| 48 | + "readme", |
| 49 | + "view_count", |
| 50 | + "github_stars", |
| 51 | + ] |
| 52 | + |
| 53 | + for field in required_fields: |
| 54 | + assert hasattr(server_detail, field), f"Server detail should have '{field}' attribute" |
| 55 | + |
| 56 | + # Validate field types |
| 57 | + assert isinstance(server_detail.id, str), "ID should be a string" |
| 58 | + assert isinstance(server_detail.name, str), "Name should be a string" |
| 59 | + assert isinstance(server_detail.tags, list), "Tags should be a list" |
| 60 | + assert isinstance(server_detail.is_hosted, bool), "is_hosted should be a boolean" |
| 61 | + assert isinstance(server_detail.is_verified, bool), "is_verified should be a boolean" |
| 62 | + assert isinstance(server_detail.view_count, int), "View count should be an integer" |
| 63 | + assert isinstance(server_detail.github_stars, int), "GitHub stars should be an integer" |
| 64 | + assert isinstance(server_detail.server_config, list), "Server config should be a list" |
| 65 | + assert isinstance(server_detail.env_schema, str), "Env schema should be a string" |
| 66 | + assert isinstance(server_detail.readme, str), "Readme should be a string" |
| 67 | + assert isinstance(server_detail.logo_url, str), "Logo URL should be a string" |
| 68 | + |
| 69 | + |
| 70 | +@pytest.mark.integration |
| 71 | +async def test_get_mcp_server_detail(mcp_server): |
| 72 | + """Test get_mcp_server_detail with a known server ID.""" |
| 73 | + async with Client(mcp_server) as client: |
| 74 | + server_id = "pengqun/modelscope-mcp-server" |
| 75 | + server_detail = await get_mcp_server_detail_helper(client, server_id) |
| 76 | + |
| 77 | + # Validate response structure |
| 78 | + validate_server_detail_fields(server_detail) |
| 79 | + |
| 80 | + # Print detailed information |
| 81 | + print(f"\n✅ Received MCP server detail for '{server_id}':") |
| 82 | + print_server_detail_info(server_detail) |
| 83 | + |
| 84 | + # Validate specific fields for known server |
| 85 | + assert server_detail.id == server_id, f"Server ID should be {server_id}" |
| 86 | + assert server_detail.author == "pengqun", "Author should be pengqun" |
| 87 | + assert server_detail.name != "", "Name should not be empty" |
0 commit comments