msys2-web/tests/test_mcp.py
Christoph Reiter 1c703c66d7 Add an example MCP server
Only provides one tool for vercmp() as a test.

Since the mcp session can only be instanciated once I needed to
adjust the test client usage in the test suite a bit and make
it a shared session fixture.
2025-07-06 17:32:20 +02:00

37 lines
872 B
Python

# type: ignore
import json
def _get_sse_data(response):
for line in response.text.split('\n'):
if line.startswith('data:'):
return json.loads(line[5:].strip())
def test_msys2_vercmp(client):
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "msys2_vercmp",
"arguments": {
"versionA": "1.0.0",
"versionB": "1.0.1"
}
}
}
headers = {
"Accept": "application/json, text/event-stream"
}
response = client.post('/mcp/mcp/tools/call', json=payload, headers=headers)
response.raise_for_status()
data = _get_sse_data(response)
assert data["jsonrpc"] == "2.0"
assert data["id"] == 1
assert "result" in data
assert data["result"]["content"][0]["text"] == "-1"