earakely-scale's picture
Publish bookstack: 13 tasks, 25 runs
c3a2f7c verified
Raw History Blame Contribute Delete
1.53 kB
"""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}]