File size: 1,534 Bytes
c3a2f7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Checks the replay environment through its MCP endpoint: the tool count and one replayed status."""
import json

from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client

TOOL_COUNT = 31
TOOL = "get_attachments"
RECORDED_STATUS = 200


def replayed_status(result):
    """The status member of a replayed tool result, structured or from its text content."""
    data = result.structuredContent
    if data is None:
        text = "".join(getattr(part, "text", "") for part in result.content)
        data = json.loads(text) if text else {}
    return data.get("status") if isinstance(data, dict) else None


async def verify(mcp_url):
    async with streamable_http_client(mcp_url) as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()
            listed = await session.list_tools()
            result = await session.call_tool(TOOL, {}) if TOOL is not None else None
    count = len(listed.tools)
    passed = count == TOOL_COUNT
    description = f"listed {count} tools, expected {TOOL_COUNT}"
    if result is not None:
        status = None if result.isError else replayed_status(result)
        passed = passed and status == RECORDED_STATUS
        description += f"; {TOOL} replayed status {status!r}, recorded {RECORDED_STATUS!r}"
    else:
        description += "; no GET tool without path parameters to replay"
    print(f"replay: {description}")
    return [{"id": "replay", "result": passed, "description": description}]